목차
PostgreSQL을 처음 설치하면 기본 설정으로 작동한다. 하지만 하드웨어 사양에 맞춰 설정을 조정하면 성능을 크게 향상시킬 수 있다.
- 메모리 설정
- shared_buffers를 늘리면 데이터 캐시가 증가하여 쿼리 성능이 향상된다.
- work_mem을 조정하면 복잡한 쿼리나 정렬 작업이 빨라진다.
- CPU 활용
- max_parallel_workers와 max_worker_processes를 통해 여러 CPU 코어를 효율적으로 사용할 수 있다. 이는 대용량 데이터 처리를 빠르게 해준다.
- 디스크 I/O 최적화
- effective_io_concurrency를 통해 디스크 작업의 동시성을 최적화하면, 디스크 읽기/쓰기 속도가 향상된다.
- wal_buffers를 적절히 설정하면 쓰기 작업 성능이 개선된다.
이러한 설정 조정을 통해 PostgreSQL 데이터베이스의 성능을 최대한으로 끌어올릴 수 있다. 적절한 설정을 통해 서버의 하드웨어를 효율적으로 활용하여 더 빠르고 안정적인 데이터베이스 운영이 가능하다.
그냥 성능을 최대로 높이면 되는 것 아닌가?
서버 성능을 최대로 설정한다고 해서 항상 최적의 성능을 보장하는 것은 아니다.
우선, 너무 많은 자원을 할당하면 다른 애플리케이션이 필요로 하는 자원이 부족해질 수 있으며, 지나치게 높은 설정은 시스템의 불안정을 초래할 수 있다.
예를 들어, PostgreSQL의 shared_buffers를 너무 높게 설정하면, 운영 체제와 다른 애플리케이션이 사용할 메모리가 부족해질 수 있다. 일반적으로 shared_buffers는 전체 RAM의 약 25%로 설정하는 것이 권장된다고 한다.
https://postgresql.kr/docs/10/runtime-config-resource.html
혹은 work_mem을 너무 높게 설정하면, 많은 사용자가 동시에 정렬 작업을 수행할 때 메모리 부족 문제가 발생할 수 있다. 따라서 이 값을 세션 단위로 조정하는 것이 좋다.
(참조 포스팅)
https://vladmihalcea.com/postgresql-performance-tuning-settings/
https://www.timescale.com/learn/postgresql-performance-tuning-key-parameters
https://www.percona.com/blog/tuning-postgresql-database-parameters-to-optimize-performance/
마지막으로, 각 하드웨어 환경에 따라 다른 최적의 설정값이 존재한다. CPU, RAM, 디스크 I/O 등 하드웨어 사양에 따라 PostgreSQL의 성능에 영향을 미치는 설정값이 다르기도 하다.
예를 들어 내 CPU가 8코어 이상이라면 병렬 처리 값을 높일 수 있지만(max_parallel_workers), 만약 4코어 이하라면 병렬 처리를 낮추는 편이 가장 최적화하기 좋을 것이다.
https://stackify.com/postgresql-performance-tutorial/
'CS study > 데이터베이스' 카테고리의 다른 글
[인덱스] 순차 증가 값은 항상 효율적인가? (24.06.12) (0) | 2024.10.01 |
---|---|
3주차 - 랜덤I/O, 순차 I/O와 인덱스, B+Tree, B-Tree (0) | 2024.01.25 |
DataBase 2주차 정리 - SQL, DDL, DML, DCL, JOIN, 쿼리 순서 (0) | 2024.01.18 |
1주차 스터디 노트(DB, 스키마, RDBMS, Key, 제약조건) (1) | 2024.01.11 |
[Elasticsearch] RDBMS에 비해 왜 빠를까? 역인덱싱에 대해 (1) | 2023.12.17 |