본문 바로가기

CS study/데이터베이스

[DB]psql 하드웨어 성능 튜닝 (24.07.10)

목차

    PostgreSQL을 처음 설치하면 기본 설정으로 작동한다. 하지만 하드웨어 사양에 맞춰 설정을 조정하면 성능을 크게 향상시킬 수 있다.

    1. 메모리 설정
      • shared_buffers를 늘리면 데이터 캐시가 증가하여 쿼리 성능이 향상된다.
      • work_mem을 조정하면 복잡한 쿼리나 정렬 작업이 빨라진다.
    2. CPU 활용
      • max_parallel_workers와 max_worker_processes를 통해 여러 CPU 코어를 효율적으로 사용할 수 있다. 이는 대용량 데이터 처리를 빠르게 해준다.
    3. 디스크 I/O 최적화
      • effective_io_concurrency를 통해 디스크 작업의 동시성을 최적화하면, 디스크 읽기/쓰기 속도가 향상된다.
      • wal_buffers를 적절히 설정하면 쓰기 작업 성능이 개선된다.

    이러한 설정 조정을 통해 PostgreSQL 데이터베이스의 성능을 최대한으로 끌어올릴 수 있다. 적절한 설정을 통해 서버의 하드웨어를 효율적으로 활용하여 더 빠르고 안정적인 데이터베이스 운영이 가능하다.

    https://pgtune.leopard.in.ua/

     

    PGTune - calculate configuration for PostgreSQL based on the maximum performance for a given hardware configuration

     

    pgtune.leopard.in.ua

     

    그냥 성능을 최대로 높이면 되는 것 아닌가?

    서버 성능을 최대로 설정한다고 해서 항상 최적의 성능을 보장하는 것은 아니다.

    우선, 너무 많은 자원을 할당하면 다른 애플리케이션이 필요로 하는 자원이 부족해질 수 있으며, 지나치게 높은 설정은 시스템의 불안정을 초래할 수 있다.

     

    예를 들어, PostgreSQL의 shared_buffers를 너무 높게 설정하면, 운영 체제와 다른 애플리케이션이 사용할 메모리가 부족해질 수 있다. 일반적으로 shared_buffers는 전체 RAM의 약 25%로 설정하는 것이 권장된다고 한다.

     

    https://postgresql.kr/docs/10/runtime-config-resource.html

     

    19.4. 리소스 소비

    19.4.4. 비용 기반 청소 지연 VACUUM 및 ANALYZE 명령 실행 중에는 다양한 I/O 명령을 수행하는 데 드는 예상 비용을 추적하는 내부 카운터가 시스템에서 유지된다. 누적 비용이 제한값(vacuum_cost_limit으

    postgresql.kr

     

    혹은 work_mem을 너무 높게 설정하면, 많은 사용자가 동시에 정렬 작업을 수행할 때 메모리 부족 문제가 발생할 수 있다. 따라서 이 값을 세션 단위로 조정하는 것이 좋다.

    (참조 포스팅)

    https://vladmihalcea.com/postgresql-performance-tuning-settings/

     

    PostgreSQL Performance Tuning Settings - Vlad Mihalcea

    Introduction In this article, we are going to explore various PostgreSQL performance tuning settings that you might want to configure since the default values are not suitable for a QA or production environment. As explained in this PostgreSQL wiki page, t

    vladmihalcea.com

     

    https://www.timescale.com/learn/postgresql-performance-tuning-key-parameters

     

    PostgreSQL Performance Tuning: Key Parameters | Timescale

    A deep dive into the key parameters to improve your PostgreSQL performance tuning and scale your database.

    www.timescale.com

     

    https://www.percona.com/blog/tuning-postgresql-database-parameters-to-optimize-performance/

     

    PostgreSQL Performance Tuning: Optimizing Database Parameters for Maximum Efficiency

    In this blog post, we cover PostgreSQL performance tuning and establish some basic guidelines for setting database parameters to enhance PostgreSQL performance.

    www.percona.com

     

    마지막으로, 각 하드웨어 환경에 따라 다른 최적의 설정값이 존재한다. CPU, RAM, 디스크 I/O 등 하드웨어 사양에 따라 PostgreSQL의 성능에 영향을 미치는 설정값이 다르기도 하다.

    예를 들어 내 CPU가 8코어 이상이라면 병렬 처리 값을 높일 수 있지만(max_parallel_workers), 만약 4코어 이하라면 병렬 처리를 낮추는 편이 가장 최적화하기 좋을 것이다.

    https://stackify.com/postgresql-performance-tutorial/

     

    PostgreSQL Performance Tuning Tutorial - Stackify

    Setting up the database correctly is just the first step in PostgreSQL performance tuning. Take PostgreSQL performance optimization to the next level.

    stackify.com