[Troubleshooting] PostgreSQL shared memory resize 에러

배배·2024년 5월 2일

PostgreSQL

목록 보기
6/6

📌 PostgreSQL shared memory resize 에러



❓ 문제

  • PostgreSQL에서 Query 수행 시 shared memory resize 에러 발생
ERROR:  could not resize shared memory segment "/PostgreSQL.1966028679" to 4294967296 bytes: No space left on device



🔍 원인

  • Parallel Worker가 Leader Worker에게 결과물을 전달 할 때 shared memory 영역을 사용
  • 현재 Docker psql container의 shm_size 값을 제한 하도록 하고 있음
  • Docker의 shared memory는 한정적이지만 parallel 쿼리의 shared memory는 제한 없이 할당되면서 error가 발생



✅ 해결

  • Query 수행 시 max_parallel_workers_per_gather 파라미터 조정
	set max_parallel_workers_per_gather=4; (기본 24)
  • psql container의 shared memory max 값 조정

  1. psql docker-compose.yml의 shared memory size 수정
  
    services:
    postgresql:
      image: XXX
      container_name: psql
      ports:
        - "5432:5432"
      environment:
        - TZ=Asia/Seoul
        - PGCTLTIMEOUT=600
      volumes:
        - /etc/localtime:/etc/localtime:ro
        - /data/psql:/var/lib/postgresql/13/main
      shm_size: "32gb"
      #shm_size: "16gb"
    
  2. psql docker container 재시작
  
    $ docker-compose up -D
  
  3. postgresql.conf 파일의 shared_buffer 값 조정 (DB 메모리의 25% ~ 30%정도 권장)
  
  	#shared_buffers = '16GB'
    shared_buffers = '32GB' 	# (change requires restart)
    
  4. change requires restart 설정이므로 container 내부에서 psql 서비스 재시작이 필요함
  
  5. psql 서비스 재시작 후 적용 여부 확인
  select name, setting, source, sourcefile, sourceline from pg_settings where name = 'shared_buffers';
  
        name      | setting |       source       |               sourcefile                | sourceline
----------------+---------+--------------------+-----------------------------------------+------------
 shared_buffers | 4194304 | configuration file | /etc/postgresql/13/main/postgresql.conf |        122



🌟 REF

profile
데이터 엔지니어

0개의 댓글