The heading of the psalm indicates that David wrote it for use at the dedication of the temple. David himself was forbidden by God from building the temple (this task was given to his Solomon), nevertheless he wrote a psalm to be sung whenever the task was finished. This tells us that he did not resent the Lord’s rejection of his desire to build a house for God. Instead he wrote a psalm that celebrates what the Lord had done for him.
In verses 1-3, David praises the Lord for his help. It is not clear which incident is in the background. The psalmist had undergone a physical illness that seemed to be fatal, and this prospect had cheered up his enemies. In his distress, he had called on the Lord and had recovered from his illness. Therefore, he calls on those assembled to worship God to praise him for delivering his servant (v. 4).
David reflects on his time of trouble and notes that it was relatively short in comparison to the years in which he had known God’s favour (v. 5). He admits that he had gone through a distressing experience, yet the Lord had restored to him the joy of salvation.
Why had the psalmist entered that difficult period? He gives the answer in verse 6 – he had become self-confident, a reminder that such an attitude can be found in the best of God’s people. God’s response was to withdraw a sense of security from David (v.7).
This action of fatherly chastisement led David to engage in earnest prayer for restoration (vv. 8-10). It looked even to David himself that he was going to die, so he prayed with a sense of desperation to the only one who could help him. We can see his desperation in the fact that all he could plead for was mercy.
God heard David’s prayer and delivered him completely from what he feared (vv. 11-12). Instead of sadness, there was gladness. In response, David determined to be grateful always for this divine act of deliverance.
The lesson of the psalm is that the response to divine restoration should be individual gratitude by the restored person and communal rejoicing by his friends.