19 lines
912 B
Bash
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Общее количество подключений
psql -U postgres -c "SELECT count(*) FROM pg_stat_activity;"
# Использование лимита подключений
psql -U postgres -c "SELECT count(*), max_connections FROM pg_stat_activity, (SELECT setting::int as max_connections FROM pg_settings WHERE name='max_connections') mc GROUP BY max_connections;"
# Проверка системных ресурсов
top -p $(pgrep -d',' -f "postgres:")
free -h
iostat -x 1
# Следим за новыми подключениями с определенного IP
tail -f postgresql-Tue.log | grep "10.7.90.30"
# Или более детальный мониторинг
tail -f postgresql-Tue.log | awk '/10.7.90.30/ {print strftime("%Y-%m-%d %H:%M:%S"), $0}'
# Считаем частоту подключений
grep "10.7.90.30" postgresql-Tue.log | grep "connection received" | wc -l