Commit 93f03dad authored by Tom Lane's avatar Tom Lane

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
parent b12db9ff
......@@ -41,6 +41,7 @@
#include "postgres.h"
#include "commands/tablespace.h"
#include "executor/instrument.h"
#include "miscadmin.h"
#include "pgstat.h"
......@@ -185,6 +186,17 @@ BufFileCreateTemp(bool interXact)
BufFile *file;
File pfile;
/*
* Ensure that temp tablespaces are set up for OpenTemporaryFile to use.
* Possibly the caller will have done this already, but it seems useful to
* double-check here. Failure to do this at all would result in the temp
* files always getting placed in the default tablespace, which is a
* pretty hard-to-detect bug. Callers may prefer to do it earlier if they
* want to be sure that any required catalog access is done in some other
* resource context.
*/
PrepareTempTablespaces();
pfile = OpenTemporaryFile(interXact);
Assert(pfile >= 0);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment