Historical commentary by Matthew Henry. The wording and interpretations below belong to the original source.
Consolations.
We have here the lively actings of David's faith in his prayer, by which he was assured that the issue would be comfortable, though the attempt upon him was formidable.
I. He was sure that he had God on his side, that God took his part ( v. 4 ); he speaks it with an air of triumph and exultation, Behold, God is my helper. If we be for him, he is for us; and, if he be for us, we shall have such help in him that we need not fear any power engaged against us. Though men and devils aim to be our destroyers, they shall not prevail while God is our helper: The Lord is with those that uphold my soul. Compare Ps. cxviii. 7 , " The Lord taketh my part with those that help me. There are some that uphold me, and God is one of them; he is the principal one; none of them could help me if he did not help them." Every creature is that to us (and no more) that God makes it to be. He means, "The Lord is he that upholds my soul, and keeps me from tiring in my work and sinking under my burdens." He that by his providence upholds all things by his grace upholds the souls of his people. God, who will in due time save his people, does, in the mean time, sustain them and bear them up, so that the spirit he has made shall not fail before him.
II. God taking part with him, he doubted not but his enemies should both flee and fall before him ( v. 5 ): " He shall reward evil unto my enemies that observe me, seeking an opportunity to do me a mischief. The evil they designed against me the righteous God will return upon their own heads." David would not render evil to them, but he knew God would: I as a deaf man heard not, for thou wilt hear. The enemies we forgive, if they repent not, God will judge; and for this reason we must not avenge ourselves, because God has said, Vengeance is mine. But he prays, Cut them off in thy truth. This is not a prayer of malice, but a prayer of faith; for it has an eye to the word of God, and only desires the performance of that. There is truth in God's threatenings as well as in his promises, and sinners that repent not will find it so to their cost.
III. He promises to give thanks to God for all the experiences he had had of his goodness to him ( v. 6 ): I will sacrifice unto thee. Though sacrifices were expensive, yet, when God required that his worshippers should in that way praise him, David would not only offer them, but offer them freely and without grudging. All our spiritual sacrifices must, in this sense, be free-will-offerings; for God loves a cheerful giver. Yet he will not only bring his sacrifice, which was but the shadow, the ceremony; he will mind the substance: I will praise thy name. A thankful heart, and the calves of our lips giving thanks to his name, are the sacrifices God will accept: " I will praise thy name, for it is good. Thy name is not only great but good, and therefore to be praised. To praise thy name is not only what we are bound to, but it is good, it is pleasant, it is profitable; it is good for us ( Ps. xcii. 1 ); therefore I will praise thy name. "