There is a lot of imagery in this short verse. There is a reason why these words about God's amazing protection gush forth from David. The Psalm begins with this description of David and why he wrote it: "...who addressed the words of this song to the LORD on the day when the LORD rescued him from the hand of his enemies and from the hand of Saul..."
David had been an outlaw fugitive running and hiding in the Judean desert. He knew how to hide in a rock. And that is the imagery that pours from him in this psalm. He saw God's protection in all of the desert experiences of his life.
The words pour out the beauty of the bleak desert landscape. God is a rock, a fortress, and a stronghold. God shields David and delivers him. God is the salvation that comes at the blowing of the ram's horn. God was David's protective delivering army. And David felt secure in the stronghold of God's salvation.
Yet when you read the accounts of David in the desert, there are moments where it seems he will fall. And David does not always look first to God. There was a mercy and grace extended in the desert when David miserably tried to save himself by his own wits. God often kept David safe in spite of all of David's mistakes. You can get the context of all this by reading the history of it in 1 Samuel chapters 19 through 31. These were hard times by all definitions. But God was a good God. And that is a comfort to us all. In all times God is good. In hard times we trust Him all the more. He is our Rock.. our fortress of protection when we are running in the desert.