Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

I'm trying to show all locks (DBMS-wide) in Postgres.

I initially tried adapting the documented example to:

SELECT pg_database.datname AS database, relation::regclass, pg_locks.database AS db_oid, pg_locks.relation AS rel_oid,
        locktype, page, tuple, virtualxid, transactionid, classid, objid, objsubid, virtualtransaction, pid, mode, granted
    FROM pg_locks
    LEFT OUTER JOIN pg_database ON (pg_locks.database = pg_database.oid)
    ORDER BY database, relation;

but Postgres seems to only be able to resolve the names of relations in the current catalog:

    database    |                relation                 | db_oid  | rel_oid |   locktype    | page | tuple | virtualxid  | transactionid | classid | objid | objsubid | virtualtransaction |  pid  |           mode           | granted
----------------+-----------------------------------------+---------+---------+---------------+------+-------+-------------+---------------+---------+-------+----------+--------------------+-------+--------------------------+---------
 franknfurter   | pg_locks                                | 2881378 |   11000 | relation      |      |       |             |               |         |       |          | 40/1709521         |  9684 | AccessShareLock          | t
 janet          |                                         | 3820378 | 3820698 | relation      |      |       |             |               |         |       |          | 97/3461972         | 19937 | AccessShareLock          | t
 janet          |                                         | 3820378 | 3820698 | relation      |      |       |             |               |         |       |          | 97/3461972         | 19937 | RowExclusiveLock         | t
                | pg_database_datname_index               |       0 |    2671 | relation      |      |       |             |               |         |       |          | 40/1709521         |  9684 | AccessShareLock          | t
 brad           |                                         |  772666 |  772946 | relation      |      |       |             |               |         |       |          | 28/1711346         |  9317 | ShareUpdateExclusiveLock | t
 franknfurter   | idx_posts_user_id_deleted_at            | 2881378 | 2883250 | relation      |      |       |             |               |         |       |          | 21/2032902         |  9602 | RowExclusiveLock         | t
 franknfurter   | pg_class                                | 2881378 |    1259 | relation      |      |       |             |               |         |       |          | 40/1709521         |  9684 | AccessShareLock          | t
 franknfurter   | posts_pkey                              | 2881378 | 2881707 | relation      |      |       |             |               |         |       |          | 21/2032902         |  9602 | RowExclusiveLock         | t
                |                                         |         |         | virtualxid    |      |       | 97/3461972  |               |         |       |          | 97/3461972         | 19937 | ExclusiveLock            | t

is this just a limitation of postgres or am I doing something differently?

share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

You can only resolve names from the current database. This is because the pg_class table, which is what the ::reglass operator uses to resolve the names, is local to each database.

share|improve this answer
    
I suspected this would be the case, but I couldn't find anything that explicitly said so ☹ –  MikeyB Aug 20 '13 at 5:45
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.