Is the pg_locks been used?

Started by Carlos Henrique Reimerabout 20 years ago2 messagesgeneral
Jump to latest
#1Carlos Henrique Reimer
carlosreimer@yahoo.com.br

Hi,

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?

Thanks in advance!

Reimer

---------------------------------
Yahoo! Acesso Gr�tis
Internet r�pida e gr�tis. Instale o discador agora!

#2Neil Conway
neilc@samurai.com
In reply to: Carlos Henrique Reimer (#1)
Re: Is the pg_locks been used?

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