A prayer for deliverance in times of trouble.
v1-3: Testimony of past victories; by the power of God (v7). All is of God (Deut 7.1; 8.18; Josh 24.12). What "we have heard" was true, for God drove out the nations, and planted the people of Israel in the land.
There is a danger that, following previous victories, we begin to trust in ourselves; in Gal 3.3, Paul teaches that, having begun in the Spirit, we must continue in the Spirit.
v4-8: Confidence of present and future victories. The Lord God has commanded victory and will continue to do so. Since God commands victory, victory is assured. We do well to acknowledge that victory is not through our own efforts, but through God Himself. We therefore boast (glory) in God alone.
v9-16: The problem of current trials. We do not think of our Christian experience as a series of rebukes and rewards from God depending on our obedience or disobedience. Rather, life is a journey, through sunny villages of blessing, thrilling experiences of God's power, winds of adversity demanding steely determination, as well as deep sorrows. The psalmist attributes all events to the hand of God; and this is right, as he continues to look to God for deliverance.
v17-19: The trials (of v9-16) were not the result of specific sins. The response to the trials must still be in faithfulness and obedience; trusting that all our circumstances are ordained by God, and that He is in control.
v20-22: The people had remained loyal to God. They had resisted the temptation to seek a foreign god. Any disloyalty could not have been hidden.
Yet, even in their faithfulness, they faced death for God's sake. (v22 is quoted in Rom 8.36; there too the context is of the faithful facing persecution for Christ's sake.)
v23-26: The final plea to God for help, Awake! Arise! (Ps 121.4) There is no dependence on personal righteousness, but solely on God's mercy.