pgsql查看数据库死锁脚本

数据库被锁定后,会导致其它用户无法使用,如下脚本可查询死锁。

SELECT
  pg_locks.pid,
    transactionid,
  usename,
  mode,
  granted,
    pg_stat_activity.backend_start,
  query,
    pg_stat_activity.*
FROM
  pg_locks
  JOIN pg_stat_activity ON pg_locks.pid = pg_stat_activity.pid
    where transactionid is not null
    ORDER BY backend_start 

如下脚本可以停止被锁的线程。

select pg_terminate_backend(1602927)

 

posted @ 2024-01-04 18:59  段江涛IT  阅读(566)  评论(0编辑  收藏  举报
页脚HTML代码