Exhaustive list of what takes what locks

Поиск
Список
Период
Сортировка
От Nikolas Everett
Тема Exhaustive list of what takes what locks
Дата
Msg-id AANLkTiksaoSZ03m_jALCBwhfogZxNA5_wKo_3J6ydBfF@mail.gmail.com
обсуждение исходный текст
Ответы Re: Exhaustive list of what takes what locks  (Greg Smith <greg@2ndquadrant.com>)
Re: Exhaustive list of what takes what locks  (Robert Haas <robertmhaas@gmail.com>)
Re: Exhaustive list of what takes what locks  (Noah Misch <noah@leadboat.com>)
Список pgsql-performance
Dear list,

Is there an exhaustive list of what takes what locks and how long they last?  I'm asking because we just had some trouble doing a hot db change to an 8.3.6 system.  I know it is an old version but it is what I have to work with.  You can reproduce it like so:

First:
DROP TABLE IF EXISTS foo;
DROP TABLE IF EXISTS account;

CREATE TABLE account (account_id SERIAL PRIMARY KEY, name CHARACTER VARYING NOT NULL);
CREATE TABLE foo (account_id INTEGER NOT NULL REFERENCES account (account_id), stuff CHARACTER VARYING);

In one connection:
INSERT INTO account (name) SELECT generate_series FROM GENERATE_SERIES(0, 10000000);

In another connection while that last one is running:
DROP TABLE foo;

And in another connection if you are feeling frisky:
   select 
     pg_stat_activity.datname,pg_class.relname,pg_locks.transactionid, pg_locks.mode, pg_locks.granted,
     pg_stat_activity.usename,pg_stat_activity.current_query, pg_stat_activity.query_start, 
     age(now(),pg_stat_activity.query_start) as "age", pg_stat_activity.procpid 
   from pg_stat_activity,pg_locks left 
     outer join pg_class on (pg_locks.relation = pg_class.oid)  
   where pg_locks.pid=pg_stat_activity.procpid order by query_start;

That query shows that the DROP takes an AccessExclusiveLock on account.  This isn't totally unexpected but it is unfortunate because it means we have to wait for a downtime window to maintain constraints even if they are not really in use.

This isn't exactly how our workload actually works.  Ours is more deadlock prone.  We have many connections all querying account and we do the migration in a transaction.  It looks as though the AccessExclusiveLock is held until the transaction terminates.

Nik Everett

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

Предыдущее
От: "Ross J. Reedstrom"
Дата:
Сообщение: Re: postgres 9 query performance
Следующее
От: Greg Smith
Дата:
Сообщение: Re: Any experience using "shake" defragmenter?