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

Commitcfe89f5

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 parent1d94c39 commitcfe89f5

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
@@ -1183,6 +1183,7 @@ GetDefaultTablespace(char relpersistence, bool partitioned)
11831183

11841184
typedefstruct
11851185
{
1186+
/* Array of OIDs to be passed to SetTempTablespaces() */
11861187
intnumSpcs;
11871188
OidtblSpcs[FLEXIBLE_ARRAY_MEMBER];
11881189
}temp_tablespaces_extra;
@@ -1232,6 +1233,7 @@ check_temp_tablespaces(char **newval, void **extra, GucSource source)
12321233
/* Allow an empty string (signifying database default) */
12331234
if (curname[0]=='\0')
12341235
{
1236+
/* InvalidOid signifies database's default tablespace */
12351237
tblSpcs[numSpcs++]=InvalidOid;
12361238
continue;
12371239
}
@@ -1258,6 +1260,7 @@ check_temp_tablespaces(char **newval, void **extra, GucSource source)
12581260
*/
12591261
if (curoid==MyDatabaseTableSpace)
12601262
{
1263+
/* InvalidOid signifies database's default tablespace */
12611264
tblSpcs[numSpcs++]=InvalidOid;
12621265
continue;
12631266
}
@@ -1368,6 +1371,7 @@ PrepareTempTablespaces(void)
13681371
/* Allow an empty string (signifying database default) */
13691372
if (curname[0]=='\0')
13701373
{
1374+
/* InvalidOid signifies database's default tablespace */
13711375
tblSpcs[numSpcs++]=InvalidOid;
13721376
continue;
13731377
}
@@ -1386,7 +1390,8 @@ PrepareTempTablespaces(void)
13861390
*/
13871391
if (curoid==MyDatabaseTableSpace)
13881392
{
1389-
tblSpcs[numSpcs++]=curoid;
1393+
/* InvalidOid signifies database's default tablespace */
1394+
tblSpcs[numSpcs++]=InvalidOid;
13901395
continue;
13911396
}
13921397

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -264,8 +264,10 @@ static intnumExternalFDs = 0;
264264
staticlongtempFileCounter=0;
265265

266266
/*
267-
* Array of OIDs of temp tablespaces. When numTempTableSpaces is -1,
268-
* this has not been set in the current transaction.
267+
* Array of OIDs of temp tablespaces. (Some entries may be InvalidOid,
268+
* indicating that the current database's default tablespace should be used.)
269+
* When numTempTableSpaces is -1, this has not been set in the current
270+
* transaction.
269271
*/
270272
staticOid*tempTableSpaces=NULL;
271273
staticintnumTempTableSpaces=-1;
@@ -2779,6 +2781,9 @@ closeAllVfds(void)
27792781
* unless this function is called again before then. It is caller's
27802782
* responsibility that the passed-in array has adequate lifespan (typically
27812783
* it'd be allocated in TopTransactionContext).
2784+
*
2785+
* Some entries of the array may be InvalidOid, indicating that the current
2786+
* database's default tablespace should be used.
27822787
*/
27832788
void
27842789
SetTempTablespaces(Oid*tableSpaces,intnumSpaces)
@@ -2818,7 +2823,10 @@ TempTablespacesAreSet(void)
28182823
* GetTempTablespaces
28192824
*
28202825
* Populate an array with the OIDs of the tablespaces that should be used for
2821-
* temporary files. Return the number that were copied into the output array.
2826+
* temporary files. (Some entries may be InvalidOid, indicating that the
2827+
* current database's default tablespace should be used.) At most numSpaces
2828+
* entries will be filled.
2829+
* Returns the number of OIDs that were copied into the output array.
28222830
*/
28232831
int
28242832
GetTempTablespaces(Oid*tableSpaces,intnumSpaces)

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

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

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

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp