I've updated the patch with another approach: 0001: This sets the MemoryContext type to T_Invalid just before adding it to the aset freelist, allowing to distinguish between a MemoryContext that was placed in the freelist and shouldn't be used, and a valid one. The existing MemoryContextIsValid checks will be triggered if a MemoryContext in the freelist is used. I've also added additional MemoryContextIsValid to make sure the MemoryContext restored by a transaction is valid.
0002: Keep the replication command alive when there's an ongoing snapshot export. This way, the context restored is valid and can be reused. This requires the replication command context to be created under the TopMemoryContext. Regards, Anthonin Bonnefoy
v02-0001-Add-additional-memory-context-checks.patch
Description: Binary data
v02-0002-Avoid-using-deleted-context-with-replication-com.patch
Description: Binary data