Re: FW: deleted records - Mailing list pgsql-general

From Michael Fuhr
Subject Re: FW: deleted records
Date
Msg-id 20051228164403.GA29215@winnie.fuhr.org
Whole thread Raw
In response to FW: deleted records  ("H.J. Sanders" <hjs@worldonline.nl>)
List pgsql-general
On Wed, Dec 28, 2005 at 02:15:24PM +0100, H.J. Sanders wrote:
> is there a way to find out how many deleted records there are in
> a table (this gives an indication that it is time to vacuum)?

Use the pgstattuple() function from contrib/pgstattuple.

test=> CREATE TABLE foo (x integer);
CREATE TABLE
test=> INSERT INTO foo SELECT 1 FROM generate_series(1, 10000);
INSERT 0 10000
test=> DELETE FROM foo WHERE random() < 0.5;
DELETE 4957
test=> \x
Expanded display is on.
test=> SELECT * FROM pgstattuple('foo');
-[ RECORD 1 ]------+-------
table_len          | 368640
tuple_count        | 5043
tuple_len          | 161376
tuple_percent      | 43.78
dead_tuple_count   | 4957
dead_tuple_len     | 158624
dead_tuple_percent | 43.03
free_space         | 7736
free_percent       | 2.1

--
Michael Fuhr

pgsql-general by date:

Previous
From: Tony Caduto
Date:
Subject: Re: sending mail from Postgres
Next
From: Vivek Khera
Date:
Subject: Re: just an inconvenience, or.... : failed queries don't appear in the log anymore since v8.?.?