If shutdown (non hot enabled) standby and promote the standby using
promote_trigger_file via pg_ctl start with -w (wait), currently pg_ctl
returns as soon as recovery is started. Instead would be helpful if
pg_ctl can wait till PM_STATUS_READY for this case, given promotion is
requested.

pg_ctl -w returns as soon as recovery is started for non hot enabled
standby because PM_STATUS_STANDBY is written
on PMSIGNAL_RECOVERY_STARTED. Given the intent to promote the standby
using promote_trigger_file, it would be better to not write
PM_STATUS_STANDBY, instead let promotion complete and return only
after connections can be actually accepted.

Seems helpful behavior for users, though I am not sure about how much
promote_trigger_file is used with non hot enabled standbys. This is
something which will help to solidify some of the tests in Greenplum
hence checking interest for the same here.

It's doable via below patch:

diff --git a/src/backend/postmaster/postmaster.c
b/src/backend/postmaster/postmaster.c
index 5b5fc97c72..c49010aa5a 100644
--- a/src/backend/postmaster/postmaster.c
+++ b/src/backend/postmaster/postmaster.c
@@ -5197,6 +5197,7 @@ sigusr1_handler(SIGNAL_ARGS)
        if (CheckPostmasterSignal(PMSIGNAL_RECOVERY_STARTED) &&
                pmState == PM_STARTUP && Shutdown == NoShutdown)
        {
+               bool promote_trigger_file_exist = false;
                /* WAL redo has started. We're out of reinitialization. */
                FatalError = false;
                AbortStartTime = 0;
@@ -5218,12 +5219,25 @@ sigusr1_handler(SIGNAL_ARGS)
                if (XLogArchivingAlways())
                        PgArchPID = pgarch_start();

+               {
+                       /*
+                        * if promote trigger file exist we don't wish to
convey
+                        * PM_STATUS_STANDBY, instead wish pg_ctl -w to
wait till
+                        * connections can be actually accepted by the
database.
+                        */
+                       struct stat stat_buf;
+                       if (PromoteTriggerFile != NULL &&
+                               strcmp(PromoteTriggerFile, "") != 0 &&
+                               stat(PromoteTriggerFile, &stat_buf) == 0)
+                               promote_trigger_file_exist = true;
+               }
+
                /*
                 * If we aren't planning to enter hot standby mode later,
treat
                 * RECOVERY_STARTED as meaning we're out of startup, and
report status
                 * accordingly.
                 */
-               if (!EnableHotStandby)
+               if (!EnableHotStandby && !promote_trigger_file_exist)
                {
                        AddToDataDirLockFile(LOCK_FILE_LINE_PM_STATUS,
PM_STATUS_STANDBY);
 #ifdef USE_SYSTEMD


-- 
*Ashwin Agrawal (VMware)*

Reply via email to