@@ -992,6 +992,66 @@ PostmasterMain(int argc, char *argv[])
992992 */
993993 InitializeMaxBackends ();
994994
995+ /*
996+ * Initialize pipe (or process handle on Windows) that allows children to
997+ * wake up from sleep on postmaster death.
998+ */
999+ InitPostmasterDeathWatchHandle ();
1000+
1001+ /*
1002+ * Forcibly remove the files signaling a standby promotion request.
1003+ * Otherwise, the existence of those files triggers a promotion too early,
1004+ * whether a user wants that or not.
1005+ *
1006+ * This removal of files is usually unnecessary because they can exist
1007+ * only during a few moments during a standby promotion. However there is
1008+ * a race condition: if pg_ctl promote is executed and creates the files
1009+ * during a promotion, the files can stay around even after the server is
1010+ * brought up to new master. Then, if new standby starts by using the
1011+ * backup taken from that master, the files can exist at the server
1012+ * startup and should be removed in order to avoid an unexpected
1013+ * promotion.
1014+ *
1015+ * Note that promotion signal files need to be removed before the startup
1016+ * process is invoked. Because, after that, they can be used by
1017+ * postmaster's SIGUSR1 signal handler.
1018+ */
1019+ RemovePromoteSignalFiles ();
1020+
1021+ /* Do the same for logrotate signal file */
1022+ RemoveLogrotateSignalFiles ();
1023+
1024+ /* Remove any outdated file holding the current log filenames. */
1025+ if (unlink (LOG_METAINFO_DATAFILE ) < 0 && errno != ENOENT )
1026+ ereport (LOG ,
1027+ (errcode_for_file_access (),
1028+ errmsg ("could not remove file \"%s\": %m" ,
1029+ LOG_METAINFO_DATAFILE )));
1030+
1031+ /*
1032+ * If enabled, start up syslogger collection subprocess
1033+ */
1034+ SysLoggerPID = SysLogger_Start ();
1035+
1036+ /*
1037+ * Reset whereToSendOutput from DestDebug (its starting state) to
1038+ * DestNone. This stops ereport from sending log messages to stderr unless
1039+ * Log_destination permits. We don't do this until the postmaster is
1040+ * fully launched, since startup failures may as well be reported to
1041+ * stderr.
1042+ *
1043+ * If we are in fact disabling logging to stderr, first emit a log message
1044+ * saying so, to provide a breadcrumb trail for users who may not remember
1045+ * that their logging is configured to go somewhere else.
1046+ */
1047+ if (!(Log_destination & LOG_DESTINATION_STDERR ))
1048+ ereport (LOG ,
1049+ (errmsg ("ending log output to stderr" ),
1050+ errhint ("Future log output will go to log destination \"%s\"." ,
1051+ Log_destination_string )));
1052+
1053+ whereToSendOutput = DestNone ;
1054+
9951055 /*
9961056 * Establish input sockets.
9971057 *
@@ -1183,12 +1243,6 @@ PostmasterMain(int argc, char *argv[])
11831243 */
11841244 set_stack_base ();
11851245
1186- /*
1187- * Initialize pipe (or process handle on Windows) that allows children to
1188- * wake up from sleep on postmaster death.
1189- */
1190- InitPostmasterDeathWatchHandle ();
1191-
11921246#ifdef WIN32
11931247
11941248 /*
@@ -1242,60 +1296,6 @@ PostmasterMain(int argc, char *argv[])
12421296 */
12431297 RemovePgTempFiles ();
12441298
1245- /*
1246- * Forcibly remove the files signaling a standby promotion request.
1247- * Otherwise, the existence of those files triggers a promotion too early,
1248- * whether a user wants that or not.
1249- *
1250- * This removal of files is usually unnecessary because they can exist
1251- * only during a few moments during a standby promotion. However there is
1252- * a race condition: if pg_ctl promote is executed and creates the files
1253- * during a promotion, the files can stay around even after the server is
1254- * brought up to new master. Then, if new standby starts by using the
1255- * backup taken from that master, the files can exist at the server
1256- * startup and should be removed in order to avoid an unexpected
1257- * promotion.
1258- *
1259- * Note that promotion signal files need to be removed before the startup
1260- * process is invoked. Because, after that, they can be used by
1261- * postmaster's SIGUSR1 signal handler.
1262- */
1263- RemovePromoteSignalFiles ();
1264-
1265- /* Do the same for logrotate signal file */
1266- RemoveLogrotateSignalFiles ();
1267-
1268- /* Remove any outdated file holding the current log filenames. */
1269- if (unlink (LOG_METAINFO_DATAFILE ) < 0 && errno != ENOENT )
1270- ereport (LOG ,
1271- (errcode_for_file_access (),
1272- errmsg ("could not remove file \"%s\": %m" ,
1273- LOG_METAINFO_DATAFILE )));
1274-
1275- /*
1276- * If enabled, start up syslogger collection subprocess
1277- */
1278- SysLoggerPID = SysLogger_Start ();
1279-
1280- /*
1281- * Reset whereToSendOutput from DestDebug (its starting state) to
1282- * DestNone. This stops ereport from sending log messages to stderr unless
1283- * Log_destination permits. We don't do this until the postmaster is
1284- * fully launched, since startup failures may as well be reported to
1285- * stderr.
1286- *
1287- * If we are in fact disabling logging to stderr, first emit a log message
1288- * saying so, to provide a breadcrumb trail for users who may not remember
1289- * that their logging is configured to go somewhere else.
1290- */
1291- if (!(Log_destination & LOG_DESTINATION_STDERR ))
1292- ereport (LOG ,
1293- (errmsg ("ending log output to stderr" ),
1294- errhint ("Future log output will go to log destination \"%s\"." ,
1295- Log_destination_string )));
1296-
1297- whereToSendOutput = DestNone ;
1298-
12991299 /*
13001300 * Initialize stats collection subsystem (this does NOT start the
13011301 * collector process!)
0 commit comments