1 Chronicles 22 is a very significant chapter. In it David begins the preparations for the building of the temple. God informed David well prior to this (back in 2 Samuel 7/1 Chronicles 17) that it will not be David who will build "a house" for the Lord. It will be David's son, instead. "'I declare to you that the Lord will build a house for you: When your days are over and you go to be with your fathers, I will raise up your offspring to succeed you, one of your own sons, and I will establish his kingdom. He is the one who will build a house for me, and I will establish his throne forever. I will be his father, and he will be my son. I will never take my love away from him, as I took it away from your predecessor [Saul]. I will set him over my house and my kingdom forever; his throne will be established forever'" (1 Chronicles 17:10b-14, NIV).
So here in 2 Chronicles 22, following the events of the previous chapter, where David bought Araunah's threshing floor and set up an altar there as per the Lord's instructions in order to cease the angel of the Lord from taking any more lives in the plague caused by David's transgression and David's subsequent declaration that the house of the Lord will be built there, David now begins the long preparation process.
He gives orders to assemble the "aliens" (non-Israelites) living among them to be used as the primary work force (a pretty conventional way of doing things back then). He provides large amounts of building materials, including iron, bronze, and cedar logs (the cedar logs provided to David by the Sidonians and Tyrians).
Next he calls his son, Solomon, to him and gives him this charge:
"My son, I had it in my heart to build a house for the Name of the Lord my God. But this word of the Lord came to me: 'You have shed much blood and have fought many wars. You are not to build a house for my Name, because you have shed much blood on the earth in my sight. But you will have a son who will be a man of peace and rest, and I will give him rest from all his enemies on every side. His name will be Solomon, and I will grant Israel peace and quiet during his reign. He is the one who will build a house for my Name. He will be my son, and I will be his father. And I will establish the throne of his kingdom over Israel forever'.
"Now, my son, the Lord be with you, and may you have success and build the house of the Lord your God, as he said you would. May the Lord give you discretion and understanding when he puts you in command over Israel, so that you may keep the law of the Lord your God. Then you will have success if you are careful to observe the decrees and laws that the Lord gave Moses for Israel. Be strong and courageous. Do not be afraid or discouraged" (1 Chronicles 22:7-13).
David then repeats what he has provided so far towards the building of the temple in the way of materials and workers. After this, David orders "all the leaders of Israel to help his son Solomon" (1 Chronicles 22:17).
"He said to them, 'Is not the Lord your God with you? And h as he not granted you rest on every side? For he has handed the inhabitants of the land over to me, and the land is subject to the Lord and to his people. Now devote your heart and soul to seeking the Lord your God. Begin to build the sanctuary of the Lord God, so that you may bring the ark of the covenant of the Lord and the sacred articles belonging to God into the temple that will be built for the Name of the Lord'" (1 Chronicles 22:18-19).
***
The liturgical notes for this psalm state: "A psalm. A song. For the dedication of the temple. Of David." The commentary notes in my NIV Life Application Bible go with this and suggest that it might have been composed by David when he dedicated Araunah threshing floor after God had ceased his plague on Israel to discipline David. Also, another note suggests that the sickness that David says God healed him of in verses two and three might refer to the plague (although it might just as well refer to any other serious illness David had gone through).
Kidner (Psalms: An Introduction and Commentary), however, points out, "Yet without this title the psalm would have suggested simply recovery from sickness". He goes on to mention the theory that some suggest that the title notes might actually refer to the preceding psalm. I will, however, go with the assumption that the title given is correct and view this psalm as one David would have written in conjunction with the start of preparations to build the temple.
As per Kidner, this psalm can be broken down into three sections: the rescue (30:1-5), the foolish boast (30:6-10), and the celebration (30:11-12).
David speaks of how he will exalt God, for God "lifted [David] out of the depths" (30:1). David: "I called to you for help and you healed me. Oh Lord, you brought me up from the grave; you spared me from going down into the pit" (30:2-3).
"Sing to God, you saints of his; praise his holy name. For his anger lasts only a moment, but his favor lasts a lifetime; weeping may remain for a night, but rejoicing comes in the morning" (30:4-5). (I love those verses!)
The "foolish boast" of verses 6-10 must refer to, "When I felt secure, I said, 'I will never be shaken'" (30:6). But then David follows this a verse later with, "but when you hid your face, I was dismayed. "To you, O Lord, I called; to the Lord I cried for mercy. 'What gain is there in my destruction, in my going down into the pit? Will the dust praise you? Will it proclaim your faithfulness? Hear, O Lord, and be merciful to me; O Lord, be my help'" (30:8-10).
Finally, the "celebration":
"You turned my wailing into dancing; you removed my sackcloth and clothed me with joy, that my heart may sing to you and not be silent. O Lord my God, I will give you thanks forever" (30:11-12).
(All of that said, I can see what Kidner is saying about how the content of this psalm really gives no indication of it being written for the purpose of celebrating the dedication of the temple. The preceding psalm, Psalm 29, does seem a bit more appropriate for that, what with it's constant praise for God (his "glory", "strength", "the glory due his name", "the splendor of his holiness", etc.), and the way it finishes with, "And in his temple all cry, 'Glory!' The Lord sits enthroned over the flood; the Lord in enthroned as King forever. The Lord gives strength to his people; the Lord blesses his people with peace" (Psalm 29:9b-11). So perhaps that note really should go with Psalm 29 instead of Psalm 30?)