Skip to content

Instantly share code, notes, and snippets.

@jberkus
Last active January 13, 2018 06:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jberkus/06055068f02a0eab6cd3 to your computer and use it in GitHub Desktop.
Save jberkus/06055068f02a0eab6cd3 to your computer and use it in GitHub Desktop.
polling pg_stat_activity
#!/bin/bash
NUMMIN=$(($1 * 2 + 10))
CURMIN=0
while [ $CURMIN -lt $NUMMIN ]
do
psql -q -t -A -c "SELECT now() as ts, state, client_addr, count(*) as num_conn, avg(now() - query_start) as avg_query, \
max(now() - query_start) as max_query, avg(now() - xact_start) as avg_xact, \
max(now() - xact_start) as max_xact FROM pg_stat_activity GROUP BY state, client_addr" >> connstats.log
sleep 30
let CURMIN=CURMIN+1
done
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment