[PostgreSQL] "치명적오류: 최대 동시 접속자 수를 초과했습니다" 오류 발생 원인과 해결 방법

2024. 12. 20. 22:08·디버깅∕오류해결
728x90

문제 현상

서버에서 Connection Error 가 나타나고 정상적으로 동작하지 않았다.

[Hikari Pool - Common] - Connection is not available, request timed out after 30007ms.

 

디버그 모드로 확인해보니 postgresql 동시 접속자 수를 초과했다는 에러가 발생한다.

[Hikari Pool - Query] - Exception during pool initialization.
org.postgresql.util.PSQLException: 치명적오류: 최대 동시 접속자 수를 초과했습니다.

혹은

org.postgresql.util.PSQLException: FATAL: sorry, too many clients already.

 

 

문제 원인

Database 에 설정된 max_connection 을 모두 사용해서 추가 connection 을 생성할 수 없어서 발생한 오류이다.

* max_connection 확인 SQL

show max_connections;

 

 

해결방법

Database 의 max_connection 설정을 늘린다.

※ Database 설정 값을 수정해야 하므로 PostgreSQL 재시작이 필요하다

 

PostgreSQL의 기본 max_connections 설정값과 이를 조정하는 방법에 대한 자세한 설명은 How to Increase Max Connections in PostgreSQL 를 참고하세요.

 

How to Increase Max Connections in PostgreSQL - Ubiq BI

PostgreSQL supports 100 concurrent connections. Here's how to increase max connections in PostgreSQL and handle more clients.

ubiq.co

 

1. PostgreSQL 설정 파일을 연다.

설정 파일 위치를 모를 경우, `show config_file;` 을 실행하여 파일 위치를 파악한다.

 

2. max_connections 설정 값을 수정한다.

max_connections = 200

기존 100 에서 200으로 늘려주었다.

 

3. PostgreSQL 서버를 재시작한다.

sudo service restart postgresql

 

서비스를 재실행하려고 하자 에러가 발생했다.

The service command supports only basic LSB actions (start, stop, restart, try-restart, reload, force-reload, status). For other actions, please try to use systemctl.

 

서비스 명령어를 잘못 입력했는지 systemctl 을 사용하라고 한다.

* postgresql 관련 systemctl 명령어 조회

systemctl list-units|grep postgresql

 

조회해보니 postresql  이 아닌 postgresql-12.service 여서 정정하여 명령어를 수행했다.

systemctl restart postgresql-12.service

 

4. max_connections 설정 값을 증가시킨 뒤, 정상적으로 DB connection 이 맺어지는 것을 확인했다.

 

 

대안방법

단순히 max_connections를 늘리는 것 외에도, 상황에 따라 다음과 같은 방법들을 고려해볼 수 있다.

  • Connection Pool 크기 조정
    • HikariCP와 같은 Connection Pool을 사용 중이라면, Pool 크기 설정을 최적화하여 데이터베이스에 대한 연결 요청을 효율적으로 관리할 수 있다.
    • 예: maximumPoolSize 값을 조정하여 필요한 만큼의 연결만 유지
  • 비효율적인 연결 요청 최소화
    • 애플리케이션 코드에서 불필요하게 많은 연결을 생성하지 않도록 최적화한다.
    • 예: 사용하지 않는 연결을 즉시 반환하거나, 장기 실행 쿼리를 분리하여 적정 수준의 연결 수를 유지

 


유용한 참고 링크
https://stackoverflow.com/questions/2757549/org-postgresql-util-psqlexception-fatal-sorry-too-many-clients-already

 

 

추가적인 질문이 있다면 댓글로 남겨주세요.

 

728x90
저작자표시 비영리 동일조건 (새창열림)

'디버깅∕오류해결' 카테고리의 다른 글

[JAVA] Driver does not support get/set network timeout for connections. (oracle.jdbc.driver.T4CConnection.getNetworkTimeout()I)  (0) 2025.04.02
[Tibero DB] JDBC-8033:Specified schema object was not found. 오류 발생 원인과 해결 방법  (0) 2025.01.07
[IntelliJ] No candidates found for method call plugins 오류 해결(Gradle 프로젝트)  (0) 2024.10.11
[Oracle] "ORA-00933: SQL 명령어가 올바르게 종료되지 않았습니다" 오류 발생 원인과 해결 방법  (0) 2024.08.18
[IntelliJ - Gradle build] error: package javax.xml.bind does not existimport javax.xml.bind.DatatypeConverter;  (0) 2024.05.20
'디버깅∕오류해결' 카테고리의 다른 글
  • [JAVA] Driver does not support get/set network timeout for connections. (oracle.jdbc.driver.T4CConnection.getNetworkTimeout()I)
  • [Tibero DB] JDBC-8033:Specified schema object was not found. 오류 발생 원인과 해결 방법
  • [IntelliJ] No candidates found for method call plugins 오류 해결(Gradle 프로젝트)
  • [Oracle] "ORA-00933: SQL 명령어가 올바르게 종료되지 않았습니다" 오류 발생 원인과 해결 방법
heestory217
heestory217
Done is better than Perfect! 좌충우돌 개발일지💻
    250x250
  • heestory217
    Heello World
    heestory217
  • 전체
    오늘
    어제
    • 분류 전체보기 (120)
      • 컴퓨터일반 (0)
      • WEB (1)
      • JAVA (3)
      • Python (9)
      • C (1)
      • DataBase (17)
        • Oracle (2)
        • MySQL (9)
        • SAP HANA (4)
        • PostgreSQL (0)
      • 디버깅∕오류해결 (14)
      • 코딩테스트 (54)
        • 자료구조∕알고리즘 (3)
      • 정보처리기사 (10)
      • Git∕GitHub (7)
      • 기타 (3)
  • 블로그 메뉴

    • 홈
    • 태그
    • 방명록
  • 링크

  • 공지사항

  • 인기 글

  • 태그

    hashmap sort
    treemap
    Sort a HashMap in Java
    정처기 수제비 데일리 문제
    treeset
    정처기 수제비 실기문제
    MySQL
    SAP HANA Studio
    파이썬 포맷팅
    정처기 실기
    Guava library
    정처기 실기 예상문제
    HashMap
    인텔리제이
    IntelliJ
    코딩테스트
    프로그래머스 카카오
    정처기 수제비
    leetcode
    배열 정렬하기
  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.1
heestory217
[PostgreSQL] "치명적오류: 최대 동시 접속자 수를 초과했습니다" 오류 발생 원인과 해결 방법
상단으로

티스토리툴바