mirror of
https://github.com/postgres/postgres.git
synced 2025-06-30 21:42:05 +03:00
Block replication slot advance for these not yet reserving WAL
Such replication slots are physical slots freshly created without WAL being reserved, which is the default behavior, which have not been used yet as WAL consumption resources to retain WAL. This prevents advancing a slot to a position older than any WAL available, which could falsify calculations for WAL segment recycling. This also cleans up a bit the code, as ReplicationSlotRelease() would be called on ERROR, and improves error messages. Reported-by: Kyotaro Horiguchi Author: Michael Paquier Reviewed-by: Andres Freund, Álvaro Herrera, Kyotaro Horiguchi Discussion: https://postgr.es/m/20180626071305.GH31353@paquier.xyz
This commit is contained in:
@ -483,6 +483,12 @@ pg_replication_slot_advance(PG_FUNCTION_ARGS)
|
||||
/* Acquire the slot so we "own" it */
|
||||
ReplicationSlotAcquire(NameStr(*slotname), true);
|
||||
|
||||
/* A slot whose restart_lsn has never been reserved cannot be advanced */
|
||||
if (XLogRecPtrIsInvalid(MyReplicationSlot->data.restart_lsn))
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
|
||||
errmsg("cannot advance replication slot that has not previously reserved WAL")));
|
||||
|
||||
/*
|
||||
* Check if the slot is not moving backwards. Physical slots rely simply
|
||||
* on restart_lsn as a minimum point, while logical slots have confirmed
|
||||
@ -495,14 +501,11 @@ pg_replication_slot_advance(PG_FUNCTION_ARGS)
|
||||
minlsn = MyReplicationSlot->data.restart_lsn;
|
||||
|
||||
if (moveto < minlsn)
|
||||
{
|
||||
ReplicationSlotRelease();
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||
errmsg("cannot move slot to %X/%X, minimum is %X/%X",
|
||||
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
|
||||
errmsg("cannot advance replication slot to %X/%X, minimum is %X/%X",
|
||||
(uint32) (moveto >> 32), (uint32) moveto,
|
||||
(uint32) (minlsn >> 32), (uint32) minlsn)));
|
||||
}
|
||||
|
||||
/* Do the actual slot update, depending on the slot type */
|
||||
if (OidIsValid(MyReplicationSlot->data.database))
|
||||
|
Reference in New Issue
Block a user