hibernate_startup.v7.patch
application/octet-stream
Filename: hibernate_startup.v7.patch
Type: application/octet-stream
Part: 0
Patch
Format: unified
Series: patch v7
| File | + | − |
|---|---|---|
| doc/src/sgml/config.sgml | 6 | 3 |
| doc/src/sgml/high-availability.sgml | 7 | 11 |
| src/backend/access/transam/xlogrecovery.c | 11 | 4 |
| src/backend/postmaster/startup.c | 22 | 0 |
| src/backend/utils/misc/guc_tables.c | 2 | 1 |
| src/backend/utils/misc/postgresql.conf.sample | 0 | 1 |
| src/include/postmaster/startup.h | 2 | 0 |
diff --git a/doc/src/sgml/config.sgml b/doc/src/sgml/config.sgml
index 559eb898a9..391bcb4306 100644
--- a/doc/src/sgml/config.sgml
+++ b/doc/src/sgml/config.sgml
@@ -4615,9 +4615,12 @@ ANY <replaceable class="parameter">num_sync</replaceable> ( <replaceable class="
<listitem>
<para>
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 <command>pg_ctl promote</command> or calling
- <function>pg_promote()</function>.
+ standby, though this may take as long as 60s to take effect.
+ This mechanism is now deprecated and will be removed in a later
+ release. The preferred mechanism by which to promote the standby
+ is by using <command>pg_ctl promote</command> or calling
+ <function>pg_promote()</function>, both of which promote much
+ faster than using this parameter.
This parameter can only be set in the <filename>postgresql.conf</filename>
file or on the server command line.
</para>
diff --git a/doc/src/sgml/high-availability.sgml b/doc/src/sgml/high-availability.sgml
index b2b3129397..d85788338c 100644
--- a/doc/src/sgml/high-availability.sgml
+++ b/doc/src/sgml/high-availability.sgml
@@ -653,11 +653,11 @@ protocol to make nodes agree on a serializable transactional order.
<para>
Standby mode is exited and the server switches to normal operation
- when <command>pg_ctl promote</command> is run,
- <function>pg_promote()</function> is called, or a trigger file is found
- (<varname>promote_trigger_file</varname>). Before failover,
- any WAL immediately available in the archive or in <filename>pg_wal</filename> will be
- restored, but no attempt is made to connect to the primary.
+ when <command>pg_ctl promote</command> is run, or
+ <function>pg_promote()</function> is called. Use of
+ <varname>promote_trigger_file</varname> is deprecated. Before failover,
+ any WAL immediately available in the archive or in <filename>pg_wal</filename>
+ will be restored, but no attempt is made to connect to the primary.
</para>
</sect2>
@@ -1483,12 +1483,8 @@ synchronous_standby_names = 'ANY 2 (s1, s2, s3)'
<para>
To trigger failover of a log-shipping standby server, run
- <command>pg_ctl promote</command>, call <function>pg_promote()</function>,
- or create a trigger file with the file name and path specified by the
- <varname>promote_trigger_file</varname>. If you're planning to use
- <command>pg_ctl promote</command> or to call
- <function>pg_promote()</function> to fail over,
- <varname>promote_trigger_file</varname> is not required. If you're
+ <command>pg_ctl promote</command> or call <function>pg_promote()</function>.
+ Use of <varname>promote_trigger_file</varname> is deprecated. 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.
diff --git a/src/backend/access/transam/xlogrecovery.c b/src/backend/access/transam/xlogrecovery.c
index cb07694aea..2dbe1477ac 100644
--- a/src/backend/access/transam/xlogrecovery.c
+++ b/src/backend/access/transam/xlogrecovery.c
@@ -3840,14 +3840,21 @@ 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. Hibernate, but time out
+ * to react to a trigger file. Direct use of trigger file
+ * is now deprecated and the promote_trigger_file will be
+ * removed in a later release.
+ * Disable the startup progress timeout, since we aren't
+ * actually doing anything that needs to be reported on.
*/
+ disable_startup_progress_timeout();
(void) WaitLatch(&XLogRecoveryCtl->recoveryWakeupLatch,
WL_LATCH_SET | WL_TIMEOUT |
WL_EXIT_ON_PM_DEATH,
- 5000L, WAIT_EVENT_RECOVERY_WAL_STREAM);
+ 60000L,
+ WAIT_EVENT_RECOVERY_WAL_STREAM);
+ enable_startup_progress_timeout();
ResetLatch(&XLogRecoveryCtl->recoveryWakeupLatch);
break;
}
diff --git a/src/backend/postmaster/startup.c b/src/backend/postmaster/startup.c
index f99186eab7..28926d0899 100644
--- a/src/backend/postmaster/startup.c
+++ b/src/backend/postmaster/startup.c
@@ -335,6 +335,28 @@ begin_startup_progress_phase(void)
log_startup_progress_interval);
}
+void
+disable_startup_progress_timeout(void)
+{
+ disable_timeout(STARTUP_PROGRESS_TIMEOUT, false);
+ startup_progress_timer_expired = false;
+}
+
+void
+enable_startup_progress_timeout(void)
+{
+ TimestampTz fin_time;
+
+ if (log_startup_progress_interval == 0)
+ return;
+
+ startup_progress_phase_start_time = GetCurrentTimestamp();
+ fin_time = TimestampTzPlusMilliseconds(startup_progress_phase_start_time,
+ log_startup_progress_interval);
+ enable_timeout_every(STARTUP_PROGRESS_TIMEOUT, fin_time,
+ log_startup_progress_interval);
+}
+
/*
* Report whether startup progress timeout has occurred. Reset the timer flag
* if it did, set the elapsed time to the out parameters and return true,
diff --git a/src/backend/utils/misc/guc_tables.c b/src/backend/utils/misc/guc_tables.c
index 836b49484a..38aca5dac4 100644
--- a/src/backend/utils/misc/guc_tables.c
+++ b/src/backend/utils/misc/guc_tables.c
@@ -3802,7 +3802,8 @@ struct config_string ConfigureNamesString[] =
{
{"promote_trigger_file", PGC_SIGHUP, REPLICATION_STANDBY,
gettext_noop("Specifies a file name whose presence ends recovery in the standby."),
- NULL
+ NULL,
+ GUC_NOT_IN_SAMPLE
},
&PromoteTriggerFile,
"",
diff --git a/src/backend/utils/misc/postgresql.conf.sample b/src/backend/utils/misc/postgresql.conf.sample
index 868d21c351..043864597f 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/postmaster/startup.h b/src/include/postmaster/startup.h
index d66ec1fcb1..5f0b7b7d69 100644
--- a/src/include/postmaster/startup.h
+++ b/src/include/postmaster/startup.h
@@ -32,6 +32,8 @@ extern void PostRestoreCommand(void);
extern bool IsPromoteSignaled(void);
extern void ResetPromoteSignaled(void);
+extern void disable_startup_progress_timeout(void);
+extern void enable_startup_progress_timeout(void);
extern void begin_startup_progress_phase(void);
extern void startup_progress_timeout_handler(void);
extern bool has_startup_progress_timeout_expired(long *secs, int *usecs);