This psalm is generally thought to have been written by David upon his being advanced to the throne; on account of which he praises the Lord, who had supported him under many exercises, and had made good his promise to him, at least in part; and he firmly believed the accomplishment of the rest, that he would perfect what concerned him, Psalm 138:8.

It reads in Psalm 138:1-8 NIV>
“Psalm Of David.
I will praise you, Lord, with all my heart; before the “gods” I will sing your praise. I will bow down toward your holy temple and will praise your name for your unfailing love and your faithfulness,for you have so exalted your solemn decree that it surpasses your fame. When I called, you answered me; you greatly emboldened me. May all the kings of the earth praise you, Lord, when they hear what you have decreed. May they sing of the ways of the Lord, for the glory of the Lord is great. Though the Lord is exalted, he looks kindly on the lowly; though lofty, he sees them from afar. Though I walk in the midst of trouble, you preserve my life. You stretch out your hand against the anger of my foes; with your right hand you save me. The Lord will vindicate me; your love, Lord, endures forever, do not abandon the works of your hands.