2 -- Tests for things affected by allow_system_table_mods
4 -- We run the same set of commands once with allow_system_table_mods
5 -- off and then again with on.
7 -- The "on" tests should where possible be wrapped in BEGIN/ROLLBACK
8 -- blocks so as to not leave a mess around.
9 CREATE USER regress_user_ast;
10 SET allow_system_table_mods = off;
11 -- create new table in pg_catalog
12 CREATE TABLE pg_catalog.test (a int);
13 ERROR: permission denied to create "pg_catalog.test"
14 DETAIL: System catalog modifications are currently disallowed.
16 CREATE TABLE t1x (a int, b anyarray);
17 ERROR: column "b" has pseudo-type anyarray
18 -- index on system catalog
19 ALTER TABLE pg_namespace ADD CONSTRAINT foo UNIQUE USING INDEX pg_namespace_nspname_index;
20 ERROR: permission denied: "pg_namespace" is a system catalog
21 -- write to system catalog table as superuser
22 -- (allowed even without allow_system_table_mods)
23 INSERT INTO pg_description (objoid, classoid, objsubid, description) VALUES (0, 0, 0, 'foo');
24 -- write to system catalog table as normal user
25 GRANT INSERT ON pg_description TO regress_user_ast;
26 SET ROLE regress_user_ast;
27 INSERT INTO pg_description (objoid, classoid, objsubid, description) VALUES (0, 0, 1, 'foo');
28 ERROR: permission denied for table pg_description
30 -- policy on system catalog
31 CREATE POLICY foo ON pg_description FOR SELECT USING (description NOT LIKE 'secret%');
32 ERROR: permission denied: "pg_description" is a system catalog
33 -- reserved schema name
35 ERROR: unacceptable schema name "pg_foo"
36 DETAIL: The prefix "pg_" is reserved for system schemas.
38 DROP TABLE pg_description;
39 ERROR: permission denied: "pg_description" is a system catalog
40 -- truncate of system table
41 TRUNCATE pg_description;
42 ERROR: permission denied: "pg_description" is a system catalog
43 -- rename column of system table
44 ALTER TABLE pg_description RENAME COLUMN description TO comment;
45 ERROR: permission denied: "pg_description" is a system catalog
46 -- ATSimplePermissions()
47 ALTER TABLE pg_description ALTER COLUMN description SET NOT NULL;
48 ERROR: permission denied: "pg_description" is a system catalog
50 ALTER TABLE pg_description ALTER COLUMN description SET STATISTICS -1;
51 ERROR: permission denied: "pg_description" is a system catalog
52 -- foreign key referencing catalog
53 CREATE TABLE foo (a oid, b oid, c int, FOREIGN KEY (a, b, c) REFERENCES pg_description);
54 ERROR: permission denied: "pg_description" is a system catalog
55 -- RangeVarCallbackOwnsRelation()
56 CREATE INDEX pg_description_test_index ON pg_description (description);
57 ERROR: permission denied: "pg_description" is a system catalog
58 -- RangeVarCallbackForAlterRelation()
59 ALTER TABLE pg_description RENAME TO pg_comment;
60 ERROR: permission denied: "pg_description" is a system catalog
61 ALTER TABLE pg_description SET SCHEMA public;
62 ERROR: permission denied: "pg_description" is a system catalog
63 -- reserved tablespace name
64 CREATE TABLESPACE pg_foo LOCATION '/no/such/location';
65 ERROR: unacceptable tablespace name "pg_foo"
66 DETAIL: The prefix "pg_" is reserved for system tablespaces.
68 CREATE FUNCTION tf1() RETURNS trigger
74 CREATE TRIGGER t1 BEFORE INSERT ON pg_description EXECUTE FUNCTION tf1();
75 ERROR: permission denied: "pg_description" is a system catalog
76 ALTER TRIGGER t1 ON pg_description RENAME TO t2;
77 ERROR: permission denied: "pg_description" is a system catalog
78 --DROP TRIGGER t2 ON pg_description;
80 CREATE RULE r1 AS ON INSERT TO pg_description DO INSTEAD NOTHING;
81 ERROR: permission denied: "pg_description" is a system catalog
82 ALTER RULE r1 ON pg_description RENAME TO r2;
83 ERROR: permission denied: "pg_description" is a system catalog
84 -- now make one to test dropping:
85 SET allow_system_table_mods TO on;
86 CREATE RULE r2 AS ON INSERT TO pg_description DO INSTEAD NOTHING;
87 RESET allow_system_table_mods;
88 DROP RULE r2 ON pg_description;
89 ERROR: permission denied: "pg_description" is a system catalog
91 SET allow_system_table_mods TO on;
92 DROP RULE r2 ON pg_description;
93 RESET allow_system_table_mods;
94 SET allow_system_table_mods = on;
95 -- create new table in pg_catalog
97 CREATE TABLE pg_catalog.test (a int);
101 CREATE TABLE t1 (a int, b anyarray);
103 -- index on system catalog
105 ALTER TABLE pg_namespace ADD CONSTRAINT foo UNIQUE USING INDEX pg_namespace_nspname_index;
106 NOTICE: ALTER TABLE / ADD CONSTRAINT USING INDEX will rename index "pg_namespace_nspname_index" to "foo"
108 -- write to system catalog table as superuser
110 INSERT INTO pg_description (objoid, classoid, objsubid, description) VALUES (0, 0, 2, 'foo');
112 -- write to system catalog table as normal user
114 SET ROLE regress_user_ast;
115 INSERT INTO pg_description (objoid, classoid, objsubid, description) VALUES (0, 0, 3, 'foo');
116 ERROR: permission denied for table pg_description
118 -- policy on system catalog
120 CREATE POLICY foo ON pg_description FOR SELECT USING (description NOT LIKE 'secret%');
122 -- reserved schema name
124 CREATE SCHEMA pg_foo;
127 -- (This will fail anyway because it's pinned.)
129 DROP TABLE pg_description;
130 ERROR: cannot drop table pg_description because it is required by the database system
132 -- truncate of system table
134 TRUNCATE pg_description;
136 -- rename column of system table
138 ALTER TABLE pg_description RENAME COLUMN description TO comment;
140 -- ATSimplePermissions()
142 ALTER TABLE pg_description ALTER COLUMN description SET NOT NULL;
146 ALTER TABLE pg_description ALTER COLUMN description SET STATISTICS -1;
148 -- foreign key referencing catalog
150 CREATE TABLE foo (a oid, b oid, c int, FOREIGN KEY (a, b, c) REFERENCES pg_description);
152 -- RangeVarCallbackOwnsRelation()
154 CREATE INDEX pg_description_test_index ON pg_description (description);
156 -- RangeVarCallbackForAlterRelation()
158 ALTER TABLE pg_description RENAME TO pg_comment;
161 ALTER TABLE pg_description SET SCHEMA public;
163 -- reserved tablespace name
164 SET client_min_messages = error; -- disable ENFORCE_REGRESSION_TEST_NAME_RESTRICTIONS warning
165 CREATE TABLESPACE pg_foo LOCATION '/no/such/location';
166 ERROR: directory "/no/such/location" does not exist
167 RESET client_min_messages;
169 CREATE TRIGGER t1 BEFORE INSERT ON pg_description EXECUTE FUNCTION tf1();
170 ALTER TRIGGER t1 ON pg_description RENAME TO t2;
171 DROP TRIGGER t2 ON pg_description;
173 CREATE RULE r1 AS ON INSERT TO pg_description DO INSTEAD NOTHING;
174 ALTER RULE r1 ON pg_description RENAME TO r2;
175 DROP RULE r2 ON pg_description;
177 REVOKE ALL ON pg_description FROM regress_user_ast;
178 DROP USER regress_user_ast;