Warn about tablespace creation in PGDATA
authorBruce Momjian <bruce@momjian.us>
Tue, 28 Apr 2015 21:35:12 +0000 (17:35 -0400)
committerBruce Momjian <bruce@momjian.us>
Tue, 28 Apr 2015 21:35:12 +0000 (17:35 -0400)
Also add warning to pg_upgrade

Report by Josh Berkus

src/backend/commands/tablespace.c
src/bin/pg_upgrade/check.c

index fd226125a93838a74dad709565e6e7ce6bce6bf1..4ec1affbfb16f81f004156c8e413f58d32cdb9fb 100644 (file)
@@ -288,6 +288,12 @@ CreateTableSpace(CreateTableSpaceStmt *stmt)
                                 errmsg("tablespace location \"%s\" is too long",
                                                location)));
 
+       /* Warn if the tablespace is in the data directory. */
+       if (path_is_prefix_of_path(DataDir, location))
+               ereport(WARNING,
+                               (errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
+                                errmsg("tablespace location should not be inside the data directory")));
+
        /*
         * Disallow creation of tablespaces named "pg_xxx"; we reserve this
         * namespace for system purposes.
index 647bf349f4d9f776cb052383ddfca5936e86b4cc..6db223ab070d19eddd74e1bc5b5f5509041bc01e 100644 (file)
@@ -508,6 +508,10 @@ create_script_for_old_cluster_deletion(char **deletion_script_file_name)
                canonicalize_path(old_tablespace_dir);
                if (path_is_prefix_of_path(old_cluster_pgdata, old_tablespace_dir))
                {
+                       /* reproduce warning from CREATE TABLESPACE that is in the log */
+                       pg_log(PG_WARNING,
+                               "\nWARNING:  user-defined tablespace locations should not be inside the data directory, e.g. %s\n", old_tablespace_dir);
+
                        /* Unlink file in case it is left over from a previous run. */
                        unlink(*deletion_script_file_name);
                        pg_free(*deletion_script_file_name);