In a time of trial, David was plagued by his enemies, and looked to God for deliverance. The first penitential psalm (see also: Ps 32; 38; 51; 102; 130; 143). He cries "O, Lord" several times, indicating a real, heart-felt prayer.
v1: The psalmist had experienced God's discipline and rebuke; but this was instructive, not destructive; even so, it can be hard to bear (Heb 12.11).
v3: "How long?" since the trial was continuing. Sometimes we ask Him to shorten such times, as in Matt 24.22.
v4-5: The psalmist looks for deliverance in this life. This would, of course, provide a testimony to others.
v6-7: Weariness through continued trials. Let it never be said that godly people do not suffer. This suffering remains real, even with God's mercies. We do not live in some painless dream.
v8: Workers of iniquity, enemies of the godly; it is often through such people that trials or temptation comes; so the psalmist prayed, "away from me."
v9: The Lord has heard; here is confidence and true faith.
v10: A further statement of confidence, that the Lord would provide deliverance. The psalmist's enemies were also God's enemies, and therefore would be defeated.