I sought the LORD, and he answered me and delivered me from all my fears. Those who look to him are radiant, and their faces shall never be ashamed. This poor man cried, and the LORD heard him and saved him out of all his troubles.
David writes about the contrast between what a person naturally experiences in life as a result of wrong choices and how God counteracts our most difficult experiences. This is a call to worship God for the benefits He gives to us in deliverance. It was written after David had compromised to save his own skin... an episode of his life in which he was not so much a man of faith as a scheming self-driven, fearful person. He hid from Saul's attacks by "changing his behavior" and living under the protection of the Philistine king. You can read about the double life details in 1 Samuel 21. It was not David's finest moment of faith and trust in God.
Yet God was still there for David at that time. And God eventually delivered him from this poor choice in order to honor His promise that He made to David. God's mercies are bigger than our fear-driven selfish failures. I am thankful for that.
David mentions three very human experiences that were driving him: fear (Psalm 34:4), shame (Psalm 34:5), and troubled times (Psalm 34:6). And those things can combine in our hearts to pretty much diminish faith to a barely discernible trickle. Yet when we turn back to God, He will deliver us!
David celebrated the God Who answered prayer and delivered from fear. He worshiped The Lord for taking away his shame (and David had a lot to be ashamed of... he feigned madness to live among the enemies of Israel). David felt like a man whose life was saved when God delivered him. And to be saved from near death creates a grateful heart.