728x90
idle 및 idle in transaction 이 쌓여있는 경우 max_connection 을 초과하기 전에는 db안에서 정리가 가능함.
초과한 경우에는 프로세스 킬로 죽여야함
--------------------------------------
DB 접속이 가능한 경우
- pg_terminate_backend() 로 정리
1개 세션만 정리
select pg_terminate_backend(pid명);
idle 세션 전체 정리
select pg_terminate_backend(pid) from pg_stat_activity where state = 'idle';
idle 및 idle in transaction 모두 정리
select pg_terminate_backend(pid) from pg_stat_activity where state in ('idle', 'idle in transaction');
-------------------------------------
접속 session이 max_connections를 초과하여 DB 접속이 불가능 한 경우
- 한번에 명령어 다 실행하지 말고 어떤게 잡히는지 확인 후 마지막 kill을 붙일 것
ps -ef | grep postgres | grep -v grep | awk '{print $2}' | xargs kill
728x90
'IT 관련 > PostgreSQL' 카테고리의 다른 글
| rhel9.2 repo + postgresql16 install (0) | 2026.04.07 |
|---|---|
| [PostgreSQL] 설정된 max_connections 대비 현재 연결 Session 비율 확인 (0) | 2026.02.23 |
| [PostgreSQL] pgbench 테스트 하는법 (0) | 2025.09.15 |
| [PostgreSQL] rhel8.7 에서 PostgreSQL-16 설치하는 법 (0) | 2025.09.11 |
| [PostgreSQL] rhel7.9 에서 PostgreSQL-15 설치하는 법 (0) | 2025.09.11 |