diff options
author | Alvaro Herrera <alvherre@alvh.no-ip.org> | 2020-06-26 20:41:29 -0400 |
---|---|---|
committer | Alvaro Herrera <alvherre@alvh.no-ip.org> | 2020-06-26 20:41:29 -0400 |
commit | 3b4b541777f0b85df7626623ef78df0ea48ca5dc (patch) | |
tree | 8e5944809b8bf193bf856f1ce3c4f730905946fc /src/backend/replication/slotfuncs.c | |
parent | 1f601b14e3a7c5ca035cfb59575462004a8c3125 (diff) | |
download | postgresql-3b4b541777f0b85df7626623ef78df0ea48ca5dc.tar.gz postgresql-3b4b541777f0b85df7626623ef78df0ea48ca5dc.zip |
Persist slot invalidation correctly
We failed to save slot to disk after invalidating it, so the state was
lost in case of server restart or crash. Fix by marking it dirty and
flushing.
Also, if the slot is known invalidated we don't need to reason about the
LSN at all -- it's known invalidated. Only test the LSN if the slot is
known not invalidated.
Author: Fujii Masao <masao.fujii@oss.nttdata.com>
Author: Kyotaro Horiguchi <horikyota.ntt@gmail.com>
Reviewed-by: Álvaro Herrera <alvherre@alvh.no-ip.org>
Discussion: https://postgr.es/m/17a69cfe-f1c1-a416-ee25-ae15427c69eb@oss.nttdata.com
Diffstat (limited to 'src/backend/replication/slotfuncs.c')
-rw-r--r-- | src/backend/replication/slotfuncs.c | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/src/backend/replication/slotfuncs.c b/src/backend/replication/slotfuncs.c index fca18ffae53..88033a79b21 100644 --- a/src/backend/replication/slotfuncs.c +++ b/src/backend/replication/slotfuncs.c @@ -283,7 +283,6 @@ pg_get_replication_slots(PG_FUNCTION_ARGS) bool nulls[PG_GET_REPLICATION_SLOTS_COLS]; WALAvailability walstate; XLogSegNo last_removed_seg; - XLogRecPtr targetLSN; int i; if (!slot->in_use) @@ -344,14 +343,15 @@ pg_get_replication_slots(PG_FUNCTION_ARGS) nulls[i++] = true; /* - * Report availability from invalidated_at when the slot has been - * invalidated; otherwise slots would appear as invalid without any - * more clues as to what happened. + * If invalidated_at is valid and restart_lsn is invalid, we know for + * certain that the slot has been invalidated. Otherwise, test + * availability from restart_lsn. */ - targetLSN = XLogRecPtrIsInvalid(slot_contents.data.restart_lsn) ? - slot_contents.data.invalidated_at : - slot_contents.data.restart_lsn; - walstate = GetWALAvailability(targetLSN); + if (XLogRecPtrIsInvalid(slot_contents.data.restart_lsn) && + !XLogRecPtrIsInvalid(slot_contents.data.invalidated_at)) + walstate = WALAVAIL_REMOVED; + else + walstate = GetWALAvailability(slot_contents.data.restart_lsn); switch (walstate) { |