Re: Persistent dead rows

From: Richard Huxton <dev(at)archonet(dot)com>
To: Malcolm McLean <MalcolmM(at)Interpharm(dot)co(dot)za>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Persistent dead rows
Date: 2007-02-08 08:57:10
Message-ID: 45CAE5E6.5030605@archonet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Malcolm McLean wrote:
> Hi,
>
> We are currently having a problem with one of our tables containing far
> too many dead rows. The table in question will have a few hundred
> thousand inserts and deletes per day and usually builds up quite a large
> dead row count that starts to affect the performance of the queries
> select from the table.
>
> However, it seems that when the dead row count reaches around 700000 it
> drops to 0 again and all is fast once more.
>
> I know that vacuuming is supposed to recover these, but it doesn't seem
> to be happening. Here is output from my analyze, vacuum, reindex and
> cluster commands:
>
> claim=# ANALYZE VERBOSE trans_queue;
> INFO: analyzing "public.trans_queue"
> INFO: "trans_queue": scanned 1749 of 1749 pages, containing 20383 live
> rows and 137327 dead rows; 20383 rows in sample, 20383 estimated total
> rows
> ANALYZE
> claim=# VACUUM VERBOSE ANALYZE trans_queue;

> INFO: "trans_queue": found 0 removable, 157730 nonremovable row
> versions in 1749 pages
> DETAIL: 137344 dead row versions cannot be removed yet.

This is usually because a transaction is hanging around that might be
able to see them. The vacuum can't recover them until that transaction
has completed.

> What is causing those dead rows to not get cleared even by a full
> vacuum? Is there any way keep them low without having to run a cluster
> command as that is a locking statement and requires me to close all java
> applications that are connecting to that table before running the
> cluster.

Aha! I'll bet your java app (or something in the stack) is issuing a
BEGIN and just sitting there. Try disconnecting the apps and seeing if
vacuum recovers rows then. If so, you'll need to get your java code to
stop sitting on open transactions.

--
Richard Huxton
Archonet Ltd

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Malcolm McLean 2007-02-08 09:45:38 Re: Persistent dead rows
Previous Message Richard Huxton 2007-02-08 08:50:52 Re: simplifying SQL