Created
July 27, 2022 20:35
-
-
Save adamzwakk/6a2f1ceec4d355e74411d4833c800610 to your computer and use it in GitHub Desktop.
Gets running postgresql vacuums and phases ready for influxdb
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 | |
PGSQL_HOST="localhost" | |
PGSQL_PORT="5432" | |
PGSQL_DATABASE="postgres" | |
PGSQL_USERNAME="postgres" | |
export PGPASSWORD="passwd" | |
TMP_FILE="/tmp/pgsqlchk.out" | |
ERR_FILE="/tmp/pgsqlchk.err" | |
HOST=$(hostname) | |
list=`/usr/bin/psql -t -c "select pid,s.relname, v.phase from pg_stat_progress_vacuum v left join pg_catalog.pg_class s on v.relid = s.oid" 2> /dev/null` | |
if [ -z "$list" ] | |
then | |
exit 1 | |
else | |
while IFS= read -r VALUE; do | |
PHASE=`echo "$VALUE" | awk -F"|" '{print $3}' | sed 's/^[ \t]*//;s/[ \t]*$//'` | |
TABLE=`echo "$VALUE" | awk -F"|" '{print $2}' | sed 's/^[ \t]*//;s/[ \t]*$//'` | |
PSPID=`echo "$VALUE" | awk -F"|" '{print $1}' | sed 's/^[ \t]*//;s/[ \t]*$//'` | |
if [ "$PHASE" = "initializing" ] | |
then | |
PHASE=1 | |
elif [ "$PHASE" = "scanning heap" ] | |
then | |
PHASE=2 | |
elif [ "$PHASE" = "vacuuming indexes" ] | |
then | |
PHASE=3 | |
elif [ "$PHASE" = "vacuuming heap" ] | |
then | |
PHASE=4 | |
elif [ "$PHASE" = "cleaning up indexes" ] | |
then | |
PHASE=5 | |
elif [ "$PHASE" = "truncating heap" ] | |
then | |
PHASE=6 | |
elif [ "$PHASE" = "performing final cleanup" ] | |
then | |
PHASE=7 | |
fi | |
influxline="postgresql,host=${HOST},table=${TABLE},pid=${PSPID} vacuum_phase_id=${PHASE}" | |
echo $influxline | |
done <<< "$list" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment