Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit521fd47

Browse files
committed
Use weaker locks when updating pg_subscription_rel
The previously used ShareRowExclusiveLock, while technically probablymore correct, led to deadlocks during seemingly unrelated operations andthus a poor experience. Use RowExclusiveLock, like for most similarcatalog operations. In some care cases, the user might see an errorfrom DDL commands.Discussion:https://www.postgresql.org/message-id/flat/13592.1490851519%40sss.pgh.pa.usAuthor: Petr Jelinek <petr.jelinek@2ndquadrant.com>
1 parentc45b1d2 commit521fd47

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

‎src/backend/catalog/pg_subscription.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,10 @@ textarray_to_stringlist(ArrayType *textarray)
214214

215215
/*
216216
* Set the state of a subscription table.
217+
*
218+
* The insert-or-update logic in this function is not concurrency safe so it
219+
* might raise an error in rare circumstances. But if we took a stronger lock
220+
* such as ShareRowExclusiveLock, we would risk more deadlocks.
217221
*/
218222
Oid
219223
SetSubscriptionRelState(Oidsubid,Oidrelid,charstate,
@@ -225,8 +229,7 @@ SetSubscriptionRelState(Oid subid, Oid relid, char state,
225229
boolnulls[Natts_pg_subscription_rel];
226230
Datumvalues[Natts_pg_subscription_rel];
227231

228-
/* Prevent concurrent changes. */
229-
rel=heap_open(SubscriptionRelRelationId,ShareRowExclusiveLock);
232+
rel=heap_open(SubscriptionRelRelationId,RowExclusiveLock);
230233

231234
/* Try finding existing mapping. */
232235
tup=SearchSysCacheCopy2(SUBSCRIPTIONRELMAP,
@@ -357,8 +360,7 @@ RemoveSubscriptionRel(Oid subid, Oid relid)
357360
HeapTupletup;
358361
intnkeys=0;
359362

360-
/* Prevent concurrent changes (see SetSubscriptionRelState()). */
361-
rel=heap_open(SubscriptionRelRelationId,ShareRowExclusiveLock);
363+
rel=heap_open(SubscriptionRelRelationId,RowExclusiveLock);
362364

363365
if (OidIsValid(subid))
364366
{
@@ -386,7 +388,7 @@ RemoveSubscriptionRel(Oid subid, Oid relid)
386388
}
387389
heap_endscan(scan);
388390

389-
heap_close(rel,ShareRowExclusiveLock);
391+
heap_close(rel,RowExclusiveLock);
390392
}
391393

392394

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp