Skip to content

Commit bf65400

Browse files
author
hackorum
committed
Apply wait_replication_slot_xmin_v2.patch
1 parent b597835 commit bf65400

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

src/backend/commands/indexcmds.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,7 @@ WaitForOlderSnapshots(TransactionId limitXmin, bool progress)
448448
int n_old_snapshots;
449449
int i;
450450
VirtualTransactionId *old_snapshots;
451+
TransactionId replication_slot_xmin = InvalidTransactionId;
451452

452453
old_snapshots = GetCurrentVirtualXIDs(limitXmin, true, false,
453454
PROC_IS_AUTOVACUUM | PROC_IN_VACUUM
@@ -507,6 +508,28 @@ WaitForOlderSnapshots(TransactionId limitXmin, bool progress)
507508
if (progress)
508509
pgstat_progress_update_param(PROGRESS_WAITFOR_DONE, i + 1);
509510
}
511+
512+
do
513+
{
514+
if (!TransactionIdIsNormal(limitXmin))
515+
break;
516+
517+
/*
518+
* Wait for the oldest replication slot xmin to exceed limitXmin to prevent
519+
* standby being unable to access old version data through the newly built
520+
* index.
521+
* It is necessary to wait only if replication_slot_xmin is "normal".
522+
* Since replication catalog xmin doesn't take into account snapshots for
523+
* backend connections, it doesn't need to be considered
524+
*/
525+
CHECK_FOR_INTERRUPTS();
526+
ProcArrayGetReplicationSlotXmin(&replication_slot_xmin, NULL);
527+
if (!TransactionIdIsNormal(replication_slot_xmin))
528+
break;
529+
if (!NormalTransactionIdPrecedes(replication_slot_xmin, limitXmin))
530+
break;
531+
pg_usleep(1000000);
532+
} while (true);
510533
}
511534

512535

0 commit comments

Comments
 (0)