Skip to content

Commit 198de79

Browse files
committed
Clean out column-level pg_init_privs entries when dropping tables.
DeleteInitPrivs did not get the memo about how, when dropping a whole object (with subid == 0), you should drop entries relating to its sub-objects too. This is visible in the test_pg_dump test case if one drops the extension at the end: the entry for GRANT SELECT(col1) ON regress_pg_dump_table TO public; was still present in pg_init_privs afterwards, although it was pointing to a dangling table OID. Noted while fooling with a fix for REASSIGN OWNED for pg_init_privs entries. This bug is aboriginal in the pg_init_privs feature though, and there seems no reason not to back-patch the fix.
1 parent c7de5a6 commit 198de79

File tree

3 files changed

+27
-6
lines changed

3 files changed

+27
-6
lines changed

src/backend/catalog/dependency.c

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1328,7 +1328,9 @@ deleteOneObject(const ObjectAddress *object, Relation *depRel, int flags)
13281328
/*
13291329
* Delete any comments, security labels, or initial privileges associated
13301330
* with this object. (This is a convenient place to do these things,
1331-
* rather than having every object type know to do it.)
1331+
* rather than having every object type know to do it.) As above, all
1332+
* these functions must remove records for sub-objects too if the subid is
1333+
* zero.
13321334
*/
13331335
DeleteComments(object->objectId, object->classId, object->objectSubId);
13341336
DeleteSecurityLabel(object);
@@ -2887,6 +2889,7 @@ DeleteInitPrivs(const ObjectAddress *object)
28872889
{
28882890
Relation relation;
28892891
ScanKeyData key[3];
2892+
int nkeys;
28902893
SysScanDesc scan;
28912894
HeapTuple oldtuple;
28922895

@@ -2900,13 +2903,19 @@ DeleteInitPrivs(const ObjectAddress *object)
29002903
Anum_pg_init_privs_classoid,
29012904
BTEqualStrategyNumber, F_OIDEQ,
29022905
ObjectIdGetDatum(object->classId));
2903-
ScanKeyInit(&key[2],
2904-
Anum_pg_init_privs_objsubid,
2905-
BTEqualStrategyNumber, F_INT4EQ,
2906-
Int32GetDatum(object->objectSubId));
2906+
if (object->objectSubId != 0)
2907+
{
2908+
ScanKeyInit(&key[2],
2909+
Anum_pg_init_privs_objsubid,
2910+
BTEqualStrategyNumber, F_INT4EQ,
2911+
Int32GetDatum(object->objectSubId));
2912+
nkeys = 3;
2913+
}
2914+
else
2915+
nkeys = 2;
29072916

29082917
scan = systable_beginscan(relation, InitPrivsObjIndexId, true,
2909-
NULL, 3, key);
2918+
NULL, nkeys, key);
29102919

29112920
while (HeapTupleIsValid(oldtuple = systable_getnext(scan)))
29122921
CatalogTupleDelete(relation, &oldtuple->t_self);

src/test/modules/test_pg_dump/expected/test_pg_dump.out

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,10 @@ ALTER EXTENSION test_pg_dump DROP SERVER s0;
9393
ALTER EXTENSION test_pg_dump DROP TABLE test_pg_dump_t1;
9494
ALTER EXTENSION test_pg_dump DROP TYPE test_pg_dump_e1;
9595
ALTER EXTENSION test_pg_dump DROP VIEW test_pg_dump_v1;
96+
DROP EXTENSION test_pg_dump;
97+
-- shouldn't be anything left in pg_init_privs
98+
SELECT * FROM pg_init_privs WHERE privtype = 'e';
99+
objoid | classoid | objsubid | privtype | initprivs
100+
--------+----------+----------+----------+-----------
101+
(0 rows)
102+

src/test/modules/test_pg_dump/sql/test_pg_dump.sql

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,3 +106,8 @@ ALTER EXTENSION test_pg_dump DROP SERVER s0;
106106
ALTER EXTENSION test_pg_dump DROP TABLE test_pg_dump_t1;
107107
ALTER EXTENSION test_pg_dump DROP TYPE test_pg_dump_e1;
108108
ALTER EXTENSION test_pg_dump DROP VIEW test_pg_dump_v1;
109+
110+
DROP EXTENSION test_pg_dump;
111+
112+
-- shouldn't be anything left in pg_init_privs
113+
SELECT * FROM pg_init_privs WHERE privtype = 'e';

0 commit comments

Comments
 (0)