Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 93f03da

Browse files
committed
Make BufFileCreateTemp() ensure that temp tablespaces are set up.
If PrepareTempTablespaces() has never been called in the current transaction, OpenTemporaryFile() will fall back to using the default tablespace, which is a bug if the user wanted temp files placed elsewhere. gistInitBuildBuffers() appears to have this disease already, and it seems like an easy trap for future coders to fall into. We discussed other ways to close this gap, but none of them are prettier or more reliable than just having BufFileCreateTemp do it. In particular, having fd.c do this creates layering issues that we could do without. Per suggestion from Melanie Plageman. Arguably this is a bug fix, but nobody seems very excited about back-patching, so change in HEAD only. Discussion: https://postgr.es/m/CAAKRu_YwzjuGAmmaw4-8XO=OVFGR1QhY_Pq-t3wjb9ribBJb_Q@mail.gmail.com
1 parent b12db9f commit 93f03da

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/backend/storage/file/buffile.c

+12
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141

4242
#include "postgres.h"
4343

44+
#include "commands/tablespace.h"
4445
#include "executor/instrument.h"
4546
#include "miscadmin.h"
4647
#include "pgstat.h"
@@ -185,6 +186,17 @@ BufFileCreateTemp(bool interXact)
185186
BufFile *file;
186187
File pfile;
187188

189+
/*
190+
* Ensure that temp tablespaces are set up for OpenTemporaryFile to use.
191+
* Possibly the caller will have done this already, but it seems useful to
192+
* double-check here. Failure to do this at all would result in the temp
193+
* files always getting placed in the default tablespace, which is a
194+
* pretty hard-to-detect bug. Callers may prefer to do it earlier if they
195+
* want to be sure that any required catalog access is done in some other
196+
* resource context.
197+
*/
198+
PrepareTempTablespaces();
199+
188200
pfile = OpenTemporaryFile(interXact);
189201
Assert(pfile >= 0);
190202

0 commit comments

Comments
 (0)