Monitoring open connections - Mailing list pgsql-general

From Simon Brooke
Subject Monitoring open connections
Date
Msg-id 39645901.AD57A9EB@weft.co.uk
Whole thread Raw
Responses SQL DOMAINS in PostgreSQL  (Jesus Aneiros <aneiros@jagua.cfg.sld.cu>)
List pgsql-general
Herewith a little script to monitor open connections to Postgres
databases on Linux platforms; I wrote it while desperately debugging
some connection pooling code which was (but hopefully is not still)
breaking horribly. If it's useful to you, feel free to use or adapt.

-------------------------------- cut here
--------------------------------
#! /bin/bash

# Monitor number of open Postgres connections by user and database
# Simon Brooke <simon@jasmine.org.uk>, 6th July 2000
# Copyleft - no warranty, use it if you like it.

tmp=/tmp/wpg$$
bak=/tmp/wpg$$.bak

cat /dev/null > $tmp
cat /dev/null > $bak

while [ 1 -eq 1 ];
do
    ps auxww |\
    awk '$11 ~ "postgres" {printf( "User: %-8s; Database: %-8s\n", $13,
$14)}' > $tmp

    cmp -s $tmp $bak

    if [ $? -ne 0 ]        # there's been a change
    then
        echo ""            # new line
    date;            # report it
    sort $tmp |\
    uniq -c;
    else
    echo -n "."        # I'm still alive
    fi
    mv $tmp $bak
    sleep 10;
done
-------------------------------- cut here
--------------------------------


--
Simon Brooke, Technical Director, Weft Technology Ltd --
http://www.weft.co.uk/

    the weft is not just what binds the web: it is what makes it a web

pgsql-general by date:

Previous
From: Stephane Bortzmeyer
Date:
Subject: Re: Find all the dates in the calendar week?
Next
From: JanWieck@t-online.de (Jan Wieck)
Date:
Subject: Re: lztext and compression ratios...