Search
 
SCRIPT & CODE EXAMPLE
 

SQL

postgres check blocking

Run the below to find out if you´ve got queries blocking PostgreSQL.

SELECT blocked_locks.pid AS blocked_pid,
blocked_activity.usename AS blocked_user,
blocking_locks.pid AS blocking_pid,
blocking_activity.usename AS blocking_user, 
blocked_activity.query AS blocked_statement,
blocking_activity.query AS current_statement_in_blocking_process
FROM pg_catalog.pg_locks blocked_locks 
JOIN pg_catalog.pg_stat_activity blocked_activity ON blocked_activity.pid = blocked_locks.pid
JOIN pg_catalog.pg_locks blocking_locks 
ON blocking_locks.locktype = blocked_locks.locktype 
AND blocking_locks.DATABASE IS NOT DISTINCT FROM blocked_locks.DATABASE
AND blocking_locks.relation IS NOT DISTINCT FROM blocked_locks.relation
AND blocking_locks.page IS NOT DISTINCT FROM blocked_locks.page
AND blocking_locks.tuple IS NOT DISTINCT FROM blocked_locks.tuple
AND blocking_locks.virtualxid IS NOT DISTINCT FROM blocked_locks.virtualxid
AND blocking_locks.transactionid IS NOT DISTINCT FROM blocked_locks.transactionid
AND blocking_locks.classid IS NOT DISTINCT FROM blocked_locks.classid
AND blocking_locks.objid IS NOT DISTINCT FROM blocked_locks.objid
AND blocking_locks.objsubid IS NOT DISTINCT FROM blocked_locks.objsubid
AND blocking_locks.pid != blocked_locks.pid 
JOIN pg_catalog.pg_stat_activity blocking_activity ON blocking_activity.pid = blocking_locks.pid
WHERE NOT blocked_locks.GRANTED;
Comment

PREVIOUS NEXT
Code Example
Sql :: encoding UTF8 has no equivalent in encoding WIN1252 
Sql :: mysql date format unix timestamp 
Sql :: get the mysql table columns data type mysql 
Sql :: sql select roundup column 
Sql :: mysql remove definers 
Sql :: set boolean flasksql 
Sql :: python mysql check if database exists 
Sql :: list all tables and columns in postgresql 
Sql :: mysql drop column 
Sql :: mysql month name extract 
Sql :: how to use a trigger to validate input data 
Sql :: reutrn string after character sql 
Sql :: oracle list dates between 
Sql :: drop table if exists oracle 
Sql :: dbms_output.put_line 
Sql :: helptext in sql 
Sql :: how to count null values in mysql 
Sql :: mysql search like order by best match 
Sql :: copy one column data to another in sql 
Sql :: sqlite version check 
Sql :: go install mysql 
Sql :: alter table in mysql 
Sql :: Step 1: Installing MySQL Client You can install MySQL client directly through pip using the command pip install mysqlclient 
Sql :: how to add foreign key constraint in sql 
Sql :: script to add datafile to tablespace 
Sql :: best sql course 
Sql :: add unique constraint sql server multiple columns 
Sql :: uppercase and lowercase in sql 
Sql :: where not in array sql 
Sql :: sql remove not null constraint 
ADD CONTENT
Topic
Content
Source link
Name
9+8 =