Re: "Compacting" a relation - Mailing list pgsql-hackers

From Hannu Krosing
Subject Re: "Compacting" a relation
Date
Msg-id 1164796140.3527.14.camel@localhost.localdomain
Whole thread Raw
In response to "Compacting" a relation  (Peter Eisentraut <peter_e@gmx.net>)
Responses Re: "Compacting" a relation  (Jim Nasby <decibel@decibel.org>)
List pgsql-hackers
Ühel kenal päeval, K, 2006-11-29 kell 11:19, kirjutas Peter Eisentraut:
> vacuumlazy.c contains a hint "Consider compacting this relation" but AFAICT, 
> there is no indication anywhere how "compacting" is supposed to be achieved.  
> I guess this means VACUUM FULL or CLUSTER, but I don't think the hint can be 
> processed effectively by a user.

I once had an online/concurrent/non-locking compacting script, which did
for each const_pk_col_with_largest_ctid staring starting from end of
relation 

UPDATE rel   SET pk_col=pk_col WHERE pk_col = const_pk_col_with_largest_ctid

until the tuple moved to another page as determined by 

SELECT ctid FROM rel where pk_col=const_pk_col_with_largest_ctid

if the tuple moved to a larger page number then it was time for another
lazy vacuum.

this compacted the live data in the table and if done enough times, the
lazy vacuum did actually shorten the file.

-- 
----------------
Hannu Krosing
Database Architect
Skype Technologies OÜ
Akadeemia tee 21 F, Tallinn, 12618, Estonia

Skype me:  callto:hkrosing
Get Skype for free:  http://www.skype.com




pgsql-hackers by date:

Previous
From: Peter Eisentraut
Date:
Subject: "Compacting" a relation
Next
From: Martijn van Oosterhout
Date:
Subject: Re: Short writes