Surely the righteous shall give thanks unto thy name - Unto thee.
(1) they will have occasion to do it;
(2) they will be disposed to do it.
They will not be unmindful of the favors conferred upon them; it will be a characteristic of them that they “will” be thankful.
The upright shall dwell in thy presence - They shall be under thy protection; they shall be admitted to thy favor; they shall dwell in thy dwelling-place.
(1) On earth they shall enjoy his favor - “as if” they abode with God.
(2) in heaven they will be permitted to dwell with him forever.
The general idea of the psalm is, that the poor, the persecuted, the afflicted, if righteous, shall enjoy the favor and protection of God. God is on their side, and not on the side of the wicked who oppress them. But then, people “should be righteous” in order that they may find the favor of God and dwell with him. There is no reason why a “poor” wicked man should enjoy the favor of God anymore than why a “rich” wicked man should. It is not poverty or riches that commend us to God; it is faith, and holiness, and love, and obedience, in the condition of life in which we are placed, be it in a cottage or a palace.