SELECT plk.mode,
       plk.locktype,
       plk.pid,
       pdb.datname, 
       pc.relname,
       psa.usename,
       psa.query
  FROM pg_locks plk
  JOIN pg_database pdb
    ON plk.database = pdb.oid 
  JOIN pg_class pc 
    ON coalesce(plk.classid,plk.relation) = pc.oid 
  LEFT JOIN pg_stat_activity psa
    ON plk.pid = psa.pid
  WHERE plk.pid != pg_backend_pid() ;
  • No labels