Re: Yet another "drop table vs delete" question

From: Erik Jones <ejones(at)engineyard(dot)com>
To: Thomas Finneid <tfinneid(at)fcon(dot)no>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Yet another "drop table vs delete" question
Date: 2009-04-22 22:14:57
Message-ID: 79BBB3B7-8905-4F5E-9270-2AFB7EE91C02@engineyard.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Apr 22, 2009, at 8:04 AM, Thomas Finneid wrote:

> Alvaro Herrera wrote:
>> Try TRUNCATE. That leaves the less garbage behind and takes the less
>> time.
>
> A follow up question, as far as I understand it, delete removes
> entries in the fsm, so vacuum has to clean it all up when performing
> a delete, is this approximately correct? what happens with truncate?
> does it remove everything so that vacuum has almost no work to do or
> is it approximately as much work either way?

No, DELETE doesn't do anything with the FSM. It simply marks the
tuple in the page as deleted (not visible) to transactions with
transaction ids larger than the DELETE transaction's commit id
(assuming it commits). So, once all transactions with transaction ids
lower than that DELETE transaction's commit id it can be considered
dead since nothing can see it anymore. VACUUM looks for those dead
tuples and adds them to the FSM. INSERTs and UPDATEs (and COPYs) then
look to the free space map for a dead tuple first when space is needed
for a new tuple before allocating space in hopes of avoiding that
space allocation by reusing the dead tuple's space.

You're pretty much on with regards to TRUNCATE as it deletes the pages
that are allocated to the table (I'm not sure if the TRUNCATE handles
clearing out the FSM entries for that table or if VACUUM does when the
table is next vacuum'd).

Erik Jones, Database Administrator
Engine Yard
Support, Scalability, Reliability
866.518.9273 x 260
Location: US/Pacific
IRC: mage2k

In response to

Browse pgsql-general by date

  From Date Subject
Next Message DM 2009-04-22 22:19:27 how to revoke multiple users permission from multiple tables at the same time?
Previous Message DM 2009-04-22 22:14:29 Re: how to search for relation by name?