How to release possible Postgres row locks?

前端 未结 6 779
被撕碎了的回忆
被撕碎了的回忆 2020-12-22 17:41

I ran an update statement on a large PostgreSQL table through the phpPgAdmin interface. This timed out as it ran for too long.

I can now update some rows from that t

6条回答
  •  春和景丽
    2020-12-22 17:53

    It's possible to see the locks.

    Here is a view to make it a bit easier than using pg_locks directly:

    CREATE OR REPLACE VIEW public.active_locks AS 
     SELECT t.schemaname,
        t.relname,
        l.locktype,
        l.page,
        l.virtualtransaction,
        l.pid,
        l.mode,
        l.granted
       FROM pg_locks l
       JOIN pg_stat_all_tables t ON l.relation = t.relid
      WHERE t.schemaname <> 'pg_toast'::name AND t.schemaname <> 'pg_catalog'::name
      ORDER BY t.schemaname, t.relname;
    

    Then you just select from the view:

    SELECT * FROM active_locks;
    

    And kill it with:

    SELECT pg_cancel_backend('%pid%');
    

    Other solutions: http://wiki.postgresql.org/wiki/Lock_Monitoring

提交回复
热议问题