On Thu, Dec 22, 2011 at 6:16 AM, Simon Riggs <si...@2ndquadrant.com> wrote:

> I can see a reason to do this now. I've written patch and will commit
> on Friday. Nudge me if I don't.

It's hard to write this so it works in all cases and doesn't work in
the right cases also.

Basically, we can't get in the way of crash recovery, so the only way
we can currently tell a crash recovery from an archive recovery is the
presence of restore_command.

If you don't have that and you haven't set a recovery target, it won't
pause and there's nothing I can do, AFAICS.

Please test this and review before commit.

-- 
 Simon Riggs                   http://www.2ndQuadrant.com/
 PostgreSQL Development, 24x7 Support, Training & Services
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;
-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Reply via email to