]> granicus.if.org Git - postgresql/commitdiff
Don't allow CREATE TABLE AS to put relations in pg_global.
authorRobert Haas <rhaas@postgresql.org>
Wed, 21 Mar 2012 16:38:34 +0000 (12:38 -0400)
committerRobert Haas <rhaas@postgresql.org>
Wed, 21 Mar 2012 16:39:48 +0000 (12:39 -0400)
This was never intended to be allowed, and is blocked for an ordinary
CREATE TABLE, but CREATE TABLE AS slipped through the cracks.  This
commit won't do anything to fix existing cases where this has loophole
has been exploited, but it still seems prudent to lock it down going
forward.

Back-branch commit only, as this problem has been refactored away
on the master branch.

Andres Freund

src/backend/executor/execMain.c

index 621ad8ac940717a04275711ac4a4ebe1aba401ec..8a43db7d6ab139911cdff78bbe0e9ab520d03886 100644 (file)
@@ -43,6 +43,7 @@
 #include "access/xact.h"
 #include "catalog/heap.h"
 #include "catalog/namespace.h"
+#include "catalog/pg_tablespace.h"
 #include "catalog/toasting.h"
 #include "commands/tablespace.h"
 #include "commands/trigger.h"
@@ -2452,6 +2453,12 @@ OpenIntoRel(QueryDesc *queryDesc)
                                                   get_tablespace_name(tablespaceId));
        }
 
+       /* In all cases disallow placing user relations in pg_global */
+       if (tablespaceId == GLOBALTABLESPACE_OID)
+               ereport(ERROR,
+                       (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
+                        errmsg("only shared relations can be placed in pg_global tablespace")));
+
        /* Parse and validate any reloptions */
        reloptions = transformRelOptions((Datum) 0,
                                                                         into->options,