Hi, thanks for using healthcare magic
There is a condition called defecation syncope
which is temporary loss of consciousness
on defecation. It is associated with being pale,nauseated,sweaty and weak.
When you start to experience symptoms then you can try counter mechanisms such as gripping your fingers in a fist, tensing your arms, crossing the legs and squeezing the thighs together.
In addition , you may want to consider visiting your doctor for an assessment, in some persons episodes can result from abnormal heart rhymth or other heart disease
I hope this helps