diff options
Diffstat (limited to 'src/backend/access/transam/xlog.c')
-rw-r--r-- | src/backend/access/transam/xlog.c | 40 |
1 files changed, 7 insertions, 33 deletions
diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c index 7d23d8e21c6..7108bec69bb 100644 --- a/src/backend/access/transam/xlog.c +++ b/src/backend/access/transam/xlog.c @@ -3420,34 +3420,16 @@ InstallXLogFileSegment(XLogSegNo *segno, char *tmppath, } /* - * Prefer link() to rename() here just to be really sure that we don't - * overwrite an existing logfile. However, there shouldn't be one, so - * rename() is an acceptable substitute except for the truly paranoid. + * Perform the rename using link if available, paranoidly trying to avoid + * overwriting an existing file (there shouldn't be one). */ -#if HAVE_WORKING_LINK - if (link(tmppath, path) < 0) + if (durable_link_or_rename(tmppath, path, LOG) != 0) { if (use_lock) LWLockRelease(ControlFileLock); - ereport(LOG, - (errcode_for_file_access(), - errmsg("could not link file \"%s\" to \"%s\" (initialization of log file): %m", - tmppath, path))); - return false; - } - unlink(tmppath); -#else - if (rename(tmppath, path) < 0) - { - if (use_lock) - LWLockRelease(ControlFileLock); - ereport(LOG, - (errcode_for_file_access(), - errmsg("could not rename file \"%s\" to \"%s\" (initialization of log file): %m", - tmppath, path))); + /* durable_link_or_rename already emitted log message */ return false; } -#endif if (use_lock) LWLockRelease(ControlFileLock); @@ -5428,11 +5410,7 @@ exitArchiveRecovery(TimeLineID endTLI, XLogSegNo endLogSegNo) * re-enter archive recovery mode in a subsequent crash. */ unlink(RECOVERY_COMMAND_DONE); - if (rename(RECOVERY_COMMAND_FILE, RECOVERY_COMMAND_DONE) != 0) - ereport(FATAL, - (errcode_for_file_access(), - errmsg("could not rename file \"%s\" to \"%s\": %m", - RECOVERY_COMMAND_FILE, RECOVERY_COMMAND_DONE))); + durable_rename(RECOVERY_COMMAND_FILE, RECOVERY_COMMAND_DONE, FATAL); ereport(LOG, (errmsg("archive recovery complete"))); @@ -6619,11 +6597,7 @@ StartupXLOG(void) if (haveBackupLabel) { unlink(BACKUP_LABEL_OLD); - if (rename(BACKUP_LABEL_FILE, BACKUP_LABEL_OLD) != 0) - ereport(FATAL, - (errcode_for_file_access(), - errmsg("could not rename file \"%s\" to \"%s\": %m", - BACKUP_LABEL_FILE, BACKUP_LABEL_OLD))); + durable_rename(BACKUP_LABEL_FILE, BACKUP_LABEL_OLD, FATAL); } /* Check that the GUCs used to generate the WAL allow recovery */ @@ -10705,7 +10679,7 @@ CancelBackup(void) /* remove leftover file from previously canceled backup if it exists */ unlink(BACKUP_LABEL_OLD); - if (rename(BACKUP_LABEL_FILE, BACKUP_LABEL_OLD) == 0) + if (durable_rename(BACKUP_LABEL_FILE, BACKUP_LABEL_OLD, DEBUG1) == 0) { ereport(LOG, (errmsg("online backup mode canceled"), |