Skip to content

Commit cf358a2

Browse files
committed
Disallow starting server with insufficient wal_level for existing slot.
Previously it was possible to create a slot, change wal_level, and restart, even if the new wal_level was insufficient for the slot. That's a problem for both logical and physical slots, because the necessary WAL records are not generated. This removes a few tests in newer versions that, somewhat inexplicably, whether restarting with a too low wal_level worked (a buggy behaviour!). Reported-By: Joshua D. Drake Author: Andres Freund Discussion: https://postgr.es/m/20181029191304.lbsmhshkyymhw22w@alap3.anarazel.de Backpatch: 9.4-, where replication slots where introduced
1 parent 95015b1 commit cf358a2

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

src/backend/replication/logical/logical.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ CheckLogicalDecodingRequirements(void)
7272
{
7373
CheckSlotRequirements();
7474

75+
/*
76+
* NB: Adding a new requirement likely means that RestoreSlotFromDisk()
77+
* needs the same check.
78+
*/
79+
7580
if (wal_level < WAL_LEVEL_LOGICAL)
7681
ereport(ERROR,
7782
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),

src/backend/replication/slot.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -795,6 +795,11 @@ ReplicationSlotsCountDBSlots(Oid dboid, int *nslots, int *nactive)
795795
void
796796
CheckSlotRequirements(void)
797797
{
798+
/*
799+
* NB: Adding a new requirement likely means that RestoreSlotFromDisk()
800+
* needs the same check.
801+
*/
802+
798803
if (max_replication_slots == 0)
799804
ereport(ERROR,
800805
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
@@ -1236,6 +1241,31 @@ RestoreSlotFromDisk(const char *name)
12361241
return;
12371242
}
12381243

1244+
/*
1245+
* Verify that requirements for the specific slot type are met. That's
1246+
* important because if these aren't met we're not guaranteed to retain
1247+
* all the necessary resources for the slot.
1248+
*
1249+
* NB: We have to do so *after* the above checks for ephemeral slots,
1250+
* because otherwise a slot that shouldn't exist anymore could prevent
1251+
* restarts.
1252+
*
1253+
* NB: Changing the requirements here also requires adapting
1254+
* CheckSlotRequirements() and CheckLogicalDecodingRequirements().
1255+
*/
1256+
if (cp.slotdata.database != InvalidOid && wal_level < WAL_LEVEL_LOGICAL)
1257+
ereport(FATAL,
1258+
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
1259+
errmsg("logical replication slots \"%s\" exists, but wal_level < logical",
1260+
NameStr(cp.slotdata.name)),
1261+
errhint("Change wal_level to be replica or higher.")));
1262+
else if (wal_level < WAL_LEVEL_ARCHIVE)
1263+
ereport(FATAL,
1264+
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
1265+
errmsg("physical replication slots \"%s\" exists, but wal_level < archive",
1266+
NameStr(cp.slotdata.name)),
1267+
errhint("Change wal_level to be archive or higher.")));
1268+
12391269
/* nothing can be active yet, don't lock anything */
12401270
for (i = 0; i < max_replication_slots; i++)
12411271
{

0 commit comments

Comments
 (0)