CREATE VIEW v_querylockwait AS SELECT l1.pid AS pid, a1.current_query AS query, l2.pid AS waitingonpid, a2.current_query AS waitingonquery FROM pg_locks l1, pg_locks l2, pg_stat_activity a1, pg_stat_activity a2 WHERE l1.pid = a1.procpid AND l2.pid = a2.procpid AND NOT l1.granted AND l2.granted AND l1.locktype = l2.locktype AND l1.pid <> l2.pid AND ( (l1.locktype, l1.database, l1.relation, l1.page, l1.tuple, l1.virtualxid, l1.transactionid, l1.classid, l1.objid, l1.objsubid) IS NOT DISTINCT FROM (l2.locktype, l2.database, l2.relation, l2.page, l2.tuple, l2.virtualxid, l2.transactionid, l2.classid, l2.objid, l2.objsubid) ) AND lock_conflict(l1.mode, l2.mode);
