From a12259efe7b4d0af570e7d2d7cb48b249158a1bd Mon Sep 17 00:00:00 2001 From: Petr Jelinek Date: Sat, 1 Apr 2017 02:20:16 +0200 Subject: [PATCH] Use weaker locks when updating subscription relation state --- src/backend/catalog/pg_subscription.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/backend/catalog/pg_subscription.c b/src/backend/catalog/pg_subscription.c index e7a1634..b0bd248 100644 --- a/src/backend/catalog/pg_subscription.c +++ b/src/backend/catalog/pg_subscription.c @@ -215,6 +215,9 @@ textarray_to_stringlist(ArrayType *textarray) /* * Set the state of a subscription table. + * + * The insert or update logic in this function is not concurrency safe so + * it may raise an error. */ Oid SetSubscriptionRelState(Oid subid, Oid relid, char state, @@ -227,7 +230,7 @@ SetSubscriptionRelState(Oid subid, Oid relid, char state, Datum values[Natts_pg_subscription_rel]; /* Prevent concurrent changes. */ - rel = heap_open(SubscriptionRelRelationId, ShareRowExclusiveLock); + rel = heap_open(SubscriptionRelRelationId, RowExclusiveLock); /* Try finding existing mapping. */ tup = SearchSysCacheCopy2(SUBSCRIPTIONRELMAP, @@ -358,8 +361,7 @@ RemoveSubscriptionRel(Oid subid, Oid relid) HeapTuple tup; int nkeys = 0; - /* Prevent concurrent changes (see SetSubscriptionRelState()). */ - rel = heap_open(SubscriptionRelRelationId, ShareRowExclusiveLock); + rel = heap_open(SubscriptionRelRelationId, RowExclusiveLock); if (OidIsValid(subid)) { @@ -387,7 +389,7 @@ RemoveSubscriptionRel(Oid subid, Oid relid) } heap_endscan(scan); - heap_close(rel, ShareRowExclusiveLock); + heap_close(rel, RowExclusiveLock); } -- 2.7.4