Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 8984c8b

Browse files
committed
Improve lock level choices in pg_shdepend.c. Noticed by Tom Lane.
1 parent 6a7a63d commit 8984c8b

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

src/backend/catalog/pg_shdepend.c

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/catalog/pg_shdepend.c,v 1.22 2008/01/01 19:45:48 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/catalog/pg_shdepend.c,v 1.23 2008/01/23 15:36:38 alvherre Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -1110,7 +1110,12 @@ shdepDropOwned(List *roleids, DropBehavior behavior)
11101110

11111111
deleteobjs = new_object_addresses();
11121112

1113-
sdepRel = heap_open(SharedDependRelationId, AccessExclusiveLock);
1113+
/*
1114+
* We don't need this strong a lock here, but we'll call routines that
1115+
* acquire RowExclusiveLock. Better get that right now to avoid potential
1116+
* deadlock failures.
1117+
*/
1118+
sdepRel = heap_open(SharedDependRelationId, RowExclusiveLock);
11141119

11151120
/*
11161121
* For each role, find the dependent objects and drop them using the
@@ -1224,7 +1229,7 @@ shdepDropOwned(List *roleids, DropBehavior behavior)
12241229
/* the dependency mechanism does the actual work */
12251230
performMultipleDeletions(deleteobjs, behavior);
12261231

1227-
heap_close(sdepRel, AccessExclusiveLock);
1232+
heap_close(sdepRel, RowExclusiveLock);
12281233

12291234
free_object_addresses(deleteobjs);
12301235
}
@@ -1241,7 +1246,12 @@ shdepReassignOwned(List *roleids, Oid newrole)
12411246
Relation sdepRel;
12421247
ListCell *cell;
12431248

1244-
sdepRel = heap_open(SharedDependRelationId, AccessShareLock);
1249+
/*
1250+
* We don't need this strong a lock here, but we'll call routines that
1251+
* acquire RowExclusiveLock. Better get that right now to avoid potential
1252+
* deadlock problems.
1253+
*/
1254+
sdepRel = heap_open(SharedDependRelationId, RowExclusiveLock);
12451255

12461256
foreach(cell, roleids)
12471257
{
@@ -1343,5 +1353,5 @@ shdepReassignOwned(List *roleids, Oid newrole)
13431353
systable_endscan(scan);
13441354
}
13451355

1346-
heap_close(sdepRel, AccessShareLock);
1356+
heap_close(sdepRel, RowExclusiveLock);
13471357
}

0 commit comments

Comments
 (0)