Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id A8A43B5DC1E for ; Wed, 24 Aug 2011 04:49:17 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 67626-02-2 for ; Wed, 24 Aug 2011 07:49:10 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from sd-17937.dedibox.fr (sd-17937.dedibox.fr [88.191.100.74]) by mail.postgresql.org (Postfix) with ESMTP id 4B7D7B5DC04 for ; Wed, 24 Aug 2011 04:49:05 -0300 (ADT) Received: from [192.168.10.3] (AMontsouris-552-1-82-6.w92-140.abo.wanadoo.fr [92.140.41.6]) by sd-17937.dedibox.fr (Postfix) with ESMTPA id CA2FC3B8F5; Wed, 24 Aug 2011 09:49:04 +0200 (CEST) Subject: Re: How to track number of connections and hosts to Postgres cluster From: Guillaume Lelarge To: Venkat Balaji Cc: pgsql-performance@postgresql.org Date: Wed, 24 Aug 2011 09:49:04 +0200 In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.0.2 (3.0.2-3.fc15) Content-Transfer-Encoding: 7bit Message-ID: <1314172144.2193.9.camel@localhost.localdomain> Mime-Version: 1.0 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.9 tagged_above=-10 required=5 tests=BAYES_00=-1.9 X-Spam-Level: X-Archive-Number: 201108/261 X-Sequence-Number: 44708 On Wed, 2011-08-24 at 13:05 +0530, Venkat Balaji wrote: > Hello Everyone, > > I am working on an alert script to track the number of connections with the > host IPs to the Postgres cluster. > > 1. I need all the host IPs making a connection to Postgres Cluster (even for > a fraction of second). You should set log_connections to on. > 2. I would also want to track number of IDLE connections, IDLE IN > TRANSACTION connections and length of the connections as well. > IDLE and IDLE in transactions are the kind of informations you get in pg_stat_activity. Length of connections, you can get it with log_disconnections. > I would be making use of pg_stat_activity and also thought of enabling > logging the host ips in the db server log files which seems to be expensive > for me (in terms of IO and logfile size). > Using pg_stat_activity won't get you really small connections. You need log_connections for that, and log_disconnections for the duration of connections. So you'll have to work on a tool that could get some informations with queries on pg_stat_activity, and that could read PostgreSQL log files. -- Guillaume http://blog.guillaume.lelarge.info http://www.dalibo.com