mirror of
https://github.com/postgres/postgres.git
synced 2025-11-10 17:42:29 +03:00
Track invalidation_reason in pg_replication_slots.
Till now, the reason for replication slot invalidation is not tracked directly in pg_replication_slots. A recent commit007693f2a3added 'conflict_reason' to show the reasons for slot conflict/invalidation, but only for logical slots. This commit adds a new column 'invalidation_reason' to show invalidation reasons for both physical and logical slots. And, this commit also turns 'conflict_reason' text column to 'conflicting' boolean column (effectively reverting commit007693f2a3). The 'conflicting' column is true for invalidation reasons 'rows_removed' and 'wal_level_insufficient' because those make the slot conflict with recovery. When 'conflicting' is true, one can now look at the new 'invalidation_reason' column for the reason for the logical slot's conflict with recovery. The new 'invalidation_reason' column will also be useful to track other invalidation reasons in the future commit. Author: Bharath Rupireddy Reviewed-by: Bertrand Drouvot, Amit Kapila, Shveta Malik Discussion: https://www.postgresql.org/message-id/ZfR7HuzFEswakt/a%40ip-10-97-1-34.eu-west-3.compute.internal Discussion: https://www.postgresql.org/message-id/CALj2ACW4aUe-_uFQOjdWCEN-xXoLGhmvRFnL8SNw_TZ5nJe+aw@mail.gmail.com
This commit is contained in:
@@ -239,7 +239,7 @@ pg_drop_replication_slot(PG_FUNCTION_ARGS)
|
||||
Datum
|
||||
pg_get_replication_slots(PG_FUNCTION_ARGS)
|
||||
{
|
||||
#define PG_GET_REPLICATION_SLOTS_COLS 17
|
||||
#define PG_GET_REPLICATION_SLOTS_COLS 18
|
||||
ReturnSetInfo *rsinfo = (ReturnSetInfo *) fcinfo->resultinfo;
|
||||
XLogRecPtr currlsn;
|
||||
int slotno;
|
||||
@@ -263,6 +263,7 @@ pg_get_replication_slots(PG_FUNCTION_ARGS)
|
||||
bool nulls[PG_GET_REPLICATION_SLOTS_COLS];
|
||||
WALAvailability walstate;
|
||||
int i;
|
||||
ReplicationSlotInvalidationCause cause;
|
||||
|
||||
if (!slot->in_use)
|
||||
continue;
|
||||
@@ -409,18 +410,28 @@ pg_get_replication_slots(PG_FUNCTION_ARGS)
|
||||
|
||||
values[i++] = BoolGetDatum(slot_contents.data.two_phase);
|
||||
|
||||
if (slot_contents.data.database == InvalidOid)
|
||||
cause = slot_contents.data.invalidated;
|
||||
|
||||
if (SlotIsPhysical(&slot_contents))
|
||||
nulls[i++] = true;
|
||||
else
|
||||
{
|
||||
ReplicationSlotInvalidationCause cause = slot_contents.data.invalidated;
|
||||
|
||||
if (cause == RS_INVAL_NONE)
|
||||
nulls[i++] = true;
|
||||
/*
|
||||
* rows_removed and wal_level_insufficient are the only two
|
||||
* reasons for the logical slot's conflict with recovery.
|
||||
*/
|
||||
if (cause == RS_INVAL_HORIZON ||
|
||||
cause == RS_INVAL_WAL_LEVEL)
|
||||
values[i++] = BoolGetDatum(true);
|
||||
else
|
||||
values[i++] = CStringGetTextDatum(SlotInvalidationCauses[cause]);
|
||||
values[i++] = BoolGetDatum(false);
|
||||
}
|
||||
|
||||
if (cause == RS_INVAL_NONE)
|
||||
nulls[i++] = true;
|
||||
else
|
||||
values[i++] = CStringGetTextDatum(SlotInvalidationCauses[cause]);
|
||||
|
||||
values[i++] = BoolGetDatum(slot_contents.data.failover);
|
||||
|
||||
values[i++] = BoolGetDatum(slot_contents.data.synced);
|
||||
|
||||
Reference in New Issue
Block a user