On Thu, 2006-02-23 at 17:12 -0300, Carlos Henrique Reimer wrote:
> When the pg_locks view is used the internal lock manager data
> structures are momentarily locked and that is why I would like to know
> if some application is reading the pg_locks view and how many times.
>
> Is there a way to discover it?
AFAIK there is no easy way to determine this information. You could
probably patch Postgres to record the info fairly easy: one way would be
to allocate a small block of shared memory and an LWLock to protect it,
and then have pg_lock_status() acquire the lock and increment a counter.
Then add a new function to retrieve the current value of the counter.
You could even do it without modifying the backend proper: change the
definition of the pg_locks view to invoke a set-returning PL/PgSQL
function. That function would increment a counter stored in some table,
and then construct and return the normal pg_locks result set.
-Neil