Re: [HACKERS] View pg_stat_activity slow to get up to date

2004-11-08 Thread Tom Lane
"D'Arcy J.M. Cain" <[EMAIL PROTECTED]> writes:
> Tom Lane <[EMAIL PROTECTED]> wrote:
>> ISTM that what you have here is a bad substitute for using user locks
>> (see contrib/userlock/).

> Perhaps.  I assume that the lock is automatically released when the
> holder closes its connection to the database, right?  If so then that's
> what I need.

Right, user locks will be dropped automatically at backend exit
(otherwise their management is entirely in your hands).

regards, tom lane

---(end of broadcast)---
TIP 8: explain analyze is your friend


Re: [HACKERS] View pg_stat_activity slow to get up to date

2004-11-08 Thread D'Arcy J.M. Cain
On Mon, 08 Nov 2004 13:07:34 -0500
Tom Lane <[EMAIL PROTECTED]> wrote:
> "D'Arcy J.M. Cain" <[EMAIL PROTECTED]> writes:
> > I checked the FAQ and docs but haven't found anything definitive. 
> > This is my SQL test script:
> 
> > SELECT pg_backend_pid();
> > SELECT * FROM pg_stat_activity order by procpid;
> 
> > When I run psql reading that I find that my backend procpid is not
> > in the list.  I know that I can see it if I can introduce a little
> > sleep (1 second) between the connection and the reading of
> > pg_stat_activity.
> 
> ISTM that what you have here is a bad substitute for using user locks
> (see contrib/userlock/).

Perhaps.  I assume that the lock is automatically released when the
holder closes its connection to the database, right?  If so then that's
what I need.

-- 
D'Arcy J.M. Cain <[EMAIL PROTECTED]> |  Democracy is three wolves
http://www.druid.net/darcy/|  and a sheep voting on
+1 416 425 1212 (DoD#0082)(eNTP)   |  what's for dinner.

---(end of broadcast)---
TIP 4: Don't 'kill -9' the postmaster


Re: [HACKERS] View pg_stat_activity slow to get up to date

2004-11-08 Thread Tom Lane
"D'Arcy J.M. Cain" <[EMAIL PROTECTED]> writes:
> I checked the FAQ and docs but haven't found anything definitive.  This
> is my SQL test script:

> SELECT pg_backend_pid();
> SELECT * FROM pg_stat_activity order by procpid;

> When I run psql reading that I find that my backend procpid is not in
> the list.  I know that I can see it if I can introduce a little sleep (1
> second) between the connection and the reading of pg_stat_activity.

ISTM that what you have here is a bad substitute for using user locks
(see contrib/userlock/).

regards, tom lane

---(end of broadcast)---
TIP 5: Have you checked our extensive FAQ?

   http://www.postgresql.org/docs/faqs/FAQ.html


Re: [HACKERS] View pg_stat_activity slow to get up to date

2004-11-08 Thread D'Arcy J.M. Cain
On Mon, 08 Nov 2004 12:56:57 -0500
Jan Wieck <[EMAIL PROTECTED]> wrote:

Hi Jan.

> On 11/8/2004 12:03 PM, D'Arcy J.M. Cain wrote:
> 
> > I checked the FAQ and docs but haven't found anything definitive. 
> > This is my SQL test script:
> > 
> > SELECT pg_backend_pid();
> > SELECT * FROM pg_stat_activity order by procpid;
> > 
> > When I run psql reading that I find that my backend procpid is not
> > in the list.  I know that I can see it if I can introduce a little
> > sleep (1 second) between the connection and the reading of
> > pg_stat_activity.
> 
> That is because the way your backend gets the information from the 
> pgstat daemon process is by reading a file, which is at maximum
> written by that process every 500 msec. You will hardly ever see your
> own query.

OK, I thought that using stats might not be the most reliable method but
I couldn't find any other.  Is there a reliable way to get that info? 
Note that I don't care what the backend is doing, just whether it is
still running or not.

> All these statistics are unreliable "by design", as explained numerous
> 
> times on this list. In short, a backend should never be slowed down 
> because the pgstat process can't swallow the stats fast enough. That
> is the reason for using UDP in the first place. So the kernel is
> allowed to drop stats packets, but not to block a backend.

So it is worse than I thought.  I thought that it was slow but it looks
like it may never even make it.  Probably OK for my purposes but it
would be nice to have a reliable method.

-- 
D'Arcy J.M. Cain <[EMAIL PROTECTED]> |  Democracy is three wolves
http://www.druid.net/darcy/|  and a sheep voting on
+1 416 425 1212 (DoD#0082)(eNTP)   |  what's for dinner.

---(end of broadcast)---
TIP 8: explain analyze is your friend


Re: [HACKERS] View pg_stat_activity slow to get up to date

2004-11-08 Thread Jan Wieck
On 11/8/2004 12:03 PM, D'Arcy J.M. Cain wrote:
I checked the FAQ and docs but haven't found anything definitive.  This
is my SQL test script:
SELECT pg_backend_pid();
SELECT * FROM pg_stat_activity order by procpid;
When I run psql reading that I find that my backend procpid is not in
the list.  I know that I can see it if I can introduce a little sleep (1
second) between the connection and the reading of pg_stat_activity.
That is because the way your backend gets the information from the 
pgstat daemon process is by reading a file, which is at maximum written 
by that process every 500 msec. You will hardly ever see your own query.

My question is this.  Is there a more reliable way to see if a
particular backend is still alive?  I am trying to do a locking system
and this is necessary to make it work.  I think that in actual sessions
I will be OK but my unit test fails most of the time because of this.
All these statistics are unreliable "by design", as explained numerous 
times on this list. In short, a backend should never be slowed down 
because the pgstat process can't swallow the stats fast enough. That is 
the reason for using UDP in the first place. So the kernel is allowed to 
drop stats packets, but not to block a backend.

Jan
--
#==#
# It's easier to get forgiveness for being wrong than for being right. #
# Let's break this rule - forgive me.  #
#== [EMAIL PROTECTED] #
---(end of broadcast)---
TIP 7: don't forget to increase your free space map settings