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>
#include "nodes/makefuncs.h"
+#include "storage/lmgr.h"
+
#include "utils/array.h"
#include "utils/builtins.h"
#include "utils/fmgroids.h"
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. */
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));