Zohar Chaye Sarah
Rabbi Elazar says that when the Holy One Blessed be He comes to resurrect the dead, he will call the angel, Duma, who is appointed on the registration of every soul that died. The angel Duma will list the accounts of the righteous, the devotees and the converts that dedicated their lives to the ways of the Torah. They will all be counted and resurrected, none of those would be missed.
“שְׂאוּ-מָרוֹם עֵינֵיכֶם וּרְאוּ מִי-בָרָא אֵלֶּה, הַמּוֹצִיא בְמִסְפָּר צְבָאָם; לְכֻלָּם, בְּשֵׁם יִקְרָא, מֵרֹב אוֹנִים וְאַמִּיץ כֹּחַ, אִישׁ לֹא נֶעְדָּר”
“Lift up your eyes on high and see: who created these? He who brings out their host by number, calling them all by name; by the greatness of his might and because he is strong in power, not one is missing.”
Tikun #49 of Tikunei Zohar reveals the meaning of this verse and says that ‘his might’ is the aspect of Keter and ‘Strong in power’ is the aspect of ‘Chokmah’, the two highest level where the light of the Resurrection would come from.
Rabbi Shmuel, son of Rabbi Yaakov adds that the souls of the wicked people also given to the hands of the angel Duma. He register them and take them to Gehennam where they follow their judgement process.
“לוּלֵי יְהוָה, עֶזְרָתָה לִּי כִּמְעַט, שָׁכְנָה דוּמָה נַפְשִׁי”
“Unless YHVH had been my helper, my soul would soon have dwelt with Duma.”
King David knew that once the souls are in the hands of Duma they can’t go back and must enter Gehennam. He gave thanks to God for forgiving his sin with Bathsheba. Without it he may had to be given to the hands of Duma.