Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 154f26f

Browse files
committed
RemoveAttrDefaultById() neglected to obtain exclusive lock on the
relation being modified. In most paths of control we'd already have such a lock, but if we were dropping the default due to a cascaded delete of some function it depended on, maybe not.
1 parent 21cf6b2 commit 154f26f

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/backend/catalog/heap.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/catalog/heap.c,v 1.215 2002/08/02 18:15:05 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/catalog/heap.c,v 1.216 2002/08/02 21:54:34 tgl Exp $
1212
*
1313
*
1414
* INTERFACE ROUTINES
@@ -1027,6 +1027,7 @@ RemoveAttrDefaultById(Oid attrdefId)
10271027
{
10281028
Relation attrdef_rel;
10291029
Relation attr_rel;
1030+
Relation myrel;
10301031
ScanKeyData scankeys[1];
10311032
SysScanDesc scan;
10321033
HeapTuple tuple;
@@ -1036,6 +1037,7 @@ RemoveAttrDefaultById(Oid attrdefId)
10361037
/* Grab an appropriate lock on the pg_attrdef relation */
10371038
attrdef_rel = heap_openr(AttrDefaultRelationName, RowExclusiveLock);
10381039

1040+
/* Find the pg_attrdef tuple */
10391041
ScanKeyEntryInitialize(&scankeys[0], 0x0,
10401042
ObjectIdAttributeNumber, F_OIDEQ,
10411043
ObjectIdGetDatum(attrdefId));
@@ -1051,6 +1053,10 @@ RemoveAttrDefaultById(Oid attrdefId)
10511053
myrelid = ((Form_pg_attrdef) GETSTRUCT(tuple))->adrelid;
10521054
myattnum = ((Form_pg_attrdef) GETSTRUCT(tuple))->adnum;
10531055

1056+
/* Get an exclusive lock on the relation owning the attribute */
1057+
myrel = heap_open(myrelid, AccessExclusiveLock);
1058+
1059+
/* Now we can delete the pg_attrdef row */
10541060
simple_heap_delete(attrdef_rel, &tuple->t_self);
10551061

10561062
systable_endscan(scan);
@@ -1081,7 +1087,14 @@ RemoveAttrDefaultById(Oid attrdefId)
10811087
CatalogCloseIndices(Num_pg_attr_indices, idescs);
10821088
}
10831089

1090+
/*
1091+
* Our update of the pg_attribute row will force a relcache rebuild,
1092+
* so there's nothing else to do here.
1093+
*/
10841094
heap_close(attr_rel, RowExclusiveLock);
1095+
1096+
/* Keep lock on attribute's rel until end of xact */
1097+
heap_close(myrel, NoLock);
10851098
}
10861099

10871100
/* ----------------------------------------------------------------

0 commit comments

Comments
 (0)