Note: This psalm is a prayer for God’s justice.
A prayer of David.
A. Prayer of a Righteous Man
17:1 [note the psalmist’s triple appeal…]  Hear me, Lord [the God of the covenant], my plea is just;  listen to my cry [a desperate and intense call for divine help].  Hear my prayer — it does not rise from deceitful lips.
17:2 [note twofold content of his prayer] [1 = vindication] Let my vindication come from you; [2 = investigation] may your eyes see what is right.
17:3 [a declaration of innocence] Though you [A] probe my heart, though you [B] examine me at night [a time when he was alone with God and away from all distractions] and [C] test me, [note the findings of the probing, examining, and testing…] you will find that I have planned no evil; my mouth has not transgressed.
17:4 Though people tried to bribe me, I have kept myself from the ways of the violent [those who gave no consideration to God’s commands] through what your lips have commanded.
17:5 My steps have held to your paths [the way of godliness; “Lord, perfect what Thou hast begun in me, that I may not suffer shipwreck when I am almost at the haven.” (Beza)]; my feet have not stumbled [“When men speak ill of thee, live so that no one will believe them.” (Plato)].
B. Prayer for Protection
17:6 I call on you, my God [based on use of metaphors from Deut. 32:10-12 in verse 8, David called on the God of the Exodus and of Mount Sinai to act again on his behalf], for you will answer me [a bold confidence that God would hear and answer his cry for help]; turn your ear to me and hear my prayer.
17:7 Show me the wonders of your great love [an appeal to act on his behalf now by delivering him from those who would do him harm], you who save by your right hand [symbol of strength] those who take refuge in you from their foes.
17:8 [note two metaphors (cf. Deut. 32:10-12) for God’s love…] Keep me as  the apple of your eye [the precious part of the eye that should be carefully guarded]; hide me in  the shadow of your wings [as a hen or an eagle protect their young beneath their wings]
17:9 from the wicked who are out to destroy me, from my mortal enemies [from Heb. phrase meaning “my enemies in soul” meaning “in greed” or who are intent on taking everything from him and destroying him] who surround me [David felt surrounded like a city under siege].
C. The Wicked
17:10 They close up [unlike the righteous whose hearts are open and obedient to God] their callous hearts, and their mouths speak with arrogance.
17:11 They have tracked me down, they now surround me, with eyes alert, to throw me to the ground.
17:12 They are like a lion [a symbol of strength] hungry for prey, like a fierce lion crouching in cover.
D. Prayer for Deliverance
17:13 Rise up, Lord [the psalmist asks God to confront the wicked in his stead], confront them, bring them down [an act of destruction]; with your sword rescue me from the wicked.
E. The Wicked
17:14 By your hand save me from such people, Lord, from those of this world whose reward is in this life [the wicked give little consideration to the next world; they receive their portion in this world]. May what you have stored up for the wicked fill their bellies [the psalmist asked God to give the wicked what they deserved for their wickedness]; may their children gorge themselves on it, and may there be leftovers for their little ones.
F. Hope in Righteousness
17:15 As for me [in contrast to the fate of the wicked], I will be vindicated and will see your face; when I awake [this may be an indication that this was an evening prayer], I will be satisfied [the wicked and the godly are not satisfied by the same things] with seeing your likeness [cf. 1 John 3:2].