getting deadlocks on full table lock

From: "Merlin Moncure" <mmoncure(at)gmail(dot)com>
To: "pgsql-general General" <pgsql-general(at)postgresql(dot)org>
Subject: getting deadlocks on full table lock
Date: 2006-03-27 20:53:51
Message-ID: b42b73150603271253i11cd58afq3553b35c288826c1@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I am getting a deadlock which I can't explain...although maybe
somebody else can...here's teh situation:

I have a plpgsql function which increments a sequence when called.
when the sequence hits a certain threshold, the sequence is reset and
a materilized structure (small table) is updated. The only thing that
writes to this materilized table is the update function. When the
function executes repeatedly from multiple backends, all backends
repeatedly deadlock on AccessExclusiveLock and abort.

I only get the deadlock on truncate of lock table..., not on delete * from.

Here is a simplified version of the functions:
create function worker() returns void as
$$
begin
-- read some stuff off of mat_table
perform update_mat() where nextval('mat_seq') > 100;
end;
$$ language plpgsql;

create function update_mat() returns void as
$$
truncate mat_table; -- or lock table mat_table
insert into mat_table select stuff from real_tables;
select setval('mat_seq', 1, false),
$$ language sql;

If I call worker quicly from multiple backends (not in transaction), I
get tons of deadlocks. Each process says it and another process is
waiting on mat_table. My understanding is that that each backend
should wait on a lock if it is not available. It feels like the locks
are not getting released.

using delete from...prevents deadlocks but then I have to deal with
mvcc table bloat. what am I doing wrong?

Merlin

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2006-03-27 21:01:27 Re: getting deadlocks on full table lock
Previous Message Joshua D. Drake 2006-03-27 20:49:25 Re: [Bulk] General advice on database/web applications