Skip to content

Instantly share code, notes, and snippets.

@shantanusingh
Created June 28, 2012 20:01
Show Gist options
  • Save shantanusingh/3013540 to your computer and use it in GitHub Desktop.
Save shantanusingh/3013540 to your computer and use it in GitHub Desktop.
Debugging Deadlocks in PostgreSQL

Queries For Deadlock Detection

select pg_class.relname,pg_locks.* from pg_class,pg_locks where pg_class.relfilenode=pg_locks.relation;

select * from pg_locks;

select * from pg_locks where granted = 'f' //the query that is waiting
select * from pg_locks where transactionid = 'xx' // queries running in a transaction
select * from pg_stat_activity

##References http://rhaas.blogspot.in/2011/01/locking-in-postgresql.html

http://fishbowl.pastiche.org/2004/02/26/finding_open_locks_on_postgresql/

http://www.postgresql.org/docs/current/static/explicit-locking.html

http://stackoverflow.com/questions/1153364/postgresql-exclusive-lock-stops-application

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment