Nikhil, do you mind if I try something like that? As we already know what is the first XID when beginning redo via ShmemVariableCache->nextXid it is possible to discard 2PC files that should not be here.
Yeah, that is ok.
What makes me worry is the control of the maximum number of entries in shared memory. If there are legit 2PC files that are flushed on disk at checkpoint, you would finish with potentially more 2PC transactions than what should be possible (even if updates of max_prepared_xacts are WAL-logged).
The max_prepared_xacts number restricts the number of pending PREPARED transactions *across* the 2PC files and shmem inredo entries. We can never have more entries than this value.
Regards,
Nikhils
--
Nikhil Sontakke http://www.2ndQuadrant.com/ PostgreSQL/Postgres-XL Development, 24x7 Support, Training & Services