diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c index 1dd31b3..6141d33 100644 --- a/src/backend/access/transam/xlog.c +++ b/src/backend/access/transam/xlog.c @@ -77,8 +77,6 @@ extern uint32 bootstrap_data_checksum_version; /* File path names (all relative to $PGDATA) */ #define RECOVERY_COMMAND_FILE "recovery.conf" #define RECOVERY_COMMAND_DONE "recovery.done" -#define PROMOTE_SIGNAL_FILE "promote" -#define FALLBACK_PROMOTE_SIGNAL_FILE "fallback_promote" /* User-settable parameters */ @@ -11531,6 +11529,21 @@ CheckForStandbyTrigger(void) } /* + * Remove any trigger file able to trigger promotion. This should be + * called at the beginning of recovery. + */ +void +RemoveStandbyTrigger(void) +{ + struct stat stat_buf; + + if (stat(PROMOTE_SIGNAL_FILE, &stat_buf) == 0) + unlink(PROMOTE_SIGNAL_FILE); + if (stat(FALLBACK_PROMOTE_SIGNAL_FILE, &stat_buf) == 0) + unlink(FALLBACK_PROMOTE_SIGNAL_FILE); +} + +/* * Check to see if a promote request has arrived. Should be * called by postmaster after receiving SIGUSR1. */ diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c index df8037b..c0a3f79 100644 --- a/src/backend/postmaster/postmaster.c +++ b/src/backend/postmaster/postmaster.c @@ -1160,6 +1160,13 @@ PostmasterMain(int argc, char *argv[]) RemovePgTempFiles(); /* + * Remove any trigger file able to trigger promotion, this is safe from + * race conditions involving signals as no other processes are running + * yet. + */ + RemoveStandbyTrigger(); + + /* * If enabled, start up syslogger collection subprocess */ SysLoggerPID = SysLogger_Start(); diff --git a/src/backend/replication/basebackup.c b/src/backend/replication/basebackup.c index 1e86e4c..b3d0498 100644 --- a/src/backend/replication/basebackup.c +++ b/src/backend/replication/basebackup.c @@ -911,6 +911,15 @@ sendDir(char *path, int basepathlen, bool sizeonly, List *tablespaces, continue; /* + * Skip promote signal files. Those files may have been created by + * pg_ctl to trigger a promotion but they do not belong to a base + * backup. + */ + if (strcmp(de->d_name, PROMOTE_SIGNAL_FILE) == 0 || + strcmp(de->d_name, FALLBACK_PROMOTE_SIGNAL_FILE) == 0) + continue; + + /* * Check if the postmaster has signaled us to exit, and abort with an * error in that case. The error handler further up will call * do_pg_abort_backup() for us. Also check that if the backup was diff --git a/src/include/access/xlog.h b/src/include/access/xlog.h index 6dacee2..1d4a0af 100644 --- a/src/include/access/xlog.h +++ b/src/include/access/xlog.h @@ -261,6 +261,7 @@ extern XLogRecPtr GetRedoRecPtr(void); extern XLogRecPtr GetInsertRecPtr(void); extern XLogRecPtr GetFlushRecPtr(void); extern void GetNextXidAndEpoch(TransactionId *xid, uint32 *epoch); +extern void RemoveStandbyTrigger(void); extern bool CheckPromoteSignal(void); extern void WakeupRecovery(void); diff --git a/src/include/access/xlog_internal.h b/src/include/access/xlog_internal.h index 5ebaa5f..c385e6a 100644 --- a/src/include/access/xlog_internal.h +++ b/src/include/access/xlog_internal.h @@ -132,6 +132,12 @@ typedef XLogLongPageHeaderData *XLogLongPageHeader; #define XLOG_CONTROL_FILE "global/pg_control" /* + * Promote signal files (relative to $PGDATA) + */ +#define PROMOTE_SIGNAL_FILE "promote" +#define FALLBACK_PROMOTE_SIGNAL_FILE "fallback_promote" + +/* * These macros encapsulate knowledge about the exact layout of XLog file * names, timeline history file names, and archive-status file names. */