In one of my Bibles, Psalm 30 has two superscriptions (what I would have called headings if I didn't also read commentaries). It is either a thanksgiving for recovery from grave illness or it is a song at the dedication of the temple. Or, it is both.
It begins with the recognition that the Lord has performed the rescue.
O Lord my God, I cried to you for help, and you have healed me.
It then directs the congregation to also give thanks.
Sing praises to the Lord, O you his faithful ones, and give thanks to his holy name.
It ends with the recognition that expression of gratitude is to be made openly and publicly:
You have turned my mourning into dancing;
you have taken off my sackcloth and clothed me with joy,
so that my soul may praise you and not be silent.
O Lord my God, I will give thanks to you forever.
As a person can be grateful for being healed from some personal sickness, a nation can be grateful for its restoration after a great disaster.
The notes in the Jewish Study Bible suggest that the psalm could have been used when the temple was rebuilt after exile, 515 BCE, or at its rededication after the victory of Judas Maccabaeus, 164 BCE. This psalm continues to be read on Hanukkah as well as part of the introductory liturgy for the daily, Sabbath, and festival morning services.