aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFujii Masao <fujii@postgresql.org>2015-09-09 22:51:44 +0900
committerFujii Masao <fujii@postgresql.org>2015-09-09 22:52:28 +0900
commit65f37b3e9b0aea59cc98a2e23f45bb8fb6a56395 (patch)
treee48584158042c459a7a3fcab2866d2d733e9552e /src
parent9801bae217e9d3f72e2d1f3dd780bf0bf9365dae (diff)
downloadpostgresql-65f37b3e9b0aea59cc98a2e23f45bb8fb6a56395.tar.gz
postgresql-65f37b3e9b0aea59cc98a2e23f45bb8fb6a56395.zip
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
Diffstat (limited to 'src')
-rw-r--r--src/backend/access/transam/xlog.c10
-rw-r--r--src/backend/postmaster/postmaster.c21
-rw-r--r--src/include/access/xlog.h1
3 files changed, 32 insertions, 0 deletions
diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c
index 127bc5888f3..152d4ede37a 100644
--- a/src/backend/access/transam/xlog.c
+++ b/src/backend/access/transam/xlog.c
@@ -11588,6 +11588,16 @@ CheckForStandbyTrigger(void)
}
/*
+ * Remove the files signaling a standby promotion request.
+ */
+void
+RemovePromoteSignalFiles(void)
+{
+ unlink(PROMOTE_SIGNAL_FILE);
+ 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 1818f7ce46a..baa43b203f1 100644
--- a/src/backend/postmaster/postmaster.c
+++ b/src/backend/postmaster/postmaster.c
@@ -1176,6 +1176,27 @@ PostmasterMain(int argc, char *argv[])
RemovePgTempFiles();
/*
+ * Forcibly remove the files signaling a standby promotion
+ * request. Otherwise, the existence of those files triggers
+ * 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.
+ *
+ * Note that promotion signal files need to be removed before
+ * the startup process is invoked. Because, after that, they can
+ * be used by postmaster's SIGUSR1 signal handler.
+ */
+ RemovePromoteSignalFiles();
+
+ /*
* If enabled, start up syslogger collection subprocess
*/
SysLoggerPID = SysLogger_Start();
diff --git a/src/include/access/xlog.h b/src/include/access/xlog.h
index 6dacee2fbbd..790ca66f8a6 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 RemovePromoteSignalFiles(void);
extern bool CheckPromoteSignal(void);
extern void WakeupRecovery(void);