Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

Script to find sessions that are blocking other sessions in PostgreSQL

In this post, I am sharing a script to find sessions that are blocking other sessions in PostgreSQL.

Instead of finding blocked sessions or processes, sometimes it is better to find those sessions which are the root of blocking.

PostgreSQL DBA can use this script to find the cause of blocked transactions.

SELECT 
 pl.pid as blocked_pid
 ,psa.usename as blocked_user
 ,pl2.pid as blocking_pid
 ,psa2.usename as blocking_user
 ,psa.query as blocked_statement
FROM pg_catalog.pg_locks pl
JOIN pg_catalog.pg_stat_activity psa
 ON pl.pid = psa.pid
JOIN pg_catalog.pg_locks pl2
JOIN pg_catalog.pg_stat_activity psa2
 ON pl2.pid = psa2.pid
 ON pl.transactionid = pl2.transactionid 
  AND pl.pid != pl2.pid
WHERE NOT pl.granted;

Comments

Popular posts from this blog

VMWARE WORKSTATION 3,4,5,6,7,8,9,10,11,12,14,15...etc LICENSE KEYS COLLECTION

How to find the server is whether standby (slave) or primary(master) in Postgresql replication ?

How to Configuration UDEV SCSI Rules In Oracle Linux 5, 6 and 7

Linux ctime,mtime,atime,cmin,amin,mmin

aspell