סימן קלב סעיף ה
יֵשׁ נוֹהֲגִין לָלוּן בְּבֵית הַכְּנֶסֶת וְלוֹמַר שִׁירוֹת וְתִשְׁבָּחוֹת כָּל הַלָּיְלָה. וּכְשֶׁצָּרִיךְ לִישׁוֹן, יַרְחִיק אֶת עַצְמוֹ מִן אֲרוֹן הַקֹּדֶשׁ. וְהַחַזָּנִים לֹא יֵעֹרוּ, כִּי עַל יְדֵי זֶה מְאַבְּדִין קוֹלָן. קֹדֶם הַשְּׁכִיבָה יֹאמַר אַרְבָּעָה מִזְמוֹרֵי תְהִלִּים הָרִאשוֹנִים, שֶׁהֵם מְסֻגָּלִים לְהִנָּצֵל מִקֶּרִי, רַחֲמָנָא לִצְּלָן, כִּי יֵשׁ בָּהֶם שְׁלֹשׁ מֵאוֹת וְשֵׁש תֵּבוֹת וְאַרְבָּעָה מִזְמוֹרִים, עוֹלִין שְׁלֹשׁ מֵאוֹת וָעֶשֶׂר כְּמִנְיַן קֶרִי. וְרָאשֵׁי וְסוֹפֵי הַמִּזְמוֹרִים, עוֹלִים מֵאָה עֶשְׂרִים וָשֵׁשׁ, וְאַרְבָּעָה מִזְמוֹרִים וְהַכּוֹלֵל, בְּיַחַד עוֹלִים מֵאָה שְׁלֹשִׁים וְאַחַת, כְּמִנְיָן סַמָּאֵל, וִיכַוֵּן לְסַלְּקוֹ מֵעָלָיו. וְטוֹב שֶׁלֹא יִתְעַטֵּף בְּכָרִים וּכְסָתוֹת הַמְחַמְּמִין, וְעל כָּל פָּנִים לֹא יְכַסֶּה רַגְלָיו (תריט)
Some people have the custom to stay in the synagogue reciting songs of praise all night.4Levush writes that it is better to go home and sleep, for a person who is up all night will doze off by day and pray without proper concentration. (Mishnah Berurah 619:14) When they feel the need to sleep5It is not permitted to sleep in the synagogue, however, unless you actually intended to recite “Songs of praise” all night. (Ibid 619:6) they should move away from the Ark. The Chazzanim should not stay awake for it will cause them to lose their voice. Before going to sleep you should say the first four Psalms,6This is in addition to the regular Kerias Shemah prayer that is recited at night. (Ibid 619:4) for they are particularly beneficial in preventing nocturnal emission, may the Merciful One save us. For [these four Psalms] contain a total of three hundred and six words. By adding four, [to the number of the] Psalms, you arrive at a total of three hundred and ten, which is the numerical equivalence of קרי, keri, [nocturnal emission]. [The numerical value] of the first and last letters of the four Psalms amounts to one hundred and twenty-six, plus the four of the four Psalms, plus one, the general binding factor which unites the word, together makes a total of one hundred and thirty-one, the numerical equivalence of סמאל, [malevolent angel] and you should have in mind to shake off his evil influence. It is best not to cover yourself with pillows and blankets that make you feel hot; but at any rate you should not cover your legs.
תנא דבי אליהו כל השונה הלכות בכל יום מובטח לו שהוא בן העולם הבא שנאמר הליכות עולם לו אל תקרי הליכות אלא הלכות (נדה ע"ג.)