Skip to content

Commit bf08f22

Browse files
Avoid archiving XLOG_RUNNING_XACTS on idle server
If archive_timeout > 0 we should avoid logging XLOG_RUNNING_XACTS if idle. Bug 13685 reported by Laurence Rowe, investigated in detail by Michael Paquier, though this is not his proposed fix. 20151016203031.3019.72930@wrigleys.postgresql.org Simple non-invasive patch to allow later backpatch to 9.4 and 9.5
1 parent a75a418 commit bf08f22

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

src/backend/postmaster/bgwriter.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,8 +330,11 @@ BackgroundWriterMain(void)
330330
if (now >= timeout &&
331331
last_snapshot_lsn != GetXLogInsertRecPtr())
332332
{
333-
last_snapshot_lsn = LogStandbySnapshot();
333+
XLogRecPtr log_standby_lsn = LogStandbySnapshot();
334+
334335
last_snapshot_ts = now;
336+
if (!XLogRecPtrIsInvalid(log_standby_lsn))
337+
last_snapshot_lsn = log_standby_lsn;
335338
}
336339
}
337340

src/backend/storage/ipc/standby.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -902,6 +902,7 @@ LogStandbySnapshot(void)
902902
RunningTransactions running;
903903
xl_standby_lock *locks;
904904
int nlocks;
905+
static bool last_snapshot_overflowed = false;
905906

906907
Assert(XLogStandbyInfoActive());
907908

@@ -932,8 +933,28 @@ LogStandbySnapshot(void)
932933
* only a shared lock.
933934
*/
934935
if (wal_level < WAL_LEVEL_LOGICAL)
936+
{
935937
LWLockRelease(ProcArrayLock);
936938

939+
/*
940+
* Don't bother to log anything if nothing is happening, if we are
941+
* using archive_timeout > 0 and we didn't overflow snapshot last time.
942+
*
943+
* This ensures that we don't issue an empty WAL record, which can
944+
* be annoying when used in conjunction with archive timeout.
945+
*/
946+
if (running->xcnt == 0 &&
947+
nlocks == 0 &&
948+
XLogArchiveTimeout > 0 &&
949+
!last_snapshot_overflowed)
950+
{
951+
LWLockRelease(XidGenLock);
952+
return InvalidXLogRecPtr;
953+
}
954+
955+
last_snapshot_overflowed = running->subxid_overflow;
956+
}
957+
937958
recptr = LogCurrentRunningXacts(running);
938959

939960
/* Release lock if we kept it longer ... */

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy