What command returns tables that are on LOCK in PostgreSQL?

Question:

What command can I execute to return tables that are on LOCK in PostgreSQL .

lock example query :

BEGIN; LOCK TABLE documento_sequencial  
     ...  
COMMIT;

Answer:

select c.relname, n.nspname, l.locktype, l.mode, l.granted, l.fastpath
from
    pg_locks l
    inner join
    pg_database d on l.database = d.oid
    inner join
    pg_class c on l.relation = c.oid
    inner join
    pg_namespace n on c.relnamespace = n.oid
where d.datname = 'cpn' and n.nspname = 'public'
;
 relname | nspname | locktype |        mode         | granted | fastpath 
---------+---------+----------+---------------------+---------+----------
 t       | public  | relation | AccessExclusiveLock | t       | f
(1 row)

https://www.postgresql.org/docs/current/static/catalogs.html

Scroll to Top