Fix temporary tablespaces for shared filesets some more.
authorTom Lane <[email protected]>
Fri, 3 Jul 2020 21:01:34 +0000 (17:01 -0400)
committerTom Lane <[email protected]>
Fri, 3 Jul 2020 21:01:34 +0000 (17:01 -0400)
Commit ecd9e9f0b fixed the problem in the wrong place, causing unwanted
side-effects on the behavior of GetNextTempTableSpace().  Instead,
let's make SharedFileSetInit() responsible for subbing in the value
of MyDatabaseTableSpace when the default tablespace is called for.

The convention about what is in the tempTableSpaces[] array is
evidently insufficiently documented, so try to improve that.

It also looks like SharedFileSetInit() is doing the wrong thing in the
case where temp_tablespaces is empty.  It was hard-wiring use of the
pg_default tablespace, but it seems like using MyDatabaseTableSpace
is more consistent with what happens for other temp files.

Back-patch the reversion of PrepareTempTablespaces()'s behavior to
9.5, as ecd9e9f0b was.  The changes in SharedFileSetInit() go back
to v11 where that was introduced.  (Note there is net zero code change
before v11 from these two patch sets, so nothing to release-note.)

Magnus Hagander and Tom Lane

Discussion: https://postgr.es/m/CABUevExg5YEsOvqMxrjoNvb3ApVyH+9jggWGKwTDFyFCVWczGQ@mail.gmail.com

src/backend/commands/tablespace.c
src/backend/storage/file/fd.c

index 0dd8e311edd21317f74921074190c2ccca2b2b9a..4a5d22da7591deffc33d05ac3c2d4dc93dc21996 100644 (file)
@@ -1149,6 +1149,7 @@ GetDefaultTablespace(char relpersistence)
 
 typedef struct
 {
+   /* Array of OIDs to be passed to SetTempTablespaces() */
    int         numSpcs;
    Oid         tblSpcs[FLEXIBLE_ARRAY_MEMBER];
 } temp_tablespaces_extra;
@@ -1198,6 +1199,7 @@ check_temp_tablespaces(char **newval, void **extra, GucSource source)
            /* Allow an empty string (signifying database default) */
            if (curname[0] == '\0')
            {
+               /* InvalidOid signifies database's default tablespace */
                tblSpcs[numSpcs++] = InvalidOid;
                continue;
            }
@@ -1224,6 +1226,7 @@ check_temp_tablespaces(char **newval, void **extra, GucSource source)
             */
            if (curoid == MyDatabaseTableSpace)
            {
+               /* InvalidOid signifies database's default tablespace */
                tblSpcs[numSpcs++] = InvalidOid;
                continue;
            }
@@ -1334,6 +1337,7 @@ PrepareTempTablespaces(void)
        /* Allow an empty string (signifying database default) */
        if (curname[0] == '\0')
        {
+           /* InvalidOid signifies database's default tablespace */
            tblSpcs[numSpcs++] = InvalidOid;
            continue;
        }
@@ -1352,7 +1356,8 @@ PrepareTempTablespaces(void)
         */
        if (curoid == MyDatabaseTableSpace)
        {
-           tblSpcs[numSpcs++] = curoid;
+           /* InvalidOid signifies database's default tablespace */
+           tblSpcs[numSpcs++] = InvalidOid;
            continue;
        }
 
index 19d4e20415135e70f9900a76e88a7be4b07e891c..9004fe43cdedcd022277c28125f9dfb4d1fc476b 100644 (file)
@@ -253,8 +253,10 @@ static AllocateDesc *allocatedDescs = NULL;
 static long tempFileCounter = 0;
 
 /*
- * Array of OIDs of temp tablespaces.  When numTempTableSpaces is -1,
- * this has not been set in the current transaction.
+ * Array of OIDs of temp tablespaces.  (Some entries may be InvalidOid,
+ * indicating that the current database's default tablespace should be used.)
+ * When numTempTableSpaces is -1, this has not been set in the current
+ * transaction.
  */
 static Oid *tempTableSpaces = NULL;
 static int numTempTableSpaces = -1;
@@ -2576,6 +2578,9 @@ closeAllVfds(void)
  * unless this function is called again before then.  It is caller's
  * responsibility that the passed-in array has adequate lifespan (typically
  * it'd be allocated in TopTransactionContext).
+ *
+ * Some entries of the array may be InvalidOid, indicating that the current
+ * database's default tablespace should be used.
  */
 void
 SetTempTablespaces(Oid *tableSpaces, int numSpaces)