pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
pg_locks relation cant be found in pg_class
2+ messages / 2 participants
[nested] [flat]

* pg_locks relation cant be found in pg_class
@ 2019-07-24 09:15  Mariel Cherkassky <mariel.cherkassky@gmail.com>
  0 siblings, 1 reply; 2+ messages in thread

From: Mariel Cherkassky @ 2019-07-24 09:15 UTC (permalink / raw)
  To: pgsql-admin@lists.postgresql.org

Hey,
I'm trying to map an oid of relations in pg_lock to a relation name with
the following query :
select locktype,relname,database,mode,pid,granted from pg_locks,pg_class
where locktype='relation' and pg_locks.relation=pg_class.oid;

However, I'm getting only relations of system catalogs and not other
relations.. pg_locks contains rows for many relations, for example :
postgres=# select relation,count(*) from pg_locks where locktype='relation'
group by relation order by count desc;
 relation | count
----------+-------
    16531 |     4
   320587 |     3
    16535 |     3
   320585 |     3

but in the result of my first query I dont get the relation name. For
example :
postgres=# select count(*) from pg_class where oid in (16531,320587,16535);
 count
-------
     0

any idea ?

^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: pg_locks relation cant be found in pg_class
@ 2019-07-24 13:35  Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
  parent: Mariel Cherkassky <mariel.cherkassky@gmail.com>
  0 siblings, 0 replies; 2+ messages in thread

From: Peter Eisentraut @ 2019-07-24 13:35 UTC (permalink / raw)
  To: Mariel Cherkassky <mariel.cherkassky@gmail.com>; pgsql-admin@lists.postgresql.org

On 2019-07-24 11:15, Mariel Cherkassky wrote:
> However, I'm getting only relations of system catalogs and not other
> relations.. pg_locks contains rows for many relations, for example : 
> postgres=# select relation,count(*) from pg_locks where
> locktype='relation' group by relation order by count desc;
>  relation | count
> ----------+-------
>     16531 |     4
>    320587 |     3
>     16535 |     3
>    320585 |     3
> 
> but in the result of my first query I dont get the relation name. For
> example : 
> postgres=# select count(*) from pg_class where oid in (16531,320587,16535);
>  count
> -------
>      0
> 

"pg_locks provides a global view of all locks in the database cluster,
not only those relevant to the current database. Although its relation
column can be joined against pg_class.oid to identify locked relations,
this will only work correctly for relations in the current database
(those for which the database column is either the current database's
OID or zero)." (from the documentation)

-- 
Peter Eisentraut              http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services





^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2019-07-24 13:35 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2019-07-24 09:15 pg_locks relation cant be found in pg_class Mariel Cherkassky <mariel.cherkassky@gmail.com>
2019-07-24 13:35 ` Peter Eisentraut <peter.eisentraut@2ndquadrant.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox