The Shulhan Aruch (Orah Haim 120:1), quoting the Gemara (Berachot 55), says that if one had a bad dream which caused one great distress one shouldgo before three people, preferably who like him, and should say “I saw good dream”, and they should reply “it’s a good dream”. This process is known as “Hatavat Halom”, the rendering good of a dream. Rabbi Yosef Leib Bloch (Shiurei Da’at, vol. I) explains that a dream is a message from Hashem which is capable of being healed, as it were. It is up to the dreamer to address this dream and seek out three colleagues, and by doing so, one turns the dreaminto a positive message. Many Siddurim, including Moroccans ones, have a longer text of the Hatavat Halom which includes different verses and is longer than the very concise version that is written in the Shulhan Aruch. The longer text is based on what is recorded by the Arizal (Peri Etz Haim, Sha’ar Hazarat HaShatz, ch. 7) and the Kaf HaHaim (O.H. 220:11). It is worthwhile to note that there are many different types of dreams. The Ramhal (Derech Hashem: Dreams) mentions dreams of insignificance, for example things that one may have seen during the day, or things he may have eaten, or angels putting in falsehoods in one’s dreams. Nonetheless, if one has a dream that he feels has truth and appears to be concerning, this could be a message from Hashem and he should perform the Hatavat Halom.
Another remedy for a bad dream is recorded in the Shulhan Aruch (Orah Haim 130:1), which says that during the auspicious time during which Birkat Kohanim takes place, one should recite a special prayer (written in many Siddurim) to remedy one’s bad dream.
Rabbi Moshe Toledano (Shamayim Hadashim, § 66), citing the Magen Avraham, discusses a situation in which one cannot find three people for Hatavat Halom. In such a case, one can do it in front of two people and then do it again in front of a third person. Even though all three people were not present at the same time, it appears that doing it in such a fashion is also acceptable.
The Elya Rabba, quoting the Shela, states that one may do Hatavat Halomeven on Shabbat. The rationale is that a bad dream can cause a person extreme anxiety and thus remedying the dream is a type of Pikuah Nefesh, preservation of life, which is permitted on Shabbat.
Summary:Someone who had a truly distressing dream should performHatavat Halom.