Skip to content

Instantly share code, notes, and snippets.

@tchellomello
Created November 30, 2016 22:21
Show Gist options
  • Select an option

  • Save tchellomello/1f69a1763daf2098de211da0d6e86ed2 to your computer and use it in GitHub Desktop.

Select an option

Save tchellomello/1f69a1763daf2098de211da0d6e86ed2 to your computer and use it in GitHub Desktop.
Monitor active queries for Satellite 5
#!/bin/bash
export PATH="/bin:/sbin:/usr/bin:/usr/sbin:/opt/rh/postgresql92/root/usr/bin"
PG_VERSION=$(su - postgres -c "psql -c 'select version();'" | grep "^ PostgreSQL" | cut -f 3 -d ' ' | cut -f1 -d'.')
if [ $PG_VERSION -eq 9 ]; then
echo "SELECT query,xact_start,query_start FROM pg_stat_activity GROUP BY query,xact_start,query_start;" | spacewalk-sql --select-mode -
elif [ $PG_VERSION -eq 8 ]; then
echo "SELECT current_query, query_start, backend_start, datid, usesysid, procpid, waiting from pg_stat_activity;" | spacewalk-sql --select-mode -
#exclude the IDLEs
echo "SELECT current_query, query_start, backend_start, datid, usesysid, procpid, waiting from pg_stat_activity where current_query not like '%IDLE%';" | spacewalk-sql --select-mode -
else
echo "Sorry, I could not determine the PostgreSQL version"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment