How to view table/row locks in PostgreSQL?

postgresql show tables

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 Delete/Drop a Constraint In PostgresSQL

Support us & keep this site free of annoying ads.
Shop or Donate with Paypal

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

Leave a Comment