Psalms 30:1

מִזְמוֹר שִׁיר חֲנֻכַּת הַבַּיִת לְדָוִד

A Psalm: a song for the dedication of the Temple, by David

This Psalm, which is recited daily before pesukei d’zimra, was composed by King David for the inauguration of the Temple. As Rashi on this verse points out, the Temple wasn’t actually built until the reign of David’s son, King Solomon. Nevertheless, David eagerly anticipated the building of the Temple – an honor he was necessarily denied because of his background as a warrior – and he composed this song specifically for the occasion.