postgreSQL vacuum temp files?

jorgen picture jorgen · Sep 4, 2009 · Viewed 11.5k times · Source

I've got a "little" problem. A week ago my database was reaching full disk capacity. I deleted many rows in different tables trying to free up disk space. After which I tried running a full vacuum which did not complete.

What I want to know is. When I stopped the vacuum from fully completing does it leave any temp files on the disk that I have to delete manually? I now have a database which is at a 100% disk capacity, which needlessly to say is a big problem.

Any tips to free disk space?

I'm running SUSE with a postgres 8.1.4 database.

Answer

user80168 picture user80168 · Sep 4, 2009

First of all:

UPGRADE

Even if you can't to 8.2, 8.3 or 8.4 - at least upgrade to newest 8.1 (which is 8.1.17 at the moment, but will be 8.1.18 in 1-2 days).

Second: diagnose what is the problem.

Use du tool to diagnose where exactly did the space go. What directory is occupying too much space?

Check with df what is total used space, and then check how much of it is PostgreSQL directory.

The best option is to:

cd YOUR_PGDATA_DIR
du -sk *
cd base
du -sk *
cd LARGEST DIR FROM PREVIOUS COMMAND
du -sk * | sort -nr | head

Now, that you know which directory in PGDATA is using space you can do something about it.

if it's logs or pg_temp - restart pg or remove logs (pg_clog and pg_xlog are not logs in common meaning of the word, never delete anything from there!).

If it's something in your base directory, then:

numerical directories in base directory relate to databases. You can check it with:

select oid, datname from pg_database;

When you know the database that is using most of the space, connect to it, and check which files are using most of the space.

File names will be numerical with optional ".digits" suffix - this suffix is (for now) irrelevant, and you can check what exactly the file represents by issuing:

select relname from pg_class  where relfilenode = <NUMBER_FROM_FILE_NAME>;

Once you know which tables/indexes use most of the space - you can VACUUM FULL it, or (much better) issue CLUSTER command on them.