Last active
January 13, 2018 06:50
-
-
Save jberkus/06055068f02a0eab6cd3 to your computer and use it in GitHub Desktop.
polling pg_stat_activity
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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