pgtop, display PostgreSQL processes in `top' style

Lists: pgsql-announcepgsql-sql
From: Cosimo Streppone <cosimo(at)streppone(dot)it>
To: pgsql-announce(at)postgresql(dot)org
Cc: "DBD:"(at)svr1(dot)postgresql(dot)org:Pg list <dbdpg-general(at)gborg(dot)postgresql(dot)org>, pgsql-sql(at)postgresql(dot)org
Subject: pgtop, display PostgreSQL processes in `top' style
Date: 2005-04-30 22:10:30
Message-ID: 42740256.4090200@streppone.it
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-announce pgsql-sql

Hi everybody,

I'm currently working on something like a `mytop' clone,
also written in Perl with DBI + DBD::Pg interface.

mytop is a command line utility that displays mysql
server status and clients connected modeled after
`top' unix utility. (http://mytop.sourceforge.net).

What I'd like to achieve is something like that, but
for PostgreSQL, of course.
Now the project is in the very early stages, but it
already does something useful with Pg backend versions 7.2+
with stats enabled. Obviously, it looks at pg_stat*
relations to extract some useful information.

There are some things that are nice in `mytop', and I
think it would be nice to have also in `pgtop', but I
don't know how to replicate them:

1) is it possible to know Pg backend uptime with
SQL queries? Or must I look at postmaster.pid file?
or even something else?

2) how can I know the ip addresses/hostnames of clients
connecting to server?

3) Is there a way to know the number of queries performed
against Pg backend (by each client)? Can I distinguish
between selects / updates / inserts / copy / ... ?

If you want to take a look at it, point your
browser at http://search.cpan.org/dist/pgtop .

--
Cosimo


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Cosimo Streppone <cosimo(at)streppone(dot)it>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: pgtop, display PostgreSQL processes in `top' style
Date: 2005-05-02 03:04:49
Message-ID: 9988.1115003089@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-announce pgsql-sql

Cosimo Streppone <cosimo(at)streppone(dot)it> writes:
> 1) is it possible to know Pg backend uptime with
> SQL queries? Or must I look at postmaster.pid file?
> or even something else?

I suppose you mean postmaster uptime, not the lifespan of your own
connection. We don't track that at the moment, but IIRC there is
a patch in the queue to provide a function that returns this for 8.1.
For now you could perhaps look at "ps" output to see how long the
postmaster process has been running, but that's surely ugly and fraught
with pitfalls ...

Interesting thought here: should we track the postmaster process uptime,
or the time since the last database restart? Not the same at all.
You could argue that from a reliability standpoint the latter is the
interesting number.

> 2) how can I know the ip addresses/hostnames of clients
> connecting to server?

You can't (again, unless you want to parse "ps" output). But I think
someone has submitted a patch to add such columns to the
pg_stat_activity view. We need to figure out whether the visibility
of these columns needs to be restricted for security, but pending that
discussion it'll probably be in 8.1 in some form.

> 3) Is there a way to know the number of queries performed
> against Pg backend (by each client)? Can I distinguish
> between selects / updates / inserts / copy / ... ?

Nope, and nope. We could perhaps teach the stats collector to count
querystrings it's received from each backend, which'd answer the first
one to a reasonable extent. I'm unconvinced that we should expend the
overhead to be able to do the second.

regards, tom lane


From: Enrico Weigelt <weigelt(at)metux(dot)de>
To: pgsql-sql <pgsql-sql(at)postgresql(dot)org>
Subject: Re: pgtop, display PostgreSQL processes in `top' style
Date: 2005-05-02 03:55:53
Message-ID: 20050502035553.GF24546@nibiru.borg.metux.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-announce pgsql-sql

* Cosimo Streppone <cosimo(at)streppone(dot)it> wrote:

Hi,

> I'm currently working on something like a `mytop' clone,
> also written in Perl with DBI + DBD::Pg interface.
>
> mytop is a command line utility that displays mysql
> server status and clients connected modeled after
> `top' unix utility. (http://mytop.sourceforge.net).

Great thing.

I'd like to invest some time in it, but I'd prefer coding
it in java for several reasons.

Did you set up an mailing list for that project ?
(if not, I could offer to host it - its just some keystrokes
away for me)

cu
--
---------------------------------------------------------------------
Enrico Weigelt == metux IT service
phone: +49 36207 519931 www: http://www.metux.de/
fax: +49 36207 519932 email: contact(at)metux(dot)de
---------------------------------------------------------------------
Realtime Forex/Stock Exchange trading powered by postgresSQL :))
http://www.fxignal.net/
---------------------------------------------------------------------


From: Markus Schaber <schabi(at)logix-tt(dot)com>
To: Cosimo Streppone <cosimo(at)streppone(dot)it>
Cc: pgsql-announce(at)postgresql(dot)org, "\"\"DBD:\"(at)svr1(dot)postgresql(dot)org\"(at)logix-tt(dot)com:Pg list" <dbdpg-general(at)gborg(dot)postgresql(dot)org>, pgsql-sql(at)postgresql(dot)org
Subject: Re: [ANNOUNCE] pgtop, display PostgreSQL processes in `top' style
Date: 2005-05-02 22:09:56
Message-ID: 4276A534.7060607@logix-tt.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-announce pgsql-sql

Hi, Cosimo,

Cosimo Streppone wrote:

> 1) is it possible to know Pg backend uptime with
> SQL queries? Or must I look at postmaster.pid file?
> or even something else?

In contrib, there's a function caled backend_pid() defined in
misc_utils.sql, it may be helpful for you.

markus


From: David Wheeler <david(at)kineticode(dot)com>
To: Cosimo Streppone <cosimo(at)streppone(dot)it>
Cc: pgsql-sql(at)postgresql(dot)org, Pg list <dbdpg-general(at)gborg(dot)postgresql(dot)org>
Subject: Re: [Dbdpg-general] [ANNOUNCE] pgtop, display PostgreSQL processes in `top' style
Date: 2005-05-02 23:23:29
Message-ID: 066EC6F2-CB44-44E9-AE40-6969D3851F8C@kineticode.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-announce pgsql-sql

On Apr 30, 2005, at 15:10 , Cosimo Streppone wrote:

> 1) is it possible to know Pg backend uptime with
> SQL queries? Or must I look at postmaster.pid file?
> or even something else?

I think that the PID file is your best bet.

> 2) how can I know the ip addresses/hostnames of clients
> connecting to server?

I believe that that information is in pg_stat_activity. See:

http://www.postgresql.org/docs/current/static/monitoring.html

> 3) Is there a way to know the number of queries performed
> against Pg backend (by each client)? Can I distinguish
> between selects / updates / inserts / copy / ... ?

I think so, but you have to enable some postgresql.conf settings to
get that information logged.

http://www.postgresql.org/docs/8.0/static/runtime-config.html

Regards,

David


From: Jeff - <threshar(at)torgo(dot)978(dot)org>
To: Markus Schaber <schabi(at)logix-tt(dot)com>
Cc: Cosimo Streppone <cosimo(at)streppone(dot)it>, pgsql-announce(at)postgresql(dot)org, pgsql-sql(at)postgresql(dot)org
Subject: Re: [ANNOUNCE] pgtop, display PostgreSQL processes in `top' style
Date: 2005-05-04 14:28:19
Message-ID: 8721B090-C082-4860-88F3-CBD60EE4D4D0@torgo.978.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-announce pgsql-sql


On May 2, 2005, at 6:09 PM, Markus Schaber wrote:
>
>> 1) is it possible to know Pg backend uptime with
>> SQL queries? Or must I look at postmaster.pid file?
>> or even something else?
>>
>
> In contrib, there's a function caled backend_pid() defined in
> misc_utils.sql, it may be helpful for you.
>
> markus
>

I wrote a small util called "pgtop" that does a top style listing on
PG in terms of cpu. I also have one called pgiomonitor (that is on
pgfoundry and mostly done) that does the same but shows you which
tables are producing the most IO)

http://postgresql.jefftrout.com/pgtop.pl

it only runs on linux and it must run on the same box as pg itself.
You may want to look at it and see if you can get anything good out
of it.

queries / second is tricky. You could look at my pgspy utility but
it is in C. It can give you queries / second data
--
Jeff Trout <jeff(at)jefftrout(dot)com>
http://www.jefftrout.com/
http://www.stuarthamm.net/