David is in a difficult situation in which his life is being threatened (v. 2). He describes his opponents in verse 14 (a band of ruthless men seeks his life) and the only One who can deliver him is the Lord.
In verses 1 and 2, we see the psalmist’s self-perception: he recognises that he is poor and needy, without any spiritual resources in himself; nevertheless he mentions that he is also godly, an indication that he recognises the changes that have occurred in his life because of the Lord’s grace. At the same time, his self-assessment reveals that his level of godliness was not as high as he wanted it to be.
Further the psalmist is a man of prayer: he prays all day (v. 3), and describes his prayer as a plea (v. 6). He comes to God empty-handed, which is a good state to be in because it means he can get more from God.
As he prays, he is reminded of the great grace of God. The Lord forgives those who pray to him (v. 5) and gives them help in trouble (v. 7). Since he is capable of bringing all the nations to worship him (v. 9), it is not difficult for him to help one petitioner like David. Such a deduction is not merely a mental consequence for the psalmist; it is also a powerful argument in his prayer because he wants the Lord to do what only God can do (v. 10), which is to deliver him. When that happens, he will know the joy of the Lord (v. 4).
The psalmist knows that he needs to be taught by the Lord. He requires instruction in what the Lord is doing in providence. When he will realise God’s purpose, then he will walk in ways that please the Lord. The psalmist admits that there is part of him that does not want to obey God, so he asks the Lord to unite his heart. When that petition is answered, the psalmist will have a thankful spirit (v. 12). So there is a process described here: instruction by God leads to grateful implementation of his will.
As he prays, David recalls previous divine deliverances (v. 13), and this recollection gives him confidence regarding his current situation. In his prayer he specifies his situation (v. 14). The characters of his enemies are terrible, but the best remedy for that assessment is to consider the character of God, which the psalmist does (v. 15), and then confesses that the Lord is marked by mercy, grace, patience, and loyalty towards his people.
In verse 16, David uses as an argument in prayer the fact that his mother was a believer when he asks the Lord to ‘save the son of your maidservant’. As Spurgeon observed, David ‘gloried in being the son of a woman who herself belonged to the Lord’. The psalmist recognises that the Lord recalls all his people, including the ones of previous generations, and answers their prayers even after they are gone. David’s mother would have prayed for him many times – that was how she expressed that she was God’s maidservant.
Then David asks God for a token for good (v. 17). His words could mean that he wants to be a token of good that others will see and note that God has answered his prayer and helped him. Or it could mean that he was asking for a sample of the full deliverance he longed for, with that sample being a joyful sense of the presence of God (in response to his request for joy in verse 4).