8000 Remove files signaling a standby promotion request at postmaster startup · postgrespro/postgres@96f6a0c · GitHub
[go: up one dir, main page]

Skip to content

Commit 96f6a0c

Browse files
committed
Remove files signaling a standby promotion request at postmaster startup
This commit makes postmaster forcibly remove the files signaling a standby promotion request. Otherwise, the existence of those files can trigger a promotion too early, whether a user wants that or not. This removal of files is usually unnecessary because they can exist only during a few moments during a standby promotion. However there is a race condition: if pg_ctl promote is executed and creates the files during a promotion, the files can stay around even after the server is brought up to new master. Then, if new standby starts by using the backup taken from that master, the files can exist at the server startup and should be removed in order to avoid an unexpected promotion. Back-patch to 9.1 where promote signal file was introduced. Problem reported by Feike Steenbergen. Original patch by Michael Paquier, modified by me. Discussion: 20150528100705.4686.91426@wrigleys.postgresql.org
1 parent c3e0ddd commit 96f6a0c

File tree

3 files changed

+32
-0
lines changed
  • include/access
  • 3 files changed

    +32
    -0
    lines changed

    src/backend/access/transam/xlog.c

    Lines changed: 10 additions & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -11587,6 +11587,16 @@ CheckForStandbyTrigger(void)
    1158711587
    return false;
    1158811588
    }
    1158911589

    11590+
    /*
    11591+
    * Remove the files signaling a standby promotion request.
    11592+
    */
    11593+
    void
    11594+
    RemovePromoteSignalFiles(void)
    11595+
    {
    11596+
    unlink(PROMOTE_SIGNAL_FILE);
    11597+
    unlink(FALLBACK_PROMOTE_SIGNAL_FILE);
    11598+
    }
    11599+
    1159011600
    /*
    1159111601
    * Check to see if a promote request has arrived. Should be
    1159211602
    * called by postmaster after receiving SIGUSR1.

    src/backend/postmaster/postmaster.c

    Lines changed: 21 additions & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -1175,6 +1175,27 @@ PostmasterMain(int argc, char *argv[])
    11751175
    */
    11761176
    RemovePgTempFiles();
    11771177

    1178+
    /*
    1179+
    * Forcibly remove the files signaling a standby promotion
    1180+
    * request. Otherwise, the existence of those files triggers
    1181+
    * a promotion too early, whether a user wants that or not.
    1182+
    *
    1183+
    * This removal of files is usually unnecessary because they
    1184+
    * can exist only during a few moments during a standby
    1185+
    * promotion. However there is a race condition: if pg_ctl promote
    1186+
    * is executed and creates the files during a promotion,
    1187+
    * the files can stay around even after the server is brought up
    1188+
    * to new master. Then, if new standby starts by using the backup
    1189+
    * taken from that master, the files can exist at the server
    1190+
    * startup and should be removed in order to avoid an unexpected
    1191+
    * promotion.
    1192+
    *
    1193+
    * Note that promotion signal files need to be removed before
    1194+
    * the startup process is invoked. Because, after that, they can
    1195+
    * be used by postmaster's SIGUSR1 signal handler.
    1196+
    */
    1197+
    RemovePromoteSignalFiles();
    1198+
    11781199
    /*
    11791200
    * If enabled, start up syslogger collection subprocess
    11801201
    */

    src/include/access/xlog.h

    Lines changed: 1 addition & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -261,6 +261,7 @@ extern XLogRecPtr GetRedoRecPtr(void);
    261261
    extern XLogRecPtr GetInsertRecPtr(void);
    262262
    extern XLogRecPtr GetFlushRecPtr(void);
    263263
    extern void GetNextXidAndEpoch(TransactionId *xid, uint32 *epoch);
    264+
    extern void RemovePromoteSignalFiles(void);
    264265

    265266
    extern bool CheckPromoteSignal(void);
    266267
    extern void WakeupRecovery(void);

    0 commit comments

    Comments
     (0)
    0