The closing chapters of 2 Samuel provide sort of a wrap-up of David’s reign: avenging the Gibeonites (they “were not of the people of Israel but of the remnant of the Amorites. Although the people of Israel had sworn to spare them, Saul had sought to strike them down in his zeal for the people of Israel and Judah” 21:21), David’s song of thanksgiving, a listing of his mighty men, and the census David took of Israel.
David’s song of thanksgiving is almost identical with Psalm 18. The heading of the song is: “And David spoke to the Lord the words of this song on the day when the Lord delivered him from the hand of all his enemies, and from the hand of Saul” (22:1). The phrase “from the hand of all his enemies” is important, I think. David was able to look back on his entire life and see that God never left him. He had many struggles, but through his entire life, God walked with him and kept him. With “20/20 hindsight,” looking over life to this moment, surely we can say with David, “This God--his way is perfect; the word of the Lord proves true; he is a shield for all those who take refuge in him” (22:31).
God is our refuge and our strength,
in straits a present aid;
therefore, although the earth remove,
we will not be afraid.