PostgreSQL Lock Monitoring

Source: Internet
Author: User
Tags postgresql

pg>9.2

postgres=# SELECT Blocked_locks.pid as Blocked_pid,
postgres-# Blocked_activity.usename as Blocked_user,
postgres-# Blocking_locks.pid as Blocking_pid,
postgres-# Blocking_activity.usename as Blocking_user,
postgres-# Blocked_activity.query as Blocked_statement,
postgres-# Blocking_activity.query as Current_statement_in_blocking_process
postgres-# from Pg_catalog.pg_locks blocked_locks
postgres-# JOIN pg_catalog.pg_stat_activity blocked_activity on blocked_activity.pid = Blocked_locks.pid
postgres-# JOIN pg_catalog.pg_locks Blocking_locks
postgres-# on blocking_locks.locktype = Blocked_locks.locktype
postgres-# and Blocking_locks. DATABASE is not a DISTINCT from Blocked_locks. DATABASE
postgres-# and Blocking_locks.relation is not DISTINCT from blocked_locks.relation
postgres-# and Blocking_locks.page is not DISTINCT from Blocked_locks.page
postgres-# and Blocking_locks.tuple is not DISTINCT from Blocked_locks.tuple
postgres-# and Blocking_locks.virtualxid is not DISTINCT from Blocked_locks.virtualxid
postgres-# and Blocking_locks.transactionid is not DISTINCT from Blocked_locks.transactionid
postgres-# and Blocking_locks.classid is not DISTINCT from Blocked_locks.classid
postgres-# and Blocking_locks.objid is not DISTINCT from Blocked_locks.objid
postgres-# and Blocking_locks.objsubid is not DISTINCT from Blocked_locks.objsubid
postgres-# and Blocking_locks.pid! = Blocked_locks.pid
postgres-#
postgres-# JOIN pg_catalog.pg_stat_activity blocking_activity on blocking_activity.pid = Blocking_locks.pid
postgres-# WHERE not blocked_locks. granted;
Blocked_pid | Blocked_user | Blocking_pid | Blocking_user | blocked_statement | Current_statement_in_blocking_process
-------------+--------------+--------------+---------------+-------------------+------------------------------- --------
(0 rows)

pg< 9.2:

  SELECT BL. pidAs Blocked_pidA. usenameAs Blocked_userKl. pidAs Blocking_pidKa. usenameAs Blocking_userA. current_queryAs Blocked_statementFrom Pg_catalog.pg_locks bl join pg_catalog.pg_stat_activity A on a.procpid = bl.pid  JOIN pg_catalog.pg_locks KL on kl.transactionid = bl.transactionid and kl.pid != bl.pid join pg_catalog.pg_stat_activity ka Span class= "KW1" >on ka.procpid = kl.pid  WHERE not bl. granted; 
https://wiki.postgresql.org/wiki/Lock_Monitoring

PostgreSQL Lock Monitoring

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.