Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit79ed1d9

Browse files
committed
Fix temporary tablespaces for shared filesets some more.
Commitecd9e9f fixed the problem in the wrong place, causing unwantedside-effects on the behavior of GetNextTempTableSpace(). Instead,let's make SharedFileSetInit() responsible for subbing in the valueof MyDatabaseTableSpace when the default tablespace is called for.The convention about what is in the tempTableSpaces[] array isevidently insufficiently documented, so try to improve that.It also looks like SharedFileSetInit() is doing the wrong thing in thecase where temp_tablespaces is empty. It was hard-wiring use of thepg_default tablespace, but it seems like using MyDatabaseTableSpaceis more consistent with what happens for other temp files.Back-patch the reversion of PrepareTempTablespaces()'s behavior to9.5, asecd9e9f was. The changes in SharedFileSetInit() go backto v11 where that was introduced. (Note there is net zero code changebefore v11 from these two patch sets, so nothing to release-note.)Magnus Hagander and Tom LaneDiscussion:https://postgr.es/m/CABUevExg5YEsOvqMxrjoNvb3ApVyH+9jggWGKwTDFyFCVWczGQ@mail.gmail.com
1 parent4aa02d0 commit79ed1d9

File tree

3 files changed

+34
-5
lines changed

3 files changed

+34
-5
lines changed

‎src/backend/commands/tablespace.c‎

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

11521152
typedefstruct
11531153
{
1154+
/* Array of OIDs to be passed to SetTempTablespaces() */
11541155
intnumSpcs;
11551156
OidtblSpcs[FLEXIBLE_ARRAY_MEMBER];
11561157
}temp_tablespaces_extra;
@@ -1200,6 +1201,7 @@ check_temp_tablespaces(char **newval, void **extra, GucSource source)
12001201
/* Allow an empty string (signifying database default) */
12011202
if (curname[0]=='\0')
12021203
{
1204+
/* InvalidOid signifies database's default tablespace */
12031205
tblSpcs[numSpcs++]=InvalidOid;
12041206
continue;
12051207
}
@@ -1226,6 +1228,7 @@ check_temp_tablespaces(char **newval, void **extra, GucSource source)
12261228
*/
12271229
if (curoid==MyDatabaseTableSpace)
12281230
{
1231+
/* InvalidOid signifies database's default tablespace */
12291232
tblSpcs[numSpcs++]=InvalidOid;
12301233
continue;
12311234
}
@@ -1336,6 +1339,7 @@ PrepareTempTablespaces(void)
13361339
/* Allow an empty string (signifying database default) */
13371340
if (curname[0]=='\0')
13381341
{
1342+
/* InvalidOid signifies database's default tablespace */
13391343
tblSpcs[numSpcs++]=InvalidOid;
13401344
continue;
13411345
}
@@ -1354,7 +1358,8 @@ PrepareTempTablespaces(void)
13541358
*/
13551359
if (curoid==MyDatabaseTableSpace)
13561360
{
1357-
tblSpcs[numSpcs++]=curoid;
1361+
/* InvalidOid signifies database's default tablespace */
1362+
tblSpcs[numSpcs++]=InvalidOid;
13581363
continue;
13591364
}
13601365

‎src/backend/storage/file/fd.c‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -261,8 +261,10 @@ static AllocateDesc *allocatedDescs = NULL;
261261
staticlongtempFileCounter=0;
262262

263263
/*
264-
* Array of OIDs of temp tablespaces. When numTempTableSpaces is -1,
265-
* this has not been set in the current transaction.
264+
* Array of OIDs of temp tablespaces. (Some entries may be InvalidOid,
265+
* indicating that the current database's default tablespace should be used.)
266+
* When numTempTableSpaces is -1, this has not been set in the current
267+
* transaction.
266268
*/
267269
staticOid*tempTableSpaces=NULL;
268270
staticintnumTempTableSpaces=-1;
@@ -2822,6 +2824,9 @@ closeAllVfds(void)
28222824
* unless this function is called again before then. It is caller's
28232825
* responsibility that the passed-in array has adequate lifespan (typically
28242826
* it'd be allocated in TopTransactionContext).
2827+
*
2828+
* Some entries of the array may be InvalidOid, indicating that the current
2829+
* database's default tablespace should be used.
28252830
*/
28262831
void
28272832
SetTempTablespaces(Oid*tableSpaces,intnumSpaces)
@@ -2861,7 +2866,10 @@ TempTablespacesAreSet(void)
28612866
* GetTempTablespaces
28622867
*
28632868
* Populate an array with the OIDs of the tablespaces that should be used for
2864-
* temporary files. Return the number that were copied into the output array.
2869+
* temporary files. (Some entries may be InvalidOid, indicating that the
2870+
* current database's default tablespace should be used.) At most numSpaces
2871+
* entries will be filled.
2872+
* Returns the number of OIDs that were copied into the output array.
28652873
*/
28662874
int
28672875
GetTempTablespaces(Oid*tableSpaces,intnumSpaces)

‎src/backend/storage/file/sharedfileset.c‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,25 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg)
6161
lengthof(fileset->tablespaces));
6262
if (fileset->ntablespaces==0)
6363
{
64-
fileset->tablespaces[0]=DEFAULTTABLESPACE_OID;
64+
/* If the GUC is empty, use current database's default tablespace */
65+
fileset->tablespaces[0]=MyDatabaseTableSpace;
6566
fileset->ntablespaces=1;
6667
}
68+
else
69+
{
70+
inti;
71+
72+
/*
73+
* An entry of InvalidOid means use the default tablespace for the
74+
* current database. Replace that now, to be sure that all users of
75+
* the SharedFileSet agree on what to do.
76+
*/
77+
for (i=0;i<fileset->ntablespaces;i++)
78+
{
79+
if (fileset->tablespaces[i]==InvalidOid)
80+
fileset->tablespaces[i]=MyDatabaseTableSpace;
81+
}
82+
}
6783

6884
/* Register our cleanup callback. */
6985
on_dsm_detach(seg,SharedFileSetOnDetach,PointerGetDatum(fileset));

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp