]> granicus.if.org Git - postgresql/commitdiff
Improve subscription locking
authorPeter Eisentraut <peter_e@gmx.net>
Tue, 4 Jul 2017 02:47:06 +0000 (22:47 -0400)
committerPeter Eisentraut <peter_e@gmx.net>
Tue, 4 Jul 2017 02:47:06 +0000 (22:47 -0400)
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>

src/backend/catalog/pg_subscription.c
src/backend/commands/subscriptioncmds.c

index c69c461b62a5e656c2a1c516ffd9b2eba0ef99a3..fb53d71cd6606167636a831ad0756c226da670d3 100644 (file)
@@ -28,6 +28,8 @@
 
 #include "nodes/makefuncs.h"
 
+#include "storage/lmgr.h"
+
 #include "utils/array.h"
 #include "utils/builtins.h"
 #include "utils/fmgroids.h"
@@ -246,6 +248,8 @@ SetSubscriptionRelState(Oid subid, Oid relid, char state,
        bool            nulls[Natts_pg_subscription_rel];
        Datum           values[Natts_pg_subscription_rel];
 
+       LockSharedObject(SubscriptionRelationId, subid, 0, AccessShareLock);
+
        rel = heap_open(SubscriptionRelRelationId, RowExclusiveLock);
 
        /* Try finding existing mapping. */
index 9cbd36f6463d4db0c02b937901b9f41569ea762a..6dc3f6ee0009dedec1b7116b2fc167a849a8eb5c 100644 (file)
@@ -644,6 +644,9 @@ AlterSubscription(AlterSubscriptionStmt *stmt)
        subid = HeapTupleGetOid(tup);
        sub = GetSubscription(subid, false);
 
+       /* Lock the subscription so nobody else can do anything with it. */
+       LockSharedObject(SubscriptionRelationId, subid, 0, AccessExclusiveLock);
+
        /* Form a new tuple. */
        memset(values, 0, sizeof(values));
        memset(nulls, false, sizeof(nulls));