mirror of
https://github.com/postgres/postgres.git
synced 2025-09-03 15:22:11 +03:00
Handle logical slot conflicts on standby
During WAL replay on the standby, when a conflict with a logical slot is identified, invalidate such slots. There are two sources of conflicts: 1) Using the information added in6af1793954
, logical slots are invalidated if required rows are removed 2) wal_level on the primary server is reduced to below logical Uses the infrastructure introduced in the prior commit. FIXME: add commit reference. Change InvalidatePossiblyObsoleteSlot() to use a recovery conflict to interrupt use of a slot, if called in the startup process. The new recovery conflict is added to pg_stat_database_conflicts, as confl_active_logicalslot. See6af1793954
for an overall design of logical decoding on a standby. Bumps catversion for the addition of the pg_stat_database_conflicts column. Bumps PGSTAT_FILE_FORMAT_ID for the same reason. Author: "Drouvot, Bertrand" <bertranddrouvot.pg@gmail.com> Author: Andres Freund <andres@anarazel.de> Author: Amit Khandekar <amitdkhan.pg@gmail.com> (in an older version) Reviewed-by: "Drouvot, Bertrand" <bertranddrouvot.pg@gmail.com> Reviewed-by: Andres Freund <andres@anarazel.de> Reviewed-by: Robert Haas <robertmhaas@gmail.com> Reviewed-by: Fabrízio de Royes Mello <fabriziomello@gmail.com> Reviewed-by: Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com> Reviewed-by: Amit Kapila <amit.kapila16@gmail.com> Reviewed-by: Alvaro Herrera <alvherre@alvh.no-ip.org> Discussion: https://postgr.es/m/20230407075009.igg7be27ha2htkbt@awork3.anarazel.de
This commit is contained in:
@@ -197,6 +197,7 @@ gistRedoDeleteRecord(XLogReaderState *record)
|
||||
XLogRecGetBlockTag(record, 0, &rlocator, NULL, NULL);
|
||||
|
||||
ResolveRecoveryConflictWithSnapshot(xldata->snapshotConflictHorizon,
|
||||
xldata->isCatalogRel,
|
||||
rlocator);
|
||||
}
|
||||
|
||||
@@ -390,6 +391,7 @@ gistRedoPageReuse(XLogReaderState *record)
|
||||
*/
|
||||
if (InHotStandby)
|
||||
ResolveRecoveryConflictWithSnapshotFullXid(xlrec->snapshotConflictHorizon,
|
||||
xlrec->isCatalogRel,
|
||||
xlrec->locator);
|
||||
}
|
||||
|
||||
|
@@ -1003,6 +1003,7 @@ hash_xlog_vacuum_one_page(XLogReaderState *record)
|
||||
|
||||
XLogRecGetBlockTag(record, 0, &rlocator, NULL, NULL);
|
||||
ResolveRecoveryConflictWithSnapshot(xldata->snapshotConflictHorizon,
|
||||
xldata->isCatalogRel,
|
||||
rlocator);
|
||||
}
|
||||
|
||||
|
@@ -8769,6 +8769,7 @@ heap_xlog_prune(XLogReaderState *record)
|
||||
*/
|
||||
if (InHotStandby)
|
||||
ResolveRecoveryConflictWithSnapshot(xlrec->snapshotConflictHorizon,
|
||||
xlrec->isCatalogRel,
|
||||
rlocator);
|
||||
|
||||
/*
|
||||
@@ -8940,6 +8941,7 @@ heap_xlog_visible(XLogReaderState *record)
|
||||
*/
|
||||
if (InHotStandby)
|
||||
ResolveRecoveryConflictWithSnapshot(xlrec->snapshotConflictHorizon,
|
||||
xlrec->flags & VISIBILITYMAP_XLOG_CATALOG_REL,
|
||||
rlocator);
|
||||
|
||||
/*
|
||||
@@ -9061,6 +9063,7 @@ heap_xlog_freeze_page(XLogReaderState *record)
|
||||
|
||||
XLogRecGetBlockTag(record, 0, &rlocator, NULL, NULL);
|
||||
ResolveRecoveryConflictWithSnapshot(xlrec->snapshotConflictHorizon,
|
||||
xlrec->isCatalogRel,
|
||||
rlocator);
|
||||
}
|
||||
|
||||
|
@@ -669,6 +669,7 @@ btree_xlog_delete(XLogReaderState *record)
|
||||
XLogRecGetBlockTag(record, 0, &rlocator, NULL, NULL);
|
||||
|
||||
ResolveRecoveryConflictWithSnapshot(xlrec->snapshotConflictHorizon,
|
||||
xlrec->isCatalogRel,
|
||||
rlocator);
|
||||
}
|
||||
|
||||
@@ -1007,6 +1008,7 @@ btree_xlog_reuse_page(XLogReaderState *record)
|
||||
|
||||
if (InHotStandby)
|
||||
ResolveRecoveryConflictWithSnapshotFullXid(xlrec->snapshotConflictHorizon,
|
||||
xlrec->isCatalogRel,
|
||||
xlrec->locator);
|
||||
}
|
||||
|
||||
|
@@ -879,6 +879,7 @@ spgRedoVacuumRedirect(XLogReaderState *record)
|
||||
|
||||
XLogRecGetBlockTag(record, 0, &locator, NULL, NULL);
|
||||
ResolveRecoveryConflictWithSnapshot(xldata->snapshotConflictHorizon,
|
||||
xldata->isCatalogRel,
|
||||
locator);
|
||||
}
|
||||
|
||||
|
@@ -7970,6 +7970,21 @@ xlog_redo(XLogReaderState *record)
|
||||
/* Update our copy of the parameters in pg_control */
|
||||
memcpy(&xlrec, XLogRecGetData(record), sizeof(xl_parameter_change));
|
||||
|
||||
/*
|
||||
* Invalidate logical slots if we are in hot standby and the primary
|
||||
* does not have a WAL level sufficient for logical decoding. No need
|
||||
* to search for potentially conflicting logically slots if standby is
|
||||
* running with wal_level lower than logical, because in that case, we
|
||||
* would have either disallowed creation of logical slots or
|
||||
* invalidated existing ones.
|
||||
*/
|
||||
if (InRecovery && InHotStandby &&
|
||||
xlrec.wal_level < WAL_LEVEL_LOGICAL &&
|
||||
wal_level >= WAL_LEVEL_LOGICAL)
|
||||
InvalidateObsoleteReplicationSlots(RS_INVAL_WAL_LEVEL,
|
||||
0, InvalidOid,
|
||||
InvalidTransactionId);
|
||||
|
||||
LWLockAcquire(ControlFileLock, LW_EXCLUSIVE);
|
||||
ControlFile->MaxConnections = xlrec.MaxConnections;
|
||||
ControlFile->max_worker_processes = xlrec.max_worker_processes;
|
||||
|
Reference in New Issue
Block a user