Psalm 40:2–3 (ESV) … “He drew me up from the pit of destruction, out of the miry bog, and set my feet upon a rock, making my steps secure. He put a new song in my mouth, a song of praise to our God. Many will see and fear, and put their trust in the Lord.”
In due time, God heard David’s prayer and delivered him from the trouble. What a deliverance it was! David’s feet were lifted out of the miry clay of a horrible pit and were ‘established’ on a solid rock. Praise is the natural response to such a thing. This one act of deliverance made David keenly aware that God constantly thinks about his people and does many wonderful works on their behalf. His kind thoughts and wonderful deeds are too many to be counted (Ps 40:5).
In addition to rejoicing over his deliverance, David rejoiced in knowing the greatness of it could not go unnoticed, that it would cause others to fear (stand in awe and reverence before God) and to rely upon him completely.