This is from another thread on pancaking that I replied to. Having it happen at night adds an extra dimension that I'll talk about at the end of this...
First, formed to semi-formed stools never pancake for me - only my soft stools pancake, so fiber is key (qualifier: "for me" - everyone is unique, your experience may be different). I ensure that I include something that is fiber-rich with every meal. I eat oatmeal each morning, fibrous veggies with each meal, and I supplement with a bite or three of those carb balance wraps (18g of fiber!) throughout the day.
Secondly, air is crucial. Without air, the bag will press up against your stoma, and any soft stool will immediately stick to it. I always ensure I have some air in the bag before closing it up.
Next is lubricant. I use olive oil, but as others have suggested, any vegetable oil should suffice. It's much less expensive than the actual stoma lube products. But once I put in the oil (and air) and seal the bag, I tip the drain end up to get the oil near the stoma and rub the stoma-facing part of the bag in the oil so that it's well lubricated.
Finally, bag washing works. If pancaking does start, it won't stop until you either wash or change the bag. Washing is a lot less expensive... 😉. I use a bit of hot water and swish it all around in the bag a few times to wash out the sticky stuff (then rinse and repeat as needed), then add fresh lubricant. Do be careful with this though, you don't want to get the vent filters wet or you'll be plagued by stoma aroma.
As far as pancaking at night, this can also be impacted by sleeping position. I have long been a side sleeper, switching sides through the night. But I have found that sleeping on my stoma side can press the bag against my stoma and cause pancaking. Now, I sleep predominantly on my right side, occasionally switching to my back. But even sleeping on my back doesn't always produce the best results.
I've never (knocking on wood just now 😉) had a leak. The skin around my stoma is smooth, and I never had a leak using only a standard bag... That said, I've switched from paste to barrier rings recently, and still no leaks.
For me, the worst side effect from pancaking has been that it causes the output to cake on the vent filters, resulting in stoma aroma.
I hope this contains a helpful nugget or two for you. Find what works for you, and I wish you the best of success in this part of your adventure.