관리 메뉴

아이짱구

PostgreSQL Configuration 본문

database/postgresql

PostgreSQL Configuration

아이짱구 2016. 8. 29. 11:42

KT 전사 표준 데이터베이스로 PPAS, PostgreSQL이 지정되면서 다시금 사용하는데, Oracle 못지 않은 기능, 성능, 안정성을 자랑한다.

MySQL 보다 더 좋은 성능이 자주 보고 되곤 하는데, 우리나라는 유행이 지나가버렸고, 일본에서는 많이 사용되고 있다.


PostgreSQL을 사용하면서 가장 기본적인 튜닝 포인트에 대해 간략히 정리한다.

해당 내용은 postgresql.conf 파일에 환경설정을 해야 적용이 된다.


1. 공유 버퍼( shared_buffers ) 조정


RDBMS에서 가장 기본인 Shared Buffer 값 조정

PostgreSQL 도 여느 RDBMS와 마찬가지로 데이터베이스에 엑세스를 시도하면, 먼저 디스크에서 필요한 데이터를 공유 버퍼로 먼저 읽어 들인다.  그리고, 공유 버퍼에서 데이터를 읽고, 쓰기를 처리한다. 이후, 동일한 데이터 엑세스에 대해서는 공유버퍼에서 읽어 들여, 느린 디스크 엑세스를 줄여 성능을 확보 할 수 있는 기본적인 튜닝이다.

기본적인 디스크 캐싱이라 보면 된다.


공유 버퍼의 크기는 기본 32M 이지만, 대략 서버 메모리 기준으로 1/4 ~ 1/2 정도로 할당한다.


# - Memory - 
# shared_buffers = 32MB # default
   shared_buffers = 2GB   # DB 서버의 메모리가 32GB 라면, 4GB 또는 시스템 안정화를 위해 2GB 정도로 세팅


공식 문서내 내용 참고

 

shared_buffers (integer)

Sets the amount of memory the database server uses for shared memory buffers. The default is typically 32 megabytes (32MB), but might be less if your kernel settings will not support it (as determined during initdb). This setting must be at least 128 kilobytes. (Non-default values of BLCKSZ change the minimum.) However, settings significantly higher than the minimum are usually needed for good performance. This parameter can only be set at server start.

If you have a dedicated database server with 1GB or more of RAM, a reasonable starting value for shared_buffers is 25% of the memory in your system. There are some workloads where even large settings for shared_buffers are effective, but because PostgreSQL also relies on the operating system cache, it is unlikely that an allocation of more than 40% of RAM to shared_buffers will work better than a smaller amount. Larger settings for shared_buffers usually require a corresponding increase in checkpoint_segments, in order to spread out the process of writing large quantities of new or changed data over a longer period of time.

 

On systems with less than 1GB of RAM, a smaller percentage of RAM is appropriate, so as to leave adequate space for the operating system. Also, on Windows, large values for shared_buffersaren't as effective. You may find better results keeping the setting relatively low and using the operating system cache more instead. The useful range for shared_buffers on Windows systems is generally from 64MB to 512MB.


2. 트랜잭션 로그 버퍼 ( wal_buffers )


공유 버퍼 조정으로 디스크 캐싱하여 성능이 확보 되었다면, 신뢰성을 보장하는 트랜잭션 로그에 대한 설정이 필요하다.

데이터를 업데이트 할 때 어떤 변경을 할 것 인지를 남기는 로그이며, PostgreSQL에서는 WAL(Write Ahead Log)이라고 명칭한다.

손실된 데이터 복원에 중요한 역할을 한다.


config파일에서 wal_buffers 값 변경, 일반적으로 shared_buffers의 1/32 크기로 지정한다.

postgresql.conf 내 wal_buffers 설정


#wal_buffers = 64MB        # Shared Buffers가 2GB 이므로 1/32


3. 체크 포인트 세그먼트 ( checkpoint_segments )


디스크에 기록 안 된 공유 버퍼의 페이지를 기록하는 부분의 설정으로 디폴트는 3세그먼트 이므로, 3*16MB, 즉, 48MB가 쌓이면 디스크에 기록한다는 의미이다.


운영하면서 시스템 상황과 통계치를 근거로 설정. DISK I/O 빈도를 줄여 성능 향상에 도움이 된다.

postgresql.conf 내 Checkpoints 부분 설정


# - Checkpoints -

#checkpoint_segments = 3                # in logfile segments, min 1, 16MB each

 

Reference


PostgreSQL Online Document


출처: Data First

Comments