Skip to content

Commit 57e978a

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 8ac0eb5 commit 57e978a

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
@@ -1153,6 +1153,7 @@ GetDefaultTablespace(char relpersistence)
11531153

11541154
typedef struct
11551155
{
1156+
/* Array of OIDs to be passed to SetTempTablespaces() */
11561157
int numSpcs;
11571158
Oid tblSpcs[FLEXIBLE_ARRAY_MEMBER];
11581159
} temp_tablespaces_extra;
@@ -1202,6 +1203,7 @@ check_temp_tablespaces(char **newval, void **extra, GucSource source)
12021203
/* Allow an empty string (signifying database default) */
12031204
if (curname[0] == '\0')
12041205
{
1206+
/* InvalidOid signifies database's default tablespace */
12051207
tblSpcs[numSpcs++] = InvalidOid;
12061208
continue;
12071209
}
@@ -1228,6 +1230,7 @@ check_temp_tablespaces(char **newval, void **extra, GucSource source)
12281230
*/
12291231
if (curoid == MyDatabaseTableSpace)
12301232
{
1233+
/* InvalidOid signifies database's default tablespace */
12311234
tblSpcs[numSpcs++] = InvalidOid;
12321235
continue;
12331236
}
@@ -1338,6 +1341,7 @@ PrepareTempTablespaces(void)
13381341
/* Allow an empty string (signifying database default) */
13391342
if (curname[0] == '\0')
13401343
{
1344+
/* InvalidOid signifies database's default tablespace */
13411345
tblSpcs[numSpcs++] = InvalidOid;
13421346
continue;
13431347
}
@@ -1356,7 +1360,8 @@ PrepareTempTablespaces(void)
13561360
*/
13571361
if (curoid == MyDatabaseTableSpace)
13581362
{
1359-
tblSpcs[numSpcs++] = curoid;
1363+
/* InvalidOid signifies database's default tablespace */
1364+
tblSpcs[numSpcs++] = InvalidOid;
13601365
continue;
13611366
}
13621367

src/backend/storage/file/fd.c

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

248248
/*
249-
* Array of OIDs of temp tablespaces. When numTempTableSpaces is -1,
250-
* this has not been set in the current transaction.
249+
* Array of OIDs of temp tablespaces. (Some entries may be InvalidOid,
250+
* indicating that the current database's default tablespace should be used.)
251+
* When numTempTableSpaces is -1, this has not been set in the current
252+
* transaction.
251253
*/
252254
static Oid *tempTableSpaces = NULL;
253255
static int numTempTableSpaces = -1;
@@ -2301,6 +2303,9 @@ closeAllVfds(void)
23012303
* unless this function is called again before then. It is caller's
23022304
* responsibility that the passed-in array has adequate lifespan (typically
23032305
* it'd be allocated in TopTransactionContext).
2306+
*
2307+
* Some entries of the array may be InvalidOid, indicating that the current
2308+
* database's default tablespace should be used.
23042309
*/
23052310
void
23062311
SetTempTablespaces(Oid *tableSpaces, int numSpaces)

0 commit comments

Comments
 (0)