First, find out the statement
Select Wait.pid, wait.query as Wait_query, Wait.query_start as Wait_query_start, Wait.locktype, granted . pid as Waitfor_pid, Granted.relation, Granted.datname|| '. ' | | D.nspname | | '. ' | |C.relname as name, Granted.transactionid, Granted.virtualxid, Granted.usename, Granted.client_addr, GR Anted.query_start, Granted.queryfrom (select A.query, A.query_start, B.pid, b.re Lation, B.transactionid, B.page, B.tuple, B.locktype, B.virtualxid from Pg_stat_activity A, pg_locks b where a.waiting= ' t 'and A.pid=B.pid and granted= ' F ') waitjoin (select B.pid, B.usename, B.client_addr, B.backend_start, B.query _start, B.waiting, B.query, B.datname, A.relation, A.transactionid, A.page, A.tuple, A.locktype, A.virtualxid from Pg_locks A, pg_stat_activity b where a. PID=B.pid and a.granted= ' t ') Grantedon ((Wait.locktype= ' TransactionID 'and Granted.locktype= ' TransactionID 'and Wait.transactionid=Granted.transactionid) or (Wait.locktype= ' Relation 'and Granted.locktype= ' Relation 'and wait.relation=granted.relation) or (Wait.locktype= ' Virtualxid 'and Granted.locktype= ' Virtualxid 'and Wait.virtualxid=Granted.virtualxid) or (Wait.locktype= ' tuple 'and Granted.locktype= ' tuple 'and wait.relation=Granted.relation and Wait.page=Granted.page and Wait.tuple=granted.tuple)) Left join Pg_class con (c.relfilenode=wait.relation) LEFT join Pg_namespace Don (c.relnamespace=d.oid) Order Bygranted.query_start;
Second, kill the dependent SQL
Select Pg_terminate_backend (Process ID)
Issues with the POSTGRESQL lock table