SELECT l.database AS db_oid, d.datname, l.relation, n.nspname, c.relname, a.pid, a.usename, l.locktype, l. mode, l. granted, l.tuple FROM pg_locks l JOIN pg_class c ON (c.oid = l.relation) JOIN pg_namespace n ON (n.oid = c.relnamespace) JOIN pg_database d ON (d.oid = l.database) JOIN pg_stat_activity a ON (a.pid = l.pid) ORDER BY database, relation, pid;