int reqLen, XLogRecPtr targetRecPtr, char *readBuf);
static bool WaitForWALToBecomeAvailable(XLogRecPtr RecPtr, bool randAccess,
bool fetching_ckpt, XLogRecPtr tliRecPtr);
+static void ResetInstallXLogFileSegmentActive(void);
static void XLogShutdownWalRcv(void);
static int emode_for_corrupt_record(int emode, XLogRecPtr RecPtr);
static void XLogFileClose(void);
* Before we leave XLOG_FROM_STREAM state, make sure that
* walreceiver is not active, so that it won't overwrite
* WAL that we restore from archive.
+ * If walreceiver is actively streaming (or attempting to
+ * connect), we must shut it down. However, if it's
+ * already in WAITING state (e.g., due to timeline
+ * divergence), we only need to reset the install flag to
+ * allow archive restoration.
*/
- XLogShutdownWalRcv();
+ if (WalRcvStreaming())
+ XLogShutdownWalRcv();
+ else
+ {
+ ResetInstallXLogFileSegmentActive();
+ }
/*
* Before we sleep, re-scan for possible new timelines if
}
}
-/* Thin wrapper around ShutdownWalRcv(). */
+/* Disable WAL file recycling and preallocation. */
static void
-XLogShutdownWalRcv(void)
+ResetInstallXLogFileSegmentActive(void)
{
- ShutdownWalRcv();
-
LWLockAcquire(ControlFileLock, LW_EXCLUSIVE);
XLogCtl->InstallXLogFileSegmentActive = false;
LWLockRelease(ControlFileLock);
}
+/* Thin wrapper around ShutdownWalRcv(). */
+static void
+XLogShutdownWalRcv(void)
+{
+ ShutdownWalRcv();
+ ResetInstallXLogFileSegmentActive();
+}
+
/*
* Determine what log level should be used to report a corrupt WAL record
* in the current WAL page, previously read by XLogPageRead().
use File::Path qw(rmtree);
use PostgresNode;
use TestLib;
-use Test::More tests => 3;
+use Test::More tests => 4;
$ENV{PGDATABASE} = 'postgres';
$node_standby_2->safe_psql('postgres', "SELECT count(*) FROM tab_int");
is($result, qq(2000), 'check content of standby 2');
+# Check the logs, WAL receiver should not have been stopped while
+# transitioning to its new timeline. There is no need to rely on an
+# offset in this check of the server logs: a new log file is used on
+# node restart when primary_conninfo is updated above.
+ok( !$node_standby_2->log_contains(
+ "FATAL: .* terminating walreceiver process due to administrator command"
+ ),
+ 'WAL receiver should not be stopped across timeline jumps');
# Ensure that a standby is able to follow a primary on a newer timeline
# when WAL archiving is enabled.