Alex Camargo
Alex Camargo

Reputation: 45

Dead Tuples without updates/deletes

Is it possible? I have a table with fast growing dead tuples, but I can't see any update or delete to the table during the day, just inserts and selects. Autovacuum runs each 10 min, the n_dead_tup goes almost to zero and start growing again.

There is one delete at this table, for purging rows with date 15 days ago, running only once per day (triple-checked that is done just once per day).

In the rest of the day, only inserts and selects run on this table.

Upvotes: 4

Views: 1476

Answers (1)

klin
klin

Reputation: 121604

A failed attempt to insert data may cause dead tuples. Example:

create table test(id serial primary key, str text);

insert into test (str) values ('abc');

select pg_stat_get_dead_tuples('test'::regclass);

 pg_stat_get_dead_tuples 
-------------------------
                       0
(1 row)

insert into test values (1, 'def');

ERROR:  duplicate key value violates unique constraint "test_pkey"
DETAIL:  Key (id)=(1) already exists.

select pg_stat_get_dead_tuples('test'::regclass);

 pg_stat_get_dead_tuples 
-------------------------
                       1
(1 row)

This also applies to the inserts aborted due to rollback.

Upvotes: 5

Related Questions