This is an automated email from the ASF dual-hosted git repository. tuhaihe pushed a commit to branch add-behave-test-ci in repository https://gitbox.apache.org/repos/asf/cloudberry.git
commit 21f9bf04de1d324cab044ad1d80be3074790f750 Author: Dianjin Wang <[email protected]> AuthorDate: Fri Sep 11 12:24:08 2026 +0800 Wait for promotion before reporting ready with promote_trigger_file Cloudberry keeps the promote_trigger_file GUC that PostgreSQL 16 removed, because gpactivatestandby's force path promotes a standby coordinator by creating the trigger file and then starting the server in utility mode. CheckForStandbyTrigger no longer honoured the GUC, so that path never promoted. Restore the check, and close the race it exposes in the postmaster: with hot_standby off, PM_STATUS_STANDBY is reported as soon as recovery starts, which "pg_ctl -w" treats as ready. gpstart would then connect before promotion finished and fail with "the database system is not accepting connections". Extend the existing promotion_requested guard to cover a configured trigger file that is already present, so pg_ctl waits for PM_STATUS_READY. --- src/backend/access/transam/xlogrecovery.c | 26 ++++++++++++++++++++++++++ src/backend/postmaster/postmaster.c | 20 ++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/src/backend/access/transam/xlogrecovery.c b/src/backend/access/transam/xlogrecovery.c index 63b4c323a61..28be3b44c72 100644 --- a/src/backend/access/transam/xlogrecovery.c +++ b/src/backend/access/transam/xlogrecovery.c @@ -4575,6 +4575,8 @@ SetPromoteIsTriggered(void) static bool CheckForStandbyTrigger(void) { + struct stat stat_buf; + if (LocalPromoteIsTriggered) return true; @@ -4587,6 +4589,30 @@ CheckForStandbyTrigger(void) return true; } + /* + * Cloudberry retains the promote_trigger_file GUC (removed upstream in + * PostgreSQL 16) because management utilities such as gpactivatestandby + * rely on it to promote a standby coordinator that is started in utility + * mode. Honor the GUC here: the presence of the configured file ends + * recovery, matching the documented behavior of the GUC. + */ + if (PromoteTriggerFile == NULL || strcmp(PromoteTriggerFile, "") == 0) + return false; + + if (stat(PromoteTriggerFile, &stat_buf) == 0) + { + ereport(LOG, + (errmsg("promote trigger file found: %s", PromoteTriggerFile))); + unlink(PromoteTriggerFile); + SetPromoteIsTriggered(); + return true; + } + else if (errno != ENOENT) + ereport(ERROR, + (errcode_for_file_access(), + errmsg("could not stat promote trigger file \"%s\": %m", + PromoteTriggerFile))); + return false; } diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c index 12c8649b159..b00199abea1 100644 --- a/src/backend/postmaster/postmaster.c +++ b/src/backend/postmaster/postmaster.c @@ -5755,6 +5755,26 @@ process_pm_pmsignal(void) if (recoveryTargetAction == RECOVERY_TARGET_ACTION_PROMOTE) promotion_requested = true; + /* + * GPDB: A configured promote_trigger_file whose file is already + * present means a promotion is imminent (for example + * gpactivatestandby's force path creates the trigger file before + * starting the standby coordinator in utility mode). Treat that the + * same as an explicit promotion request so that, with hot standby + * disabled, we do not prematurely report PM_STATUS_STANDBY. Otherwise + * "pg_ctl -w" would return as soon as recovery starts and the caller + * (gpstart) would try to read the catalog before the server has + * actually finished promoting and can accept connections. + */ + if (!promotion_requested && + PromoteTriggerFile != NULL && PromoteTriggerFile[0] != '\0') + { + struct stat stat_buf; + + if (stat(PromoteTriggerFile, &stat_buf) == 0) + promotion_requested = 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 --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
