473,799 Members | 2,727 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

select count(*) from pg_stat_activit y in V8.0.0

Coming off of 7.4.3 I've always used

select count(*) from pg_stat_activit y

through the ODBC driver to obtain the number of connections to the db. I've
found that with v8.0 Beta 1 that this at times has returned a value of 0
(when there is obviously still a connection). It's not repeatable, and
occurs sporadically. Does anyone have any reason as to why this would be
isolated to V8? Is this an acceptable means of obtaining the number of
connection to the database in V8 (via ODBC).

Thanks so much,
Peter
---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

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

Nov 23 '05 #1
5 3216
Anony Mous wrote:
Coming off of 7.4.3 I've always used

select count(*) from pg_stat_activit y

through the ODBC driver to obtain the number of connections to the db. I've
found that with v8.0 Beta 1 that this at times has returned a value of 0
(when there is obviously still a connection). It's not repeatable, and
occurs sporadically. Does anyone have any reason as to why this would be
isolated to V8? Is this an acceptable means of obtaining the number of
connection to the database in V8 (via ODBC).


Do you have multiple live connections? My understanding of
pg_stat_activit y is that it can lag slightly behind the current state of
the system. If the only connection that is active is the one doing the
counting you could be checking before the table has been updated.

--
Richard Huxton
Archonet Ltd

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddres sHere" to ma*******@postg resql.org)

Nov 23 '05 #2
Richard Huxton <de*@archonet.c om> writes:
Anony Mous wrote:
select count(*) from pg_stat_activit y
Do you have multiple live connections? My understanding of
pg_stat_activit y is that it can lag slightly behind the current state of
the system.


If memory serves, it's up to 500 msec behind. So this technique has
never been 100% accurate. I'm not sure why A.Mous failed to observe the
inaccuracy before ...

regards, tom lane

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

Nov 23 '05 #3
Thanks, Richard.

I've never seen this behaviour before in 7.4.3 and indeed it is the only
connection to the back end at the time when the count is occurring. However,
it would have had the connection for at least 30 seconds before requesting a
count.

Is there a better method of obtaining the number of connections to the
backend?

Thanks
Peter

-----Original Message-----
From: Richard Huxton [mailto:de*@arch onet.com]
Sent: August 19, 2004 2:21 AM
To: Anony Mous
Cc: pg***********@p ostgresql.org
Subject: Re: [GENERAL] select count(*) from pg_stat_activit y in V8.0.0

Anony Mous wrote:
Coming off of 7.4.3 I've always used

select count(*) from pg_stat_activit y

through the ODBC driver to obtain the number of connections to the db. I've found that with v8.0 Beta 1 that this at times has returned a value of 0
(when there is obviously still a connection). It's not repeatable, and
occurs sporadically. Does anyone have any reason as to why this would be
isolated to V8? Is this an acceptable means of obtaining the number of
connection to the database in V8 (via ODBC).


Do you have multiple live connections? My understanding of
pg_stat_activit y is that it can lag slightly behind the current state of
the system. If the only connection that is active is the one doing the
counting you could be checking before the table has been updated.

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

Nov 23 '05 #4
Anony Mous wrote:
Thanks, Richard.

I've never seen this behaviour before in 7.4.3 and indeed it is the only
connection to the back end at the time when the count is occurring. However,
it would have had the connection for at least 30 seconds before requesting a
count.

Is there a better method of obtaining the number of connections to the
backend?


Other than "ps" - no I don't think so. The 30 seconds doesn't sound
right, Tom reckoned 0.5sec which sounds plausible. Might this be the
first query you've sent on this connection?

I'm wondering if the ODBC connection isn't actually established until
you run the first query? It doesn't sound right to me, but I don't have
any of my ODBC apps to hand at the moment to check.

Could you:
1. Connect
2. SELECT 1; (or similar)
3. Sleep from 10msec => 1sec
4. SELECT * FROM pg_stat_activit y;

That way we could disable step 2 and tinker with the delay in step 3 to
see what happens.

--
Richard Huxton
Archonet Ltd

---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org

Nov 23 '05 #5
Thanks, Richard.

I've never seen this behaviour before in 7.4.3 and indeed it is the only
connection to the back end at the time when the count is occurring.
However, it would have had the connection for at least 30 seconds before
requesting a count.

Is there a better method of obtaining the number of connections to the
backend?

Thanks
Peter

-----Original Message-----
From: Richard Huxton [mailto:de*@arch onet.com]
Sent: August 19, 2004 2:21 AM
To: Anony Mous
Cc: pg***********@p ostgresql.org
Subject: Re: [GENERAL] select count(*) from pg_stat_activit y in V8.0.0

Anony Mous wrote:
Coming off of 7.4.3 I've always used

select count(*) from pg_stat_activit y

through the ODBC driver to obtain the number of connections to the db. I've found that with v8.0 Beta 1 that this at times has returned a value of 0
(when there is obviously still a connection). It's not repeatable, and
occurs sporadically. Does anyone have any reason as to why this would be
isolated to V8? Is this an acceptable means of obtaining the number of
connection to the database in V8 (via ODBC).


Do you have multiple live connections? My understanding of
pg_stat_activit y is that it can lag slightly behind the current state of
the system. If the only connection that is active is the one doing the
counting you could be checking before the table has been updated.

--
Richard Huxton
Archonet Ltd
---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddres sHere" to ma*******@postg resql.org)

Nov 23 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
3550
by: Ian T | last post by:
Hi, I've got what I think (probably incorrectly) should be a simple SELECT : Two colums with data like col1 col2 1 50 1 51 2 50
4
2868
by: jimh | last post by:
I'm not a SQL expert. I want to be able to write a stored procedure that will return 'people who bought this product also bought this...'. I have a user table that links to a transaction table that links to a transaction items table that links to the products table: (User Table) UserID Other user data
11
958
by: JoshuaF | last post by:
hello everyone i am very new to postgresql 7.3.3 and am using it on my mac G4 OS X and i am having some trouble which i hope you can help me out with some answers to my questions: 1.) How can I get a list of users currently logged into the database? Is it possible? 2) I plan on using postgresql for a posting board database, how can I search for a certain word that is in the post's topic subject header? For example if the post subject...
1
4620
by: Jaime Casanova | last post by:
Hi all, in the pg_stat_activity catalog there is a field called current_query but it is in blank when i modify the show statement stat in postgresql.conf i win nothing. what am i doing wrong? thanks in advance, Jaime Casanova (el_vigia)
2
1824
by: Rajesh Kumar Mallah | last post by:
Hi , I noticed that an entry in pg_stat_activity was existing for a long duration > 2 mins while its backend ( process corresponding to that procpid) was not running. how can it be possible ? version: 7.3.4
4
2275
by: elein | last post by:
The variable names in postgresql.conf have changed in the last several releases. I'm now confused about what variable(s) to set to show the query in pg_stat_activity. Hints? --elein ============================================================ elein@varlena.com Varlena, LLC www.varlena.com
3
1997
by: Jeff Amiel | last post by:
I ran a home-grown self continuous stress test tool against my 7.4.2 database. I banged 'ps' (running freebsd) while it was active and witnessed several of the 'back end' postgres processes exeucting queries, commits, inserts, etc....(the actual work the processes were doing was listed in the 'ps' output) however, if I checked pg_stat_activity during the same time period, I saw nothing populated in the current_query column...ever.
22
12496
by: MP | last post by:
vb6,ado,mdb,win2k i pass the sql string to the .Execute method on the open connection to Table_Name(const) db table fwiw (the connection opened via class wrapper:) msConnString = "Data Source=" & msDbFilename moConn.Properties("Persist Security Info") = False moConn.ConnectionString = msConnString moConn.CursorLocation = adUseClient moConn.Mode = adModeReadWrite' or using default...same result
0
7501
by: djflow | last post by:
Hi! II was wondering if you can help me with SQL query.. Below 7 separated select query works fine(only when they are retrieved separately) But I want to combined them together and so that i can make report from my database on the one sheet rather than querying each select statement ( I will use MS Query from the Excel) ========================================================= 1) select convert(varchar, create_date_time, 112) as Date,...
0
9689
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10495
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10269
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10032
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9085
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6811
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5469
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5597
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3764
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.