The primary purpose of including this psalm in the Ascents collection is to serve as a reminder as to why there is an annual pilgrimage to Jerusalem. The main point is that it is the symbolic earthly throne of Jehovah and the throne of David. It’s the city of promises; God put His stamp of approval on this city as the place to meet Him. This psalm quotes part of Solomon’s prayer in the Temple and echoes strongly of sections of 1 Samuel.
The word translated here as “affliction” refers to the full breadth of David’s humility before the Lord, and how much he was willing to sacrifice in his zeal for the Lord’s reputation. Thus, David couldn’t sleep in his newly captured fortress until he had settled the business of where the Ark of Covenant should rest.
Keep in mind that the most recent location of the Tabernacle was just outside Jerusalem in Nob. During some of King Saul’s warfare with the Philistines, the Ark was captured and taken to their territory. The Lord humbled the Philistines and they sent the Ark away on a cart, not daring to accompany it. The Ark ended up in Beth Shemesh, which was supposed to be a city of the Priests, but they weren’t ready to handle the Ark. So they called for a noble family in Kiriath-jearim to come and take custody of it. The Ark was properly handled and kept there for twenty years. David brought it up from there to a tent in his palace courtyard. The passage here refers to that previous resting place as one of the fields cut into a forest covering the hill there, and the city was named after that forest (jaar). Thus, we have a poetic rendering of how David was quite diligent in searching for the Ark as the symbolic throne of God.
We see the picture of Israel inviting God to accept Jerusalem as His new resting place on the earth. It was a giddy day of celebration and David humbled himself once more. So the priests and the people put on their festive garments, but their true adornment was praise and joy. It was very much like a coronation celebration for a very good reason, as Jehovah was the true Ruler of Israel, the suzerain for whom the whole kingdom was vassal. “Dwell here, O Lord!”
The response to this supplication was first the reminder that God had most emphatically chosen David as His shepherd over the nation. It was an extravagant promise that David found overwhelming. Then the psalm notes that this is part of a package deal in which God chose also to make Zion His earthly home. As part of His glory shining from this place, it would be one of the wealthiest cities on earth, wherein even the poorest would have enough to eat and find safe shelter. And if the people are faithful, they would indeed be adorned in the garments of praise and worship. They could rest assured that God would never leave them without a wise king.