How to view table/row locks in PostgreSQL?

postgresql reset statistics, pg_stat_reset

This article will show you how to see a list view a list of locks that are currently open (or waiting) on your database rows and tables. This information is beneficial when debugging timing-related errors and data inconsistencies.

  1. Login to the PostgresSQL command-line interface
  2. psql -U [username] [database_name]

  3. Run the following query:
  4. select t.relname,l.locktype,page,virtualtransaction,pid,mode,granted from pg_locks l, pg_stat_all_tables t where l.relation=t.relid order by relation asc;

See also  How to find (log) slow queries in PostgreSQL 8.x, 9.x

1 thought on “How to view table/row locks in PostgreSQL?”

Leave a Comment