Skip to content

Commit de396a1

Browse files
committed
Properly re-initialize replication slot shared memory upon creation.
Slot creation did not clear all fields upon creation. After start the memory is zeroed, but when a physical replication slot was created in the shared memory of a previously existing logical slot, catalog_xmin would not be cleared. That in turn would prevent vacuum from doing its duties. To fix initialize all the fields. To make similar future bugs less likely, zero all of ReplicationSlotPersistentData, and re-order the rest of the initialization to be in struct member order. Analysis: Andrew Gierth Reported-By: md@chewy.com Author: Michael Paquier Discussion: <20160705173502.1398.70934@wrigleys.postgresql.org> Backpatch: 9.4, where replication slots were introduced
1 parent 509815e commit de396a1

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

src/backend/replication/slot.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -263,12 +263,22 @@ ReplicationSlotCreate(const char *name, bool db_specific,
263263
*/
264264
Assert(!slot->in_use);
265265
Assert(slot->active_pid == 0);
266-
slot->data.persistency = persistency;
267-
slot->data.xmin = InvalidTransactionId;
268-
slot->effective_xmin = InvalidTransactionId;
266+
267+
/* first initialize persistent data */
268+
memset(&slot->data, 0, sizeof(ReplicationSlotPersistentData));
269269
StrNCpy(NameStr(slot->data.name), name, NAMEDATALEN);
270270
slot->data.database = db_specific ? MyDatabaseId : InvalidOid;
271-
slot->data.restart_lsn = InvalidXLogRecPtr;
271+
slot->data.persistency = persistency;
272+
273+
/* and then data only present in shared memory */
274+
slot->just_dirtied = false;
275+
slot->dirty = false;
276+
slot->effective_xmin = InvalidTransactionId;
277+
slot->effective_catalog_xmin = InvalidTransactionId;
278+
slot->candidate_catalog_xmin = InvalidTransactionId;
279+
slot->candidate_xmin_lsn = InvalidXLogRecPtr;
280+
slot->candidate_restart_valid = InvalidXLogRecPtr;
281+
slot->candidate_restart_lsn = InvalidXLogRecPtr;
272282

273283
/*
274284
* Create the slot on disk. We haven't actually marked the slot allocated

0 commit comments

Comments
 (0)