Re: Database deadlock/hanging - Mailing list pgsql-general

From Reece Hart
Subject Re: Database deadlock/hanging
Date
Msg-id 1173288424.5374.22.camel@snafu.site
Whole thread Raw
In response to Database deadlock/hanging  (John Gateley <gateley@jriver.com>)
Responses Re: Database deadlock/hanging
List pgsql-general
On Wed, 2007-03-07 at 10:08 -0600, John Gateley wrote:
> I'm guessing it's something related to table locks.
...
> Any pointers on what I should be looking for to prevent this from
> happening again? What information I should be tracking to figure
> out what is exactly happening?

Your inserts almost certainly have a table or index exclusively locked
and thereby causing a backlog of selects.

You can fish current and waiting locks out of pg_locks, but those use
internal identifiers rather than names.  Here's a view that will make
pg_locks more readable:

rkh@csb-dev=> CREATE OR REPLACE VIEW pgutils.locks AS
 SELECT l.pid, d.datname AS "database", n.nspname AS "schema", c.relname AS relation, l.locktype, l."mode",
        CASE l."granted"
            WHEN true THEN 'RUN'::text
            ELSE 'WAIT'::text
        END AS state, a.usename, a.current_query, to_char(now() - a.query_start, 'HH24:MI:SS'::text) AS duration
   FROM pg_locks l
   JOIN pg_database d ON l."database" = d.oid
   JOIN pg_class c ON l.relation = c.oid
   JOIN pg_namespace n ON c.relnamespace = n.oid
   JOIN pg_stat_activity a ON l.pid = a.procpid
  ORDER BY l.pid, d.datname, n.nspname, c.relname, l."granted";

rkh@csb-dev=> select * from pgutils.locks ;
  pid  | database |   schema   |      relation      | locktype |      mode       | state | usename | current_query |
duration 

-------+----------+------------+--------------------+----------+-----------------+-------+---------+---------------+----------
 28434 | csb-dev  | pg_catalog | pg_class           | relation | AccessShareLock | RUN   | rkh     | <IDLE>        |
00:00:21
 28434 | csb-dev  | pg_catalog | pg_class_oid_index | relation | AccessShareLock | RUN   | rkh     | <IDLE>        |
00:00:21
 28434 | csb-dev  | pg_catalog | pg_locks           | relation | AccessShareLock | RUN   | rkh     | <IDLE>        |
00:00:21
 28434 | csb-dev  | pg_catalog | pg_namespace       | relation | AccessShareLock | RUN   | rkh     | <IDLE>        |
00:00:21
 28434 | csb-dev  | pg_catalog | pg_stat_activity   | relation | AccessShareLock | RUN   | rkh     | <IDLE>        |
00:00:21
 28434 | csb-dev  | pgutils    | locks              | relation | AccessShareLock | RUN   | rkh     | <IDLE>        |
00:00:21
(6 rows)

-Reece

--
Reece Hart, http://harts.net/reece/, GPG:0x25EC91A0
./universe -G 6.672e-11 -e 1.602e-19 -protonmass 1.673e-27 -uspres bush
kernel warning: universe consuming too many resources. Killing.
universe killed due to catastrophic leadership. Try -uspres carter.


pgsql-general by date:

Previous
From: Alexander Elgert
Date:
Subject: Re: postgres slower on nested queries
Next
From: "Chris Fischer"
Date:
Subject: "Cache lookup failed for function" when recreating procs