]> granicus.if.org Git - postgresql/commitdiff
Improve lock level choices in pg_shdepend.c. Noticed by Tom Lane.
authorAlvaro Herrera <alvherre@alvh.no-ip.org>
Wed, 23 Jan 2008 15:36:38 +0000 (15:36 +0000)
committerAlvaro Herrera <alvherre@alvh.no-ip.org>
Wed, 23 Jan 2008 15:36:38 +0000 (15:36 +0000)
src/backend/catalog/pg_shdepend.c

index dd326648ec20be4040f6d63f878f285cd1d0905c..be37d628ae40d02062d77790f7aeaf99de1946b5 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/catalog/pg_shdepend.c,v 1.22 2008/01/01 19:45:48 momjian Exp $
+ *       $PostgreSQL: pgsql/src/backend/catalog/pg_shdepend.c,v 1.23 2008/01/23 15:36:38 alvherre Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -1110,7 +1110,12 @@ shdepDropOwned(List *roleids, DropBehavior behavior)
 
        deleteobjs = new_object_addresses();
 
-       sdepRel = heap_open(SharedDependRelationId, AccessExclusiveLock);
+       /*
+        * We don't need this strong a lock here, but we'll call routines that
+        * acquire RowExclusiveLock.  Better get that right now to avoid potential
+        * deadlock failures.
+        */
+       sdepRel = heap_open(SharedDependRelationId, RowExclusiveLock);
 
        /*
         * For each role, find the dependent objects and drop them using the
@@ -1224,7 +1229,7 @@ shdepDropOwned(List *roleids, DropBehavior behavior)
        /* the dependency mechanism does the actual work */
        performMultipleDeletions(deleteobjs, behavior);
 
-       heap_close(sdepRel, AccessExclusiveLock);
+       heap_close(sdepRel, RowExclusiveLock);
 
        free_object_addresses(deleteobjs);
 }
@@ -1241,7 +1246,12 @@ shdepReassignOwned(List *roleids, Oid newrole)
        Relation        sdepRel;
        ListCell   *cell;
 
-       sdepRel = heap_open(SharedDependRelationId, AccessShareLock);
+       /*
+        * We don't need this strong a lock here, but we'll call routines that
+        * acquire RowExclusiveLock.  Better get that right now to avoid potential
+        * deadlock problems.
+        */
+       sdepRel = heap_open(SharedDependRelationId, RowExclusiveLock);
 
        foreach(cell, roleids)
        {
@@ -1343,5 +1353,5 @@ shdepReassignOwned(List *roleids, Oid newrole)
                systable_endscan(scan);
        }
 
-       heap_close(sdepRel, AccessShareLock);
+       heap_close(sdepRel, RowExclusiveLock);
 }