Skip to content

Commit 38b38fb

Browse files
committed
pg_stat_replication.sync_state was displayed incorrectly at page boundary.
XLogRecPtrIsInvalid() only checks the xrecoff field, which is correct when checking if a WAL record could legally begin at the given position, but WAL sending can legally be paused at a page boundary, in which case xrecoff is 0. Use XLByteEQ(..., InvalidXLogRecPtr) instead, which checks that both xlogid and xrecoff are 0. 9.3 doesn't have this problem because XLogRecPtr is now a single 64-bit integer, so XLogRecPtrIsInvalid() does the right thing. Apply to 9.2, and 9.1 where pg_stat_replication view was introduced. Kyotaro HORIGUCHI, reviewed by Fujii Masao.
1 parent 806e6d1 commit 38b38fb

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

src/backend/replication/syncrep.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,7 @@ SyncRepReleaseWaiters(void)
375375
int numprocs = 0;
376376
int priority = 0;
377377
int i;
378+
XLogRecPtr InvalidXLogRecPtr = {0, 0};
378379

379380
/*
380381
* If this WALSender is serving a standby that is not on the list of
@@ -384,7 +385,7 @@ SyncRepReleaseWaiters(void)
384385
*/
385386
if (MyWalSnd->sync_standby_priority == 0 ||
386387
MyWalSnd->state < WALSNDSTATE_STREAMING ||
387-
XLogRecPtrIsInvalid(MyWalSnd->flush))
388+
XLByteEQ(MyWalSnd->flush, InvalidXLogRecPtr))
388389
return;
389390

390391
/*
@@ -405,7 +406,7 @@ SyncRepReleaseWaiters(void)
405406
walsnd->sync_standby_priority > 0 &&
406407
(priority == 0 ||
407408
priority > walsnd->sync_standby_priority) &&
408-
!XLogRecPtrIsInvalid(walsnd->flush))
409+
!XLByteEQ(walsnd->flush, InvalidXLogRecPtr))
409410
{
410411
priority = walsnd->sync_standby_priority;
411412
syncWalSnd = walsnd;

src/backend/replication/walsender.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1403,6 +1403,7 @@ pg_stat_get_wal_senders(PG_FUNCTION_ARGS)
14031403
int priority = 0;
14041404
int sync_standby = -1;
14051405
int i;
1406+
XLogRecPtr InvalidXLogRecPtr = {0, 0};
14061407

14071408
/* check to see if caller supports us returning a tuplestore */
14081409
if (rsinfo == NULL || !IsA(rsinfo, ReturnSetInfo))
@@ -1448,14 +1449,14 @@ pg_stat_get_wal_senders(PG_FUNCTION_ARGS)
14481449
* which always returns an invalid flush location, as an
14491450
* asynchronous standby.
14501451
*/
1451-
sync_priority[i] = XLogRecPtrIsInvalid(walsnd->flush) ?
1452+
sync_priority[i] = XLByteEQ(walsnd->flush, InvalidXLogRecPtr) ?
14521453
0 : walsnd->sync_standby_priority;
14531454

14541455
if (walsnd->state == WALSNDSTATE_STREAMING &&
14551456
walsnd->sync_standby_priority > 0 &&
14561457
(priority == 0 ||
14571458
priority > walsnd->sync_standby_priority) &&
1458-
!XLogRecPtrIsInvalid(walsnd->flush))
1459+
!XLByteEQ(walsnd->flush, InvalidXLogRecPtr))
14591460
{
14601461
priority = walsnd->sync_standby_priority;
14611462
sync_standby = i;

0 commit comments

Comments
 (0)