aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/backend/commands/tablespace.c7
-rw-r--r--src/backend/storage/file/fd.c14
-rw-r--r--src/backend/storage/file/sharedfileset.c18
3 files changed, 34 insertions, 5 deletions
diff --git a/src/backend/commands/tablespace.c b/src/backend/commands/tablespace.c
index 3105efe0403..e4cd961e3ba 100644
--- a/src/backend/commands/tablespace.c
+++ b/src/backend/commands/tablespace.c
@@ -1151,6 +1151,7 @@ GetDefaultTablespace(char relpersistence)
typedef struct
{
+ /* Array of OIDs to be passed to SetTempTablespaces() */
int numSpcs;
Oid tblSpcs[FLEXIBLE_ARRAY_MEMBER];
} temp_tablespaces_extra;
@@ -1200,6 +1201,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;
}
@@ -1226,6 +1228,7 @@ check_temp_tablespaces(char **newval, void **extra, GucSource source)
*/
if (curoid == MyDatabaseTableSpace)
{
+ /* InvalidOid signifies database's default tablespace */
tblSpcs[numSpcs++] = InvalidOid;
continue;
}
@@ -1336,6 +1339,7 @@ PrepareTempTablespaces(void)
/* Allow an empty string (signifying database default) */
if (curname[0] == '\0')
{
+ /* InvalidOid signifies database's default tablespace */
tblSpcs[numSpcs++] = InvalidOid;
continue;
}
@@ -1354,7 +1358,8 @@ PrepareTempTablespaces(void)
*/
if (curoid == MyDatabaseTableSpace)
{
- tblSpcs[numSpcs++] = curoid;
+ /* InvalidOid signifies database's default tablespace */
+ tblSpcs[numSpcs++] = InvalidOid;
continue;
}
diff --git a/src/backend/storage/file/fd.c b/src/backend/storage/file/fd.c
index 8d2b8aacfeb..d31a6b87b85 100644
--- a/src/backend/storage/file/fd.c
+++ b/src/backend/storage/file/fd.c
@@ -261,8 +261,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;
@@ -2822,6 +2824,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)
@@ -2861,7 +2866,10 @@ TempTablespacesAreSet(void)
* GetTempTablespaces
*
* Populate an array with the OIDs of the tablespaces that should be used for
- * temporary files. Return the number that were copied into the output array.
+ * temporary files. (Some entries may be InvalidOid, indicating that the
+ * current database's default tablespace should be used.) At most numSpaces
+ * entries will be filled.
+ * Returns the number of OIDs that were copied into the output array.
*/
int
GetTempTablespaces(Oid *tableSpaces, int numSpaces)
diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c
index d41b39a1771..aa634acb26e 100644
--- a/src/backend/storage/file/sharedfileset.c
+++ b/src/backend/storage/file/sharedfileset.c
@@ -61,9 +61,25 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg)
lengthof(fileset->tablespaces));
if (fileset->ntablespaces == 0)
{
- fileset->tablespaces[0] = DEFAULTTABLESPACE_OID;
+ /* If the GUC is empty, use current database's default tablespace */
+ fileset->tablespaces[0] = MyDatabaseTableSpace;
fileset->ntablespaces = 1;
}
+ else
+ {
+ int i;
+
+ /*
+ * An entry of InvalidOid means use the default tablespace for the
+ * current database. Replace that now, to be sure that all users of
+ * the SharedFileSet agree on what to do.
+ */
+ for (i = 0; i < fileset->ntablespaces; i++)
+ {
+ if (fileset->tablespaces[i] == InvalidOid)
+ fileset->tablespaces[i] = MyDatabaseTableSpace;
+ }
+ }
/* Register our cleanup callback. */
on_dsm_detach(seg, SharedFileSetOnDetach, PointerGetDatum(fileset));