Duplicate usage of tablespace location? - Mailing list pgsql-hackers

From Kyotaro HORIGUCHI
Subject Duplicate usage of tablespace location?
Date
Msg-id 20170406.160844.120459562.horiguchi.kyotaro@lab.ntt.co.jp
Whole thread Raw
List pgsql-hackers
Hello,

I noticed by the following report, PostgreSQL can share the same
directory as tablespaces of two servers with different
pg-versions.

https://www.postgresql.org/message-id/2008148.rxBNyNRHPZ@peanuts2

8.4 checked that the tablespace location is empty, but from 9.0,
the check is replaced with creating a PG_PGVER_CATVER
subdirectory. This works for multiple servers with the same
version, but don't for servers with different versions.

This is apparently a bug but doesn't cause any other problem
immediately. If we choose not to do this, the documentaion needs
to be edited instead.

https://www.postgresql.org/docs/9.6/static/manage-ag-tablespaces.html

| The location must be an existing, empty directory that is owned
| by the PostgreSQL operating system user.

regards,

- 
Kyotaro Horiguchi
NTT Open Source Software Center
diff --git a/src/backend/commands/tablespace.c b/src/backend/commands/tablespace.c
index f9c2620..6a89be1 100644
--- a/src/backend/commands/tablespace.c
+++ b/src/backend/commands/tablespace.c
@@ -606,23 +606,21 @@ create_tablespace_directories(const char *location, const Oid tablespaceoid)        }    }
+        /*
-     * The creation of the version directory prevents more than one tablespace
-     * in a single location.
+     * Check the target directory is empty.     */
+    if (!directory_is_empty(location))
+        ereport(ERROR,
+                (errcode(ERRCODE_OBJECT_IN_USE),
+                 errmsg("directory \"%s\" is not empty",
+                        location)));
+    if (mkdir(location_with_version_dir, S_IRWXU) < 0)
-    {
-        if (errno == EEXIST)
-            ereport(ERROR,
-                    (errcode(ERRCODE_OBJECT_IN_USE),
-                     errmsg("directory \"%s\" already in use as a tablespace",
-                            location_with_version_dir)));
-        else
-            ereport(ERROR,
-                    (errcode_for_file_access(),
-                     errmsg("could not create directory \"%s\": %m",
-                            location_with_version_dir)));
-    }
+        ereport(ERROR,
+                (errcode_for_file_access(),
+                 errmsg("could not create directory \"%s\": %m",
+                        location_with_version_dir)));    /*     * In recovery, remove old symlink, in case it points
tothe wrong place. 

pgsql-hackers by date:

Previous
From: Petr Jelinek
Date:
Subject: Re: PoC plpgsql - possibility to force custom or genericplan
Next
From: Amit Langote
Date:
Subject: Re: Declarative partitioning vs. information_schema