getting deadlocks on full table lock

Поиск
Список
Период
Сортировка
От Merlin Moncure
Тема getting deadlocks on full table lock
Дата
Msg-id b42b73150603271253i11cd58afq3553b35c288826c1@mail.gmail.com
обсуждение исходный текст
Ответы Re: getting deadlocks on full table lock  (Tom Lane <tgl@sss.pgh.pa.us>)
Список 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

В списке pgsql-general по дате отправления:

Предыдущее
От: "Joshua D. Drake"
Дата:
Сообщение: Re: [Bulk] General advice on database/web applications
Следующее
От: Tom Lane
Дата:
Сообщение: Re: getting deadlocks on full table lock