This psalm focuses on the ingathering of God's people. The psalmist describes a variety of different situations in which God finds them and from which he rescues them. It is important to recognise that these situations were under the Lord's providential control at all times. Each situation was very difficult for those living in it, yet none of the situations was too hard for the Lord to deal with.
The psalm begins by calling on God's people to give thanks to him for his mercy (his steadfast love is expressed in mercy, otherwise it could not be shown to sinners). By definition, mercy must be permanent, otherwise it means that it is limited to a set period of time and that would not be mercy. After showing mercy to a sinner for the first time, God never changes his mind. Mercy is the detail about God that his people should always highlight when speaking to him or speaking about him to others. The biggest help that we can give to one another is to remind one another that our all-powerful, all-knowing, eternal God is merciful towards us. Because he is merciful, he will be good to us.
Some of God's people were living in a spiritual wasteland when God found them (vv. 4-9). They were lost and unaware of which direction they should go. Moreover they sensed their spiritual dryness and were led to call on the Lord for help. The reason why they prayed to him was because he was drawing them secretly to himself. He answered their prayer and became their guide to the heavenly city. On the journey he supplied them out of the riches of his grace and they found ongoing satisfaction in their souls. They were now satisfied by the same God who had deprived them. It is not surprising that such should want to thank him.
Others of God's people experienced what the psalmist depicts as spiritual imprisonment before the Lord rescued them (vv. 10-16). The imprisonment was not like a short-term confinement; instead it was like those who are imprisoned and facing a death sentence. They sensed that they were undergoing God's sentence on their rebellion. Frequently this is part of the process of conviction of sin and is a very oppressive experience. Yet when they turned to the Lord he freely forgave them and liberated them from their spiritual chains. What seemed impossible to them -- to be set free -- was performed for them by the same God who had condemned them. It is not surprising that such should want to thank him.
A third group of God's people had lived foolishly and brought trouble on themselves before their conversion (vv. 17-22). These troubles can have personal effects or they can affect their prospects for the future. Eventually they were overwhelmed by what they brought on themselves. But when they cried to the Lord in their desperation, he listened to them and rescued them. Because he had done so, they can now sing to him songs of joy. Usually those who have been delivered from such a background don't want to sing other songs.
A fourth group experienced God's grace while involved in dangerous employments (vv. 23-32). The activity that the psalmist selects is that of sailors, although he could have also used other dangerous employments such as mining or fighting in the army. The sailors found themselves in the midst of a great storm and their lives were in danger. Yet when they cried to the Lord he heard them and rescued them. Then he became their Pilot and brought them safely to their destination. Again they are exhorted to praise the Lord publicly for his mercy shown to them.
In verses 33-42, the psalmist meditates on God's providential dealings with communities. The Lord is in sovereign control and he can reverse or change any situation. What the psalmist wants his readers to grasp is that God gets involved in all these situations in order to work for the good of his people. This should give us confidence as we look at the circumstances we face. At the same time, the Lord is at work to silence the claims of the wicked. It is salutary to note that every wicked person who is currently stating his or her opinion will be silenced eventually by God. The message of the psalm is that our responsibility is to remember that God is at work, either rescuing his people or punishing his enemies.