Remember, O Lord
This long pilgrim psalm is a prayer for the LORD to honor the commitment of David by fulfilling the promises to David. David had vowed to find a resting place for the ark of the covenant, and the LORD vowed to make an everlasting covenant with his house. It is the fulfillment of this latter vow, based on the completion of the former vow, for which the psalmist prays.
The faithfulness of David is not only remembered in this psalm, but relived by the faithful in the use of the psalm. A ritual procession seems to lie in the background of the psalm as the composition celebrates finding the ark and proceeding to Jerusalem (2 Sam. 6:12–19).
But as one might expect in such a complex composition, there are numerous views that have been put forward concerning its writing. The traditional view is that it was written by David after receiving the covenant (2 Sam. 7). The psalm then may have been composed for the actual transference of the ark to Jerusalem (or to commemorate it with a psalm to be used in the future); and it would have included an early prayer for God to fulfill the promise he had made to David. A second view is that the psalm was written a little later, perhaps by Solomon or a poet of his time, in commemoration of David’s faithful act—which Solomon completed by building the temple.
There is no information in the psalm about its setting or occasion. One would gather from the passage that the Israelites were living in the land, that the central sanctuary was operating, and that they prayed for the Davidic covenant to be fulfilled. This may or may not indicate that kingship was in difficulty at the time. Likewise the prayer for the priests to be clothed with righteousness may or may not indicate the priesthood was corrupt.
Whatever the circumstances, the prayer called for the fulfillment of the promises, and so ultimately looked to that glorious future known as the Messianic age.