Search Postgresql Archives

getting deadlocks on full table lock

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux