Skip to content

Commit cb9079c

Browse files
committed
Improve subscription locking
This avoids "tuple concurrently updated" errors when a ALTER or DROP SUBSCRIPTION writes to pg_subscription_rel at the same time as a worker. Author: Petr Jelinek <petr.jelinek@2ndquadrant.com>
1 parent 42794d6 commit cb9079c

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

src/backend/catalog/pg_subscription.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828

2929
#include "nodes/makefuncs.h"
3030

31+
#include "storage/lmgr.h"
32+
3133
#include "utils/array.h"
3234
#include "utils/builtins.h"
3335
#include "utils/fmgroids.h"
@@ -246,6 +248,8 @@ SetSubscriptionRelState(Oid subid, Oid relid, char state,
246248
bool nulls[Natts_pg_subscription_rel];
247249
Datum values[Natts_pg_subscription_rel];
248250

251+
LockSharedObject(SubscriptionRelationId, subid, 0, AccessShareLock);
252+
249253
rel = heap_open(SubscriptionRelRelationId, RowExclusiveLock);
250254

251255
/* Try finding existing mapping. */

src/backend/commands/subscriptioncmds.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,9 @@ AlterSubscription(AlterSubscriptionStmt *stmt)
644644
subid = HeapTupleGetOid(tup);
645645
sub = GetSubscription(subid, false);
646646

647+
/* Lock the subscription so nobody else can do anything with it. */
648+
LockSharedObject(SubscriptionRelationId, subid, 0, AccessExclusiveLock);
649+
647650
/* Form a new tuple. */
648651
memset(values, 0, sizeof(values));
649652
memset(nulls, false, sizeof(nulls));

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy