The heading does not indicate when David wrote this psalm. The psalm itself is divided into three sections (1-4, 5-8, 9-12) and we can see from the first section that David has been under secret attack from hypocritical opponents who had pretended to be his friends. His response was to look to God for help.
In verse 1 David describes his soul as waiting in silence before God. This is a picture of calmness, of confidence. As Spurgeon observed, ‘Faith can hear the footsteps of coming salvation, because she has learned to be silent.’ David has this response because he knows by experience what God can do for him. Previously he had known divine deliverances, which he illustrates by calling God his rock and his fortress (v. 2). The obvious lesson for us is that past occasions of divine help should enable us to expect his assistance when new troubles come.
In the second section, David repeats his confidence in God. Yet he is sensitive to the fears of those who are with him (v. 8), and exhorts them to trust in the Lord as well. David is aware that they may not be able to rest silently in God and he reminds them that it is good for them to pour out their hearts in his presence. Faith in God will show itself in different ways. For some, faith at times is a quiet confidence; for others, there will be non-stop speaking to God about their burdens. Both responses are expressions of faith, and the same individual will usually know both at different times in his life. After all, David himself on other occasions was not in such a calm mood as he was when he penned this psalm (cf. Psalm 32:3-4). What actually matters is that God is the refuge for both the calm soul and the troubled soul.
In section three, David turns from contemplating God to describing his opponents. Compared to God, all of them are transitory and their methods, even if providing temporary growth in assets, will not provide long-term gain. Instead we have to remember the power and faithfulness of God, and how he will eventually sort things out and give to each person what their actions deserve. Those who depend on his grace will receive grace, those who rebel will receive punishment.