pg_receivewal, pg_basebackup: Fix temporary file cleanup on errors

pg_receivewal and the WAL streaming process of pg_basebackup could leave
temporary files behind when closing them failed, even though their
removal had been requested. For example, a temporary timeline history
file could remain after a write failure, unnecessarily occupying disk
space.

This happened because dir_close() attempted to unlink a file requested
with CLOSE_UNLINK only if the preceding operations succeeded. Failures
while finalizing compression, writing the final compressed data, or
closing the file could therefore skip the unlink operation.

Fix this by moving the unlink operation into the common cleanup path,
so that it is attempted even after an earlier failure.

Backpatch to all supported versions.

Author: Chao Li <[email protected]>
Reviewed-by: Xuneng Zhou <[email protected]>
Reviewed-by: Fujii Masao <[email protected]>
Discussion: https://postgr.es/m/[email protected]
Backpatch-through: 15

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/650925dad03ae3f5048e234d167c9f15df1e9853

Modified Files
--------------
src/bin/pg_basebackup/walmethods.c | 27 ++++++++++++++-------------
1 file changed, 14 insertions(+), 13 deletions(-)

Reply via email to