Skip to content

Instantly share code, notes, and snippets.

@collinpeters
Created February 14, 2015 12:53
Show Gist options
  • Save collinpeters/0ca5418cd49507fe3d3b to your computer and use it in GitHub Desktop.
Save collinpeters/0ca5418cd49507fe3d3b to your computer and use it in GitHub Desktop.
Command line version of pgAdmin server status window
#!/bin/sh
QUERY="\
SELECT count(*), waiting, age(now(), MAX(query_start)) as max_query_age, age(now(), MAX(backend_start)) as max_backend_start_age, age(now(), MAX(xact_start)) as max_xact_start_age, current_query \
FROM pg_stat_activity \
WHERE datname <> 'postgres' \
AND current_query NOT LIKE '%current_query%' \
GROUP BY datname, current_query, waiting"
DEST_HOST=$1
DEST_DB=$2
DEST_USER=$3
if [ -z $DEST_HOST ]; then
echo "No destination host specified.";
echo "usage: ./pg_server_status <host> <database> <user>";
exit;
fi
if [ -z $DEST_DB ]; then
echo "No destination database specified.'";
echo "usage: ./pg_server_status <host> <database> <user>";
exit;
fi
if [ -z $DEST_USER ]; then
echo "No destination user specified.";
echo "usage: ./pg_server_status <host> <database> <user>";
exit;
fi
psql -h $DEST_HOST -d $DEST_DB -U $DEST_USER -c "$QUERY"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment