꾸준한 개발일기

리눅스 :: too many clients already 오류 해결(postgresql.conf 위치, max_connections 수정 방법) 본문

Programing/리눅스

리눅스 :: too many clients already 오류 해결(postgresql.conf 위치, max_connections 수정 방법)

꾸개일 2021. 12. 3. 09:00
반응형

웹 서버에서 배치서버로 connection할 때 오류가 발생했다.

 

Caused by: org.postgresql.util.PSQLException: FATAL: sorry, too many clients already
	at org.postgresql.core.v3.ConnectionFactoryImpl.doAuthentication(ConnectionFactoryImpl.java:433) ~[postgresql-9.4.1208.jar:9.4.1208]
	at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:208) ~[postgresql-9.4.1208.jar:9.4.1208]
	at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:67) ~[postgresql-9.4.1208.jar:9.4.1208]
	at org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:216) ~[postgresql-9.4.1208.jar:9.4.1208]
	at org.postgresql.Driver.makeConnection(Driver.java:406) ~[postgresql-9.4.1208.jar:9.4.1208]

 

postgresql.conf 파일을 찾아 커넥션 수를 수정해줘야한다.

 

root 권한으로 변경

# sudo -su

환경설정이기 때문에 권한이 부여된 계정만 conf 파일을 수정할 수 있다. 루트 계정이나 해당 계정으로 권한을 변경해준다.

 

postgresql.conf 경로

# cd var/lib/pgsql/

서버마다 다르지만 sql이 설치되어있는 폴더로 이동하면 된다. 

 

해당 폴더의 파일 리스트 확인

#  ls
base              pg_ident.conf  pg_stat      pg_xact
current_logfiles  pg_logical     pg_stat_tmp  postgresql.auto.conf
global            pg_multixact   pg_subtrans  postgresql.conf

postgresql.conf 파일을 찾을 수 있다.

 

파일 백업

# cp postgresql.conf postgresql211201.conf

기존 파일을 수정하기 전에는 무.조.건. 백업을 해줘야한다. cp 명령어로 파일이름을 변경하여 복사해놓는다.

 

파일 수정

# vi postgresql.conf

파일 권한 때문에 sftp에서 파일을 받아 수정한 뒤 올릴 수 없다. vi로 수정해줘야한다.

 

vi 명령어

명령어 설명
a insert 모드로 전환
Esc + :w 저장
Esc + :wq 저장 후 종료
Esc + :q! 저장하지 않고 강제종료
/ 검색어 해당 단어로 검색

 

max_connections 수정

max_connections = 3000

100이었던 커넥션 수를 3000으로 수정해준다.

 

DB 재가동

# systemctl restart postgresql-11.service

해당 DB 서버를 재가동해준다.

 

배치서버 재가동

// tomcat stop
# cd /usr/local/tomcat-8.5/bin
# ./shutdown.sh

// tomcat start
# cd /usr/local/tomcat-8.5/bin
# ./startup.sh

배치서버까지 재가동을 해준 뒤 프로그램을 실행시키면 too many clients 오류는 해결된다.

반응형
Comments