Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PostgreSQL - How to change tmp directory?

Tags:

postgresql

I am running PostgreSQL on Windows 8 using the OpenGeo Suite. I'm running out of disk space on a large join. How can I change the temporary directory where the "hash-join temporary file" gets stored?

I am looking at the PostgreSQL configuration file and I don't see a tmp file directory.

Note: I am merging two tables with 10 million rows using a variable text field which is set to a primary key.

This is my query:

UPDATE blocks 
SET "PctBlack1" = race_blocks."PctBlack1"
FROM race_blocks
WHERE race_blocks.esriid = blocks.geoid10
like image 348
Aaron Kreider Avatar asked Sep 11 '13 00:09

Aaron Kreider


1 Answers

First, make sure you have an index on these columns (of both tables). This would make PostgreSQL use less temporary files. Also, set the GUC work_mem to as high as possible, to make PostgreSQL use more memory for operations like this.

Now, if still need, to change the temporary path, you first need to create a tablespace (if you didn't do it already):

CREATE TABLESPACE temp_disk LOCATION 'F:\pgtemp';

Then, you have to set the GUC temp_tablespaces. You can set it per database, per user, at postgresql.conf or inside the current session (before your query):

SET temp_tablespaces TO 'temp_disk';

UPDATE blocks 
SET "PctBlack1" = race_blocks."PctBlack1"
FROM race_blocks
WHERE race_blocks.esriid = blocks.geoid10

One more thing, the user must have CREATE privilege to use this:

GRANT CREATE ON TABLESPACE temp_disk TO app_user;
like image 84
MatheusOl Avatar answered Oct 29 '22 16:10

MatheusOl