Skip to content

Commit a7d3f3b

Browse files
committed
Fix temporary tablespaces for shared filesets some more.
Commit ecd9e9f 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 ecd9e9f 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
1 parent 4a1d215 commit a7d3f3b

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

src/backend/commands/tablespace.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1149,6 +1149,7 @@ GetDefaultTablespace(char relpersistence)
11491149

11501150
typedef struct
11511151
{
1152+
/* Array of OIDs to be passed to SetTempTablespaces() */
11521153
int numSpcs;
11531154
Oid tblSpcs[FLEXIBLE_ARRAY_MEMBER];
11541155
} temp_tablespaces_extra;
@@ -1198,6 +1199,7 @@ check_temp_tablespaces(char **newval, void **extra, GucSource source)
11981199
/* Allow an empty string (signifying database default) */
11991200
if (curname[0] == '\0')
12001201
{
1202+
/* InvalidOid signifies database's default tablespace */
12011203
tblSpcs[numSpcs++] = InvalidOid;
12021204
continue;
12031205
}
@@ -1224,6 +1226,7 @@ check_temp_tablespaces(char **newval, void **extra, GucSource source)
12241226
*/
12251227
if (curoid == MyDatabaseTableSpace)
12261228
{
1229+
/* InvalidOid signifies database's default tablespace */
12271230
tblSpcs[numSpcs++] = InvalidOid;
12281231
continue;
12291232
}
@@ -1334,6 +1337,7 @@ PrepareTempTablespaces(void)
13341337
/* Allow an empty string (signifying database default) */
13351338
if (curname[0] == '\0')
13361339
{
1340+
/* InvalidOid signifies database's default tablespace */
13371341
tblSpcs[numSpcs++] = InvalidOid;
13381342
continue;
13391343
}
@@ -1352,7 +1356,8 @@ PrepareTempTablespaces(void)
13521356
*/
13531357
if (curoid == MyDatabaseTableSpace)
13541358
{
1355-
tblSpcs[numSpcs++] = curoid;
1359+
/* InvalidOid signifies database's default tablespace */
1360+
tblSpcs[numSpcs++] = InvalidOid;
13561361
continue;
13571362
}
13581363

src/backend/storage/file/fd.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,8 +253,10 @@ static AllocateDesc *allocatedDescs = NULL;
253253
static long tempFileCounter = 0;
254254

255255
/*
256-
* Array of OIDs of temp tablespaces. When numTempTableSpaces is -1,
257-
* this has not been set in the current transaction.
256+
* Array of OIDs of temp tablespaces. (Some entries may be InvalidOid,
257+
* indicating that the current database's default tablespace should be used.)
258+
* When numTempTableSpaces is -1, this has not been set in the current
259+
* transaction.
258260
*/
259261
static Oid *tempTableSpaces = NULL;
260262
static int numTempTableSpaces = -1;
@@ -2576,6 +2578,9 @@ closeAllVfds(void)
25762578
* unless this function is called again before then. It is caller's
25772579
* responsibility that the passed-in array has adequate lifespan (typically
25782580
* it'd be allocated in TopTransactionContext).
2581+
*
2582+
* Some entries of the array may be InvalidOid, indicating that the current
2583+
* database's default tablespace should be used.
25792584
*/
25802585
void
25812586
SetTempTablespaces(Oid *tableSpaces, int numSpaces)

0 commit comments

Comments
 (0)