dbTalk Databases Forums  

Q: Reclaiming deleted space in data files

comp.databases.postgresql.novice comp.databases.postgresql.novice


Discuss Q: Reclaiming deleted space in data files in the comp.databases.postgresql.novice forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Lawrence Smith
 
Posts: n/a

Default Q: Reclaiming deleted space in data files - 01-31-2004 , 04:26 PM






If I insert a large amount of data into a Postgres
table, so that the data file (or files) grow by a
large amount (something in the gigabyte range), and I
subsequently delete the table containing this data (or
delete the data from the table), can I reclaim the
space without major hassle?

I'm guessing I can with the VACUUM command. Are there
any other mechanisms for this? How "long" would it
take, i.e. if I had deleted a gigabyte of data, is
this vacuum process going to be something which
happens quickly, i.e. a matter of minutes, or is it
the kind of thing which will thrash for days and block
the DB? (I appreciate the precise timing will depend
on the size and structure of the DB, hardware etc.).

Please understand I'm not intending to do this kind of
thing often, but I have gotten into this problem with
my current DB setup and it's given me the impetus to
look for possible alternatives.


Thx

Lawrence Smith



=====
http://www.explanation-guide.info

__________________________________________________ ______________________
BT Yahoo! Broadband - Free modem offer, sign up online today and save £80 http://btyahoo.yahoo.co.uk

---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster


Reply With Quote
  #2  
Old   
Tom Lane
 
Posts: n/a

Default Re: Q: Reclaiming deleted space in data files - 01-31-2004 , 05:08 PM






=?iso-8859-1?q?Lawrence=20Smith?= <ls_services_eire (AT) yahoo (DOT) ie> writes:
Quote:
If I insert a large amount of data into a Postgres
table, so that the data file (or files) grow by a
large amount (something in the gigabyte range), and I
subsequently delete the table containing this data (or
delete the data from the table), can I reclaim the
space without major hassle?
Well, DROP TABLE reclaims the space immediately, so that case isn't very
interesting. If you're talking about deleting *all* the rows in a table
but keeping the table, TRUNCATE is your best option. If you've updated
or deleted lots of rows but don't want to lose what remains, your
options are VACUUM FULL or CLUSTER. VACUUM FULL will be faster if only
a relatively small part of the data needs to be moved to perform the
compaction. CLUSTER is probably faster if a large amount of
rearrangement will be needed (and as a bonus you can speed up retrievals
on whichever index you pick to cluster by). Either one is likely to
take a while if there are gigabytes worth of data still in the table.

Note that a plain VACUUM will release wholly-empty pages at the end of
the table, but under most scenarios that doesn't translate into giving a
lot of space back to the system. VACUUM FULL actively moves rows down
into free space in earlier pages so as to create empty pages at the end,
which it can then release.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match



Reply With Quote
  #3  
Old   
Lawrence Smith
 
Posts: n/a

Default Re: Q: Reclaiming deleted space in data files - 02-01-2004 , 10:00 AM



Tom,

many thanks for the quick and informative answer, you
guys are amazing.

I've done a test Postgres install and I see the data
dirs are divided up into individual files (rather than
one monolithic file like my current system). I'll take
a closer look at Posgtres, the projects still at a
stage where I can risk a change.

Once again, thanks.

Lawrence Smith




=====
http://www.explanation-guide.info

__________________________________________________ ______________________
BT Yahoo! Broadband - Free modem offer, sign up online today and save £80 http://btyahoo.yahoo.co.uk

---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.