mirror of
https://github.com/postgres/postgres.git
synced 2025-07-07 00:36:50 +03:00
Allow pg_create_physical_replication_slot() to reserve WAL.
When creating a physical slot it's often useful to immediately reserve the current WAL position instead of only doing after the first feedback message arrives. That e.g. allows slots to guarantee that all the WAL for a base backup will be available afterwards. Logical slots already have to reserve WAL during creation, so generalize that logic into being usable for both physical and logical slots. Catversion bump because of the new parameter. Author: Gurjeet Singh Reviewed-By: Andres Freund Discussion: CABwTF4Wh_dBCzTU=49pFXR6coR4NW1ynb+vBqT+Po=7fuq5iCw@mail.gmail.com
This commit is contained in:
@ -250,52 +250,7 @@ CreateInitDecodingContext(char *plugin,
|
||||
StrNCpy(NameStr(slot->data.plugin), plugin, NAMEDATALEN);
|
||||
SpinLockRelease(&slot->mutex);
|
||||
|
||||
/*
|
||||
* The replication slot mechanism is used to prevent removal of required
|
||||
* WAL. As there is no interlock between this and checkpoints required WAL
|
||||
* could be removed before ReplicationSlotsComputeRequiredLSN() has been
|
||||
* called to prevent that. In the very unlikely case that this happens
|
||||
* we'll just retry.
|
||||
*/
|
||||
while (true)
|
||||
{
|
||||
XLogSegNo segno;
|
||||
|
||||
/*
|
||||
* Let's start with enough information if we can, so log a standby
|
||||
* snapshot and start decoding at exactly that position.
|
||||
*/
|
||||
if (!RecoveryInProgress())
|
||||
{
|
||||
XLogRecPtr flushptr;
|
||||
|
||||
/* start at current insert position */
|
||||
slot->data.restart_lsn = GetXLogInsertRecPtr();
|
||||
|
||||
/* make sure we have enough information to start */
|
||||
flushptr = LogStandbySnapshot();
|
||||
|
||||
/* and make sure it's fsynced to disk */
|
||||
XLogFlush(flushptr);
|
||||
}
|
||||
else
|
||||
slot->data.restart_lsn = GetRedoRecPtr();
|
||||
|
||||
/* prevent WAL removal as fast as possible */
|
||||
ReplicationSlotsComputeRequiredLSN();
|
||||
|
||||
/*
|
||||
* If all required WAL is still there, great, otherwise retry. The
|
||||
* slot should prevent further removal of WAL, unless there's a
|
||||
* concurrent ReplicationSlotsComputeRequiredLSN() after we've written
|
||||
* the new restart_lsn above, so normally we should never need to loop
|
||||
* more than twice.
|
||||
*/
|
||||
XLByteToSeg(slot->data.restart_lsn, segno);
|
||||
if (XLogGetLastRemovedSegno() < segno)
|
||||
break;
|
||||
}
|
||||
|
||||
ReplicationSlotReserveWal();
|
||||
|
||||
/* ----
|
||||
* This is a bit tricky: We need to determine a safe xmin horizon to start
|
||||
|
Reference in New Issue
Block a user