From cd4329d9393f84dce34f0bd2dd936adc8ffaa213 Mon Sep 17 00:00:00 2001 From: Thomas Munro Date: Tue, 29 Nov 2022 11:28:08 +1300 Subject: [PATCH] Remove promote_trigger_file. Previously, an idle startup (recovery) process would wake up every 5 seconds to have a chance to poll for promote_trigger_file, even if that GUC was not configured. That promotion triggering mechanism was effectively superseded by pg_ctl promote and pg_promote() a long time ago. There probably aren't many users left and it's very easy to change to the modern mechanisms, so we agreed to remove the feature. This is part of a campaign to reduce wakeups on idle systems. Author: Simon Riggs Reviewed-by: Bharath Rupireddy Reviewed-by: Robert Haas Reviewed-by: Thomas Munro Reviewed-by: Tom Lane Reviewed-by: Ian Lawrence Barwick Discussion: https://postgr.es/m/CANbhV-FsjnzVOQGBpQ589%3DnWuL1Ex0Ykn74Nh1hEjp2usZSR5g%40mail.gmail.com --- .../appendix-obsolete-recovery-config.sgml | 13 ++--- doc/src/sgml/config.sgml | 18 ------ doc/src/sgml/high-availability.sgml | 22 +++---- src/backend/access/transam/xlogrecovery.c | 57 ++++++------------- src/backend/utils/misc/guc_tables.c | 10 ---- src/backend/utils/misc/postgresql.conf.sample | 1 - src/include/access/xlogrecovery.h | 1 - 7 files changed, 29 insertions(+), 93 deletions(-) diff --git a/doc/src/sgml/appendix-obsolete-recovery-config.sgml b/doc/src/sgml/appendix-obsolete-recovery-config.sgml index 1cf49131140..a57084ad43f 100644 --- a/doc/src/sgml/appendix-obsolete-recovery-config.sgml +++ b/doc/src/sgml/appendix-obsolete-recovery-config.sgml @@ -34,14 +34,11 @@ - The - trigger_file - - trigger_file - promote_trigger_file - - setting has been renamed to - . + PostgreSQL 15 and below had a setting + promote_trigger_file, or + trigger_file before 12. + Use pg_ctl promote or call + pg_promote() to promote a standby instead. diff --git a/doc/src/sgml/config.sgml b/doc/src/sgml/config.sgml index 9fd2075b1eb..82df89b1a9e 100644 --- a/doc/src/sgml/config.sgml +++ b/doc/src/sgml/config.sgml @@ -4610,24 +4610,6 @@ ANY num_sync ( - promote_trigger_file (string) - - promote_trigger_file configuration parameter - - - - - Specifies a trigger file whose presence ends recovery in the - standby. Even if this value is not set, you can still promote - the standby using pg_ctl promote or calling - pg_promote(). - This parameter can only be set in the postgresql.conf - file or on the server command line. - - - - hot_standby (boolean) diff --git a/doc/src/sgml/high-availability.sgml b/doc/src/sgml/high-availability.sgml index b2b31293972..f1806075287 100644 --- a/doc/src/sgml/high-availability.sgml +++ b/doc/src/sgml/high-availability.sgml @@ -653,11 +653,10 @@ protocol to make nodes agree on a serializable transactional order. Standby mode is exited and the server switches to normal operation - when pg_ctl promote is run, - pg_promote() is called, or a trigger file is found - (promote_trigger_file). Before failover, - any WAL immediately available in the archive or in pg_wal will be - restored, but no attempt is made to connect to the primary. + when pg_ctl promote is run, or + pg_promote() is called. Before failover, + any WAL immediately available in the archive or in pg_wal + will be restored, but no attempt is made to connect to the primary. @@ -1483,15 +1482,10 @@ synchronous_standby_names = 'ANY 2 (s1, s2, s3)' To trigger failover of a log-shipping standby server, run - pg_ctl promote, call pg_promote(), - or create a trigger file with the file name and path specified by the - promote_trigger_file. If you're planning to use - pg_ctl promote or to call - pg_promote() to fail over, - promote_trigger_file is not required. If you're - setting up the reporting servers that are only used to offload read-only - queries from the primary, not for high availability purposes, you don't - need to promote it. + pg_ctl promote or call pg_promote(). + If you're setting up reporting servers that are only used to offload + read-only queries from the primary, not for high availability purposes, + you don't need to promote. diff --git a/src/backend/access/transam/xlogrecovery.c b/src/backend/access/transam/xlogrecovery.c index cb07694aea6..ffdb55fd394 100644 --- a/src/backend/access/transam/xlogrecovery.c +++ b/src/backend/access/transam/xlogrecovery.c @@ -95,7 +95,6 @@ int recovery_min_apply_delay = 0; /* options formerly taken from recovery.conf for XLOG streaming */ char *PrimaryConnInfo = NULL; char *PrimarySlotName = NULL; -char *PromoteTriggerFile = NULL; bool wal_receiver_create_temp_slot = false; /* @@ -318,8 +317,8 @@ typedef struct XLogRecoveryCtlData /* * recoveryWakeupLatch is used to wake up the startup process to continue - * WAL replay, if it is waiting for WAL to arrive or failover trigger file - * to appear. + * WAL replay, if it is waiting for WAL to arrive or promotion to be + * requested. * * Note that the startup process also uses another latch, its procLatch, * to wait for recovery conflict. If we get rid of recoveryWakeupLatch for @@ -2906,10 +2905,7 @@ recoveryApplyDelay(XLogReaderState *record) { ResetLatch(&XLogRecoveryCtl->recoveryWakeupLatch); - /* - * This might change recovery_min_apply_delay or the trigger file's - * location. - */ + /* This might change recovery_min_apply_delay. */ HandleStartupProcInterrupts(); if (CheckForStandbyTrigger()) @@ -3155,8 +3151,8 @@ ReadRecord(XLogPrefetcher *xlogprefetcher, int emode, * as for waiting for the requested WAL record to arrive in standby mode. * * 'emode' specifies the log level used for reporting "file not found" or - * "end of WAL" situations in archive recovery, or in standby mode when a - * trigger file is found. If set to WARNING or below, XLogPageRead() returns + * "end of WAL" situations in archive recovery, or in standby mode when + * promotion is triggered. If set to WARNING or below, XLogPageRead() returns * XLREAD_FAIL in those situations, on higher log levels the ereport() won't * return. * @@ -3424,7 +3420,7 @@ WaitForWALToBecomeAvailable(XLogRecPtr RecPtr, bool randAccess, * * 1. Read from either archive or pg_wal (XLOG_FROM_ARCHIVE), or just * pg_wal (XLOG_FROM_PG_WAL) - * 2. Check trigger file + * 2. Check for promotion trigger request * 3. Read from primary server via walreceiver (XLOG_FROM_STREAM) * 4. Rescan timelines * 5. Sleep wal_retrieve_retry_interval milliseconds, and loop back to 1. @@ -3481,10 +3477,10 @@ WaitForWALToBecomeAvailable(XLogRecPtr RecPtr, bool randAccess, case XLOG_FROM_PG_WAL: /* - * Check to see if the trigger file exists. Note that we - * do this only after failure, so when you create the - * trigger file, we still finish replaying as much as we - * can from archive and pg_wal before failover. + * Check to see if promotion is requested. Note that we do + * this only after failure, so when you promote, we still + * finish replaying as much as we can from archive and + * pg_wal before failover. */ if (StandbyMode && CheckForStandbyTrigger()) { @@ -3840,14 +3836,13 @@ WaitForWALToBecomeAvailable(XLogRecPtr RecPtr, bool randAccess, XLogPrefetcherComputeStats(xlogprefetcher); /* - * Wait for more WAL to arrive. Time out after 5 seconds - * to react to a trigger file promptly and to check if the - * WAL receiver is still active. + * Wait for more WAL to arrive, when we will be woken + * immediately by the WAL receiver. */ (void) WaitLatch(&XLogRecoveryCtl->recoveryWakeupLatch, - WL_LATCH_SET | WL_TIMEOUT | - WL_EXIT_ON_PM_DEATH, - 5000L, WAIT_EVENT_RECOVERY_WAL_STREAM); + WL_LATCH_SET | WL_EXIT_ON_PM_DEATH, + -1L, + WAIT_EVENT_RECOVERY_WAL_STREAM); ResetLatch(&XLogRecoveryCtl->recoveryWakeupLatch); break; } @@ -4294,14 +4289,11 @@ SetPromoteIsTriggered(void) } /* - * Check to see whether the user-specified trigger file exists and whether a - * promote request has arrived. If either condition holds, return true. + * Check whether a promote request has arrived. */ static bool CheckForStandbyTrigger(void) { - struct stat stat_buf; - if (LocalPromoteIsTriggered) return true; @@ -4314,23 +4306,6 @@ CheckForStandbyTrigger(void) return true; } - 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/utils/misc/guc_tables.c b/src/backend/utils/misc/guc_tables.c index 349dd6a5379..1bf14eec661 100644 --- a/src/backend/utils/misc/guc_tables.c +++ b/src/backend/utils/misc/guc_tables.c @@ -3819,16 +3819,6 @@ struct config_string ConfigureNamesString[] = check_recovery_target_lsn, assign_recovery_target_lsn, NULL }, - { - {"promote_trigger_file", PGC_SIGHUP, REPLICATION_STANDBY, - gettext_noop("Specifies a file name whose presence ends recovery in the standby."), - NULL - }, - &PromoteTriggerFile, - "", - NULL, NULL, NULL - }, - { {"primary_conninfo", PGC_SIGHUP, REPLICATION_STANDBY, gettext_noop("Sets the connection string to be used to connect to the sending server."), diff --git a/src/backend/utils/misc/postgresql.conf.sample b/src/backend/utils/misc/postgresql.conf.sample index 868d21c351e..043864597f8 100644 --- a/src/backend/utils/misc/postgresql.conf.sample +++ b/src/backend/utils/misc/postgresql.conf.sample @@ -331,7 +331,6 @@ #primary_conninfo = '' # connection string to sending server #primary_slot_name = '' # replication slot on sending server -#promote_trigger_file = '' # file name whose presence ends recovery #hot_standby = on # "off" disallows queries during recovery # (change requires restart) #max_standby_archive_delay = 30s # max delay before canceling queries diff --git a/src/include/access/xlogrecovery.h b/src/include/access/xlogrecovery.h index 0e3e246bd2c..f3398425d87 100644 --- a/src/include/access/xlogrecovery.h +++ b/src/include/access/xlogrecovery.h @@ -65,7 +65,6 @@ extern PGDLLIMPORT TimestampTz recoveryTargetTime; extern PGDLLIMPORT const char *recoveryTargetName; extern PGDLLIMPORT XLogRecPtr recoveryTargetLSN; extern PGDLLIMPORT RecoveryTargetType recoveryTarget; -extern PGDLLIMPORT char *PromoteTriggerFile; extern PGDLLIMPORT bool wal_receiver_create_temp_slot; extern PGDLLIMPORT RecoveryTargetTimeLineGoal recoveryTargetTimeLineGoal; extern PGDLLIMPORT TimeLineID recoveryTargetTLIRequested;