728x90
# 1. max_connections 값 가져오기
MAX_CONN=$(psql -Atc "show max_connections;")
# 2. 현재 프로세스 개수 가져오기 (작성하신 명령어 활용)
CUR_CONN=$(ps -ef | grep postgres: | egrep -v '(grep|logger|checkpointer|background|walwriter|autovacuum|pg_auto_failover|logical|walsender)' | wc -l)
# 3. awk를 이용한 백분율 계산 (소수점 둘째 자리까지)
usage_percent=$(awk "BEGIN {printf \"%.2f\", ($CUR_CONN / $MAX_CONN) * 100}")
echo "max_connections : $MAX_CONN"
echo "현재 연결 Session : $CUR_CONN"
echo "현재 연결 비율: $usage_percent% ($CUR_CONN/$MAX_CONN)"
728x90
'IT 관련 > PostgreSQL' 카테고리의 다른 글
| rhel9.2 repo + postgresql16 install (0) | 2026.04.07 |
|---|---|
| [PostgreSQL] idle session 정리 (pg_terminate_backend(pid) / 프로세스 kill (0) | 2026.02.10 |
| [PostgreSQL] pgbench 테스트 하는법 (0) | 2025.09.15 |
| [PostgreSQL] rhel8.7 에서 PostgreSQL-16 설치하는 법 (0) | 2025.09.11 |
| [PostgreSQL] rhel7.9 에서 PostgreSQL-15 설치하는 법 (0) | 2025.09.11 |