In Psalm 3:1–2 David talked about his misery to God. Faith takes refuge in God and says: You are my shield (as God said to Abraham in Genesis 17:1). The purpose of the covenant with David was that he had to be a shield to his people. In Psalm 89:18 the king is called the shield. Just as God had given the king to be a shield to his people, so David confessed that the Lord is a shield to him.
3 But you, O LORD, are a shield about me, my glory, and the lifter of my head.