Although this psalm was written by David, it is not clear when he composed it. He refers to a time when he was being pursued by enemies, which means it could have been written during the years he was hunted by Saul or during the time when his son Absalom rebelled against him.
The first verse of the psalm is David’s affirmation that he believes God can protect him. It is an answer to the advice of his friends found in verses 2 and 3. They suggest that the righteous should flee when the attacks of the enemy become too strong. But the psalmist realises that when the foundations are being destroyed, the last thing to do is flee from the battle. Instead he is going to stay at his post, trust in the Lord and live a righteous life. William Gurnall once commented that ‘sinning times have ever been the saints’ praying times’. The darker things become, the more determined each Christian should be to overcome them by dependence on God, holy living and determined prayer.
In verse 4 the psalmist points out that the Lord is still in charge, that he is aware of what each person is doing. Verse 5 is a reminder that the Lord arranges providence in two ways: the first way is designed to test the commitment of his people and the second way is part of the process of punishment on the wicked, a process that will eventually climax in complete judgement. Often these two ways occur simultaneously; on one hand a situation is a test of his people’s loyalty, on the other hand the same situation results in the overthrow of the wicked. Usually, the wicked imagine they are progressing, but they are not. The supreme example of this simultaneous occurrence is the death of the Saviour: it was a test of his disciples’ faith, and it was an act of judgement on Christ’s enemies even although they thought they had managed to get rid of him.
In verse 7, David reminds himself of God’s attributes and activities, which is what each of God’s people should do, particularly in times when the foundations are being destroyed. The basic thought seems to be David’s awareness of divine approval of his determination to live a righteous life in a corrupt society. This consciousness of divine approval gave David spiritual strength to remain resolute whatever the situation.