Skip to content
Snippets Groups Projects
Commit 8cb23dba authored by Andres Freund's avatar Andres Freund
Browse files

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: default avatar <md@chewy.com>
Author: Michael Paquier
Discussion: <20160705173502.1398.70934@wrigleys.postgresql.org>
Backpatch: 9.4, where replication slots were introduced
parent d715b76d
No related branches found
Tags
No related merge requests found
...@@ -272,12 +272,22 @@ ReplicationSlotCreate(const char *name, bool db_specific, ...@@ -272,12 +272,22 @@ ReplicationSlotCreate(const char *name, bool db_specific,
*/ */
Assert(!slot->in_use); Assert(!slot->in_use);
Assert(slot->active_pid == 0); Assert(slot->active_pid == 0);
slot->data.persistency = persistency;
slot->data.xmin = InvalidTransactionId; /* first initialize persistent data */
slot->effective_xmin = InvalidTransactionId; memset(&slot->data, 0, sizeof(ReplicationSlotPersistentData));
StrNCpy(NameStr(slot->data.name), name, NAMEDATALEN); StrNCpy(NameStr(slot->data.name), name, NAMEDATALEN);
slot->data.database = db_specific ? MyDatabaseId : InvalidOid; slot->data.database = db_specific ? MyDatabaseId : InvalidOid;
slot->data.restart_lsn = InvalidXLogRecPtr; slot->data.persistency = persistency;
/* and then data only present in shared memory */
slot->just_dirtied = false;
slot->dirty = false;
slot->effective_xmin = InvalidTransactionId;
slot->effective_catalog_xmin = InvalidTransactionId;
slot->candidate_catalog_xmin = InvalidTransactionId;
slot->candidate_xmin_lsn = InvalidXLogRecPtr;
slot->candidate_restart_valid = InvalidXLogRecPtr;
slot->candidate_restart_lsn = InvalidXLogRecPtr;
/* /*
* Create the slot on disk. We haven't actually marked the slot allocated * Create the slot on disk. We haven't actually marked the slot allocated
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment