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

Commit 1538628

Browse files
committed
Put back allow_system_table_mods check in heap_create().
This reverts commit a475c60. Erik Rijkers reported back in January 2013 that after the patch, if you do "pg_dump -t myschema.mytable" to dump a single table, and restore that in a database where myschema does not exist, the table is silently created in pg_catalog instead. That is because pg_dump uses "SET search_path=myschema, pg_catalog" to set schema the table is created in. While allow_system_table_mods is not a very elegant solution to this, we can't leave it as it is, so for now, revert it back to the way it was previously.
1 parent f129615 commit 1538628

File tree

4 files changed

+22
-5
lines changed

4 files changed

+22
-5
lines changed

src/backend/bootstrap/bootparse.y

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,8 @@ Boot_CreateStmt:
222222
RELKIND_RELATION,
223223
RELPERSISTENCE_PERMANENT,
224224
shared_relation,
225-
mapped_relation);
225+
mapped_relation,
226+
true);
226227
elog(DEBUG4, "bootstrap relation created");
227228
}
228229
else

src/backend/catalog/heap.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,14 +246,27 @@ heap_create(const char *relname,
246246
char relkind,
247247
char relpersistence,
248248
bool shared_relation,
249-
bool mapped_relation)
249+
bool mapped_relation,
250+
bool allow_system_table_mods)
250251
{
251252
bool create_storage;
252253
Relation rel;
253254

254255
/* The caller must have provided an OID for the relation. */
255256
Assert(OidIsValid(relid));
256257

258+
/*
259+
* sanity checks
260+
*/
261+
if (!allow_system_table_mods &&
262+
(IsSystemNamespace(relnamespace) || IsToastNamespace(relnamespace)) &&
263+
IsNormalProcessingMode())
264+
ereport(ERROR,
265+
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
266+
errmsg("permission denied to create \"%s.%s\"",
267+
get_namespace_name(relnamespace), relname),
268+
errdetail("System catalog modifications are currently disallowed.")));
269+
257270
/*
258271
* Decide if we need storage or not, and handle a couple other special
259272
* cases for particular relkinds.
@@ -1132,7 +1145,8 @@ heap_create_with_catalog(const char *relname,
11321145
relkind,
11331146
relpersistence,
11341147
shared_relation,
1135-
mapped_relation);
1148+
mapped_relation,
1149+
allow_system_table_mods);
11361150

11371151
Assert(relid == RelationGetRelid(new_rel_desc));
11381152

src/backend/catalog/index.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -825,7 +825,8 @@ index_create(Relation heapRelation,
825825
RELKIND_INDEX,
826826
relpersistence,
827827
shared_relation,
828-
mapped_relation);
828+
mapped_relation,
829+
allow_system_table_mods);
829830

830831
Assert(indexRelationId == RelationGetRelid(indexRelation));
831832

src/include/catalog/heap.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ extern Relation heap_create(const char *relname,
4646
char relkind,
4747
char relpersistence,
4848
bool shared_relation,
49-
bool mapped_relation);
49+
bool mapped_relation,
50+
bool allow_system_table_mods);
5051

5152
extern Oid heap_create_with_catalog(const char *relname,
5253
Oid relnamespace,

0 commit comments

Comments
 (0)