Taken from Matthew Henry’s Commentary on the Whole Bible:
The shaking of a tree (they say) makes it take the deeper and faster root. The attempt of David’s enemies to discourage his confidence in God engages him to cleave so much the more closely to his first principles, and to review them, which he here does, abundantly to his own satisfaction and the silencing of all temptations to infidelity.
That which was shocking to his faith, and has been so to the faith of many, was the prosperity of wicked people in their wicked ways, and the straits and distresses which the best men are sometimes reduced to. Hence such an evil thought as this was apt to arise, Surely it is vain to serve God, and we may call the proud happy. But in order to stifle and shame all such thoughts, we are here called to consider:
(1) That there is a God in heaven. “The Lord is in His holy temple” above, where, though He is out of sight, we are not out of His. Let not the enemies of the saints insult over them, as if they were at a loss and at their wits’ end. No, they have a God, and they know where to find him and how to direct their prayer unto Him as their Father in heaven.
He is in His holy temple, that is, in His church. He is a God in covenant and communion with His people, through a Mediator, of whom the temple was a type. We need not say, “Who shall go up to heaven, to fetch us thence a God to trust to?” No, the word is near us, and God in the word. His Spirit is in His saints, those living temples, and the Lord is that Spirit.
(2) That this God governs the world. The Lord has not only His residence but His throne in heaven, and He has “set their dominion over the earth” (Job 38:33). For having “established His throne in heaven, … His kingdom rules over all” (Psalm 103:19).
Let us by faith see God on His throne, on His throne of glory, infinitely transcending the splendor and majesty of earthly princes—on His throne of government, giving law, giving motion, and giving aim, to all the creatures; on His throne of judgment, rendering to every man according to His works; and on His throne of grace, to which His people may come boldly for mercy and grace. We shall then see no reason to be discouraged by the pride and power of oppressors or any of the afflictions that attend the righteous.