The verse says, [Serve Hashem with awe that you may] rejoice when there is trembling (Tehillim 2:11). Our Sages comment about this: Where there is rejoicing, there must there be trembling. Therefore, any person who fears Hashem should remember Him and before entering a place of rejoicing should accept upon himself to not act inappropriately with excessive food and drink and to not talk excessively or any other similar behavior that he is likely to engage there. And in the midst of the merriment, he should remember to have pure fear of Hashem on his mind. This is a measure that works to prevent the wine from harming the person and losing his [spiritual] balance.
At the same time the person needs to fulfill the mitzvah of remembering that we angered the Holy One [in the Wilderness] and of remembering Yerushalayim. This, too, will serve as a great protection against acting out of line and will instead help the person behave uprightly, with measure and composure.