Witam,
Aktualnie staram się zbudować podstawę monitoringu serwerów i baz danych, z których korzystamy w firmie. Przy mysql nie było problemu ale psql to inna bajka... Serwer sam w sobie obrabia dużo zapytań i coś co w domyśle powinno generować max 10 zapytań na godzinę nie zamyka ich... Nie wiem czemu... Cały skrypt wygląda tak:
#!/bin/bash
# Try to detect the postgres user
if id postgres >/dev/null 2>&1; then
USER=*****
elif id postgres >/dev/null 2>&1; then
USER=********
else
exit 0
fi
echo '<<<postgres_sessions>>>'
echo "select current_query = '<IDLE>', count(*) from pg_stat_activity group by (current_query = '<IDLE>');" | su - $USER -c "psql -h 127.0.0.1 -p 5432 -d ****** -U ********** -A -t -F' '"
echo '<<<postgres_stat_database:sep(59)>>>'
echo 'select *, pg_database_size(datname) as "datsize" from pg_stat_database;' \
| su - $USER -c "psql -h 127.0.0.1 -p 5432 -d ****** -U ********** -A -F';'" | sed '$d'