This psalm is one of the imprecatory psalms; they are psalms in which the authors ask God to take vengeance on their opponents. When such psalms are first read by Christians they wonder if such sentiments are suitable for followers of Jesus. After all, he prayed for the soldiers who crucified him and he also taught his disciples to love their enemies. So can Christians use this psalm?
One way of answering this question is to consider how Paul reacted to incorrigible opponents of the Christian church. He mentions in Galatians 1:8-9 that those who were preaching a false gospel in Galatia should be cursed by God, and he refers in 2 Timothy 4:14-15 to an opponent of the gospel called Alexander the coppersmith, and Paul wanted the Lord to remember what Alexander had done and deal with him. The attack on David was of a similar nature because it was not merely an attack on him as an individual but was also a prolonged assault on the kingdom of God. So we can use the psalm if we understand what the author had in mind.
David had endured persistent trouble from a group of opponents who were led by a cruel individual, whom some commentators think was Doeg the Edomite. To begin with, the psalmist had responded with love and good (vv. 4-5) as well as by prayer. Yet since the opponent showed no sign of changing his behaviour, the psalmist asked the Lord to deal with his enemy.
Three details can be noticed about this prayer for divine vengeance. First, the psalmist does what the New Testament also teaches, which is that we should not revenge ourselves but leave it with the Lord to deal with (Rom. 12:19). Second, the psalmist's response is a cry for divine justice, and we can think of many situations where we can make a similar request (cruel political leaders, situations where the church is being persecuted, gangland atrocities). It is important to note that the psalmist recognised that divine vengeance would be severe. Third, Peter quotes verse 8 of this psalm when describing the necessity of replacing Judas Iscariot with another person who would become an apostle (Acts 1:20).
Spurgeon, in explaining this psalm, stated: 'The gentlest hearts burn with indignation when they hear of barbarities to women and children, of crafty plots for ruining the innocent, of cruel oppression of helpless orphans, and gratuitous ingratitude to the good and gentle.... We wish well to all mankind, and for that very reason we sometimes blaze with indignation against the inhuman wretches by whom every law which protects our fellow creatures is trampled down, and every dictate of humanity is set at nought.'
In verses 21-31, the psalmist prays for himself. He does not attempt to highlight his good behaviour. Instead he focuses on God's mercy and pleads for his help. The situation has become so bad that only the Lord can help him. Yet the psalmist knows the character of his God (v. 21) and is confident that he will be with his needy follower in order to help him (v. 31). Because this will be the case, the psalmist dedicates himself to join with God's people when they meet in public to praise him (v. 30).
The proof that David was not merely desiring personal revenge is that he longed to be able to join in the public worship of God and glorify him.