Many people believe this Psalm was written in the context of David fleeeing from his son Absalom.
Absalom was a slimy character who sought to ingrate the people to him by sitting at the city entrance and helping them with their disputes.
David fled the city under conflict. Sad really that the great warrior king fled from his own city, and his own son.
Absalom then, under advice, slept with Davids concubines in a tent out in the open, so the people knew that he was doing it.
This confirmed the prophecy of Nathan the prophet given when David sinned.
Its a sad and gritty story, yet in the midst of it the most famous Psalm of all was written.