pause_at_end_of_logs.v2.patch
text/x-patch
Filename: pause_at_end_of_logs.v2.patch
Type: text/x-patch
Part: 0
Message:
Re: Pause at end of recovery
Patch
Same data as JSON:
GET /api/v1/attachments/:id/patch
the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes.
API reference →
Format: unified
Series: patch v2
| File | + | − |
|---|---|---|
| doc/src/sgml/recovery-config.sgml | 3 | 1 |
| src/backend/access/transam/xlog.c | 23 | 3 |
diff --git a/doc/src/sgml/recovery-config.sgml b/doc/src/sgml/recovery-config.sgml
index 8647024..1e1614f 100644
--- a/doc/src/sgml/recovery-config.sgml
+++ b/doc/src/sgml/recovery-config.sgml
@@ -263,6 +263,8 @@ restore_command = 'copy "C:\\server\\archivedir\\%f" "%p"' # Windows
<para>
Specifies whether recovery should pause when the recovery target
is reached. The default is true.
+ If <varname>pause_at_recovery_target</> is set yet no recovery target
+ is specified there will be a pause when we reach the end of WAL.
This is intended to allow queries to be executed against the
database to check if this recovery target is the most desirable
point for recovery. The paused state can be resumed by using
@@ -275,7 +277,7 @@ restore_command = 'copy "C:\\server\\archivedir\\%f" "%p"' # Windows
</para>
<para>
This setting has no effect if <xref linkend="guc-hot-standby"> is not
- enabled, or if no recovery target is set.
+ enabled, or if the database has not reached a consistent state.
</para>
</listitem>
</varlistentry>
diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c
index 41800a4..dc72c00 100644
--- a/src/backend/access/transam/xlog.c
+++ b/src/backend/access/transam/xlog.c
@@ -186,6 +186,9 @@ static bool InArchiveRecovery = false;
/* Was the last xlog file restored from archive, or local? */
static bool restoredFromArchive = false;
+/* Were we explicitly requested to terminate recovery, by any means? */
+static bool triggered = false;
+
/* options taken from recovery.conf for archive recovery */
static char *recoveryRestoreCommand = NULL;
static char *recoveryEndCommand = NULL;
@@ -6569,6 +6572,24 @@ StartupXLOG(void)
ereport(LOG,
(errmsg("last completed transaction was at log time %s",
timestamptz_to_str(xtime))));
+
+ /*
+ * If we are in archive recovery and yet didn't have an explicit
+ * recovery target then pause at the end of recovery, unless we
+ * already paused above or we have been triggered to go live.
+ * Pause only if users can connect to send a resume message
+ */
+ if (recoveryPauseAtTarget &&
+ standbyState == STANDBY_SNAPSHOT_READY &&
+ recoveryTarget == RECOVERY_TARGET_UNSET &&
+ InArchiveRecovery &&
+ !triggered &&
+ !reachedStopPoint)
+ {
+ SetRecoveryPause(true);
+ recoveryPausesHere();
+ }
+
InRedo = false;
}
else
@@ -9836,7 +9857,7 @@ retry:
* can from archive and pg_xlog before failover.
*/
if (CheckForStandbyTrigger())
- goto triggered;
+ goto trigger_received;
}
/*
@@ -9960,7 +9981,7 @@ next_record_is_invalid:
else
return false;
-triggered:
+trigger_received:
if (readFile >= 0)
close(readFile);
readFile = -1;
@@ -10012,7 +10033,6 @@ static bool
CheckForStandbyTrigger(void)
{
struct stat stat_buf;
- static bool triggered = false;
if (triggered)
return true;