Fix partial two-phase files left by crash during checkpoint

CheckPointTwoPhase() wrote each 2PC file in place, with O_TRUNC.  A
crash mid-write, or a base backup copying the file at that point left an
empty or partial file that would make startup fail, most likely on an
"incorrect size of file" ERROR.

The 2PC files are now written through a temporary file that gets renamed
at the end, relying on the atomicity of the rename to make startup safe,
be it after a crash or a base backup.

Author: Shihao Zhong <[email protected]>
Reviewed-by: Michael Paquier <[email protected]>
Reviewed-by: David Steele <[email protected]>
Discussion: 
https://postgr.es/m/cagrkxqs_on-plgcv6xjh8mvghdcpmfwtythw3r8pykug+hs...@mail.gmail.com
Backpatch-through: 14

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/a5ccf20801c821b72bb04d56b7320d52149a1ce5

Modified Files
--------------
src/backend/access/transam/twophase.c | 40 +++++++++++++++++++++++++++++------
1 file changed, 34 insertions(+), 6 deletions(-)

Reply via email to