인성장

[PostgreSQL] Parameter 설정 방법 본문

PostgreSQL/Admin

[PostgreSQL] Parameter 설정 방법

인성장 2024. 2. 2. 13:26
Parameter 설정 방법

 

https://checktech.tistory.com/27

 

[PostgreSQL] 주요 파라미터 역할 및 산정방법

Parameter 역할 및 산정방법 PostgreSQL 파라미터별 역할에 대해 잘 이해하고 있어야지 데이터베이스 성능 저하 문제가 나왔을 때 문제를 더욱 빠르게 파악하여 운영 간 더 좋은 성능을 낼 수 있도록 D

checktech.tistory.com

 

 

파라미터 설정 방법(1) - psql 내부에서 파라미터를 설정하는 방법

-- 파라미터 조회
SELECT name, context, unit,setting,boot_val,reset_val FROM pg_settings;

-- 파라미터 값 변경
ALTER SYSTEM SET [parameter_name]='설정값';

-- 변경한 파라미터 값 적용
-- 재기동 필요없는 파라미터 적용 시 사용
SELECT pg_reload_conf();

* pg_settings 테이블 주요 column별 설명

- name : 파라미터 이름

- context : 변경가능한 경우를 분류 (context 값이 user 등이면 reload, postmaster 면 restart 필요)

- unit : 설정값 단위

- setting : 현재 적용된 값

- bool_val : server start 할 때 설정된 값 (Default 값)

- reset_val : 현재 세션에 설정된 값

 

재기동이 필요한 파라미터의 경우 설정 후, DB restart를 해줘야 설정한 값이 적용됩니다.

 

파라미터 설정 방법(2) - postgresql.conf 파일로 파라미터를 설정하는 방법

$PG_HOME/data 디렉토리 밑에 postgresql.conf 파일을 수정하여 사용하시면 됩니다. 처음 PostgreSQL를 설치하고, DB를 운영하기 전에 서비스환경에 맞는 필요한 파라미터들을 postgresql.conf 파일에 초기설정값을 지정하여 사용하는 것을 권장드립니다. 파일내용은 아래와 같이 이루어져 있고 변경하고 싶은 파라미터의 주석을 삭제하고 값을 입력하거나, 관리 편리성을 위해 맨 하단 CUSTOMIZED OPTIONS에 입력하셔도 됩니다.

$ vi postgresql.conf
... (처음생략) ...

#------------------------------------------------------------------------------
# FILE LOCATIONS
#------------------------------------------------------------------------------

# The default values of these variables are driven from the -D command-line
# option or PGDATA environment variable, represented here as ConfigDir.

#data_directory = 'ConfigDir'           # use data in another directory
                                        # (change requires restart)
#hba_file = 'ConfigDir/pg_hba.conf'     # host-based authentication file
                                        # (change requires restart)
#ident_file = 'ConfigDir/pg_ident.conf' # ident configuration file
                                        # (change requires restart)

# If external_pid_file is not explicitly set, no extra PID file is written.
#external_pid_file = ''                 # write an extra PID file
                                        # (change requires restart)


#------------------------------------------------------------------------------
# CONNECTIONS AND AUTHENTICATION
#------------------------------------------------------------------------------

# - Connection Settings -

#listen_addresses = 'localhost'         # what IP address(es) to listen on;
                                        # comma-separated list of addresses;
                                        # defaults to 'localhost'; use '*' for all
                                        # (change requires restart)
#port = 5432                            # (change requires restart)
#max_connections = 100                  # (change requires restart)
#superuser_reserved_connections = 3     # (change requires restart)
#unix_socket_directories = '/tmp'       # comma-separated list of directories
                                        # (change requires restart)
... (중간생략) ...
#------------------------------------------------------------------------------
# RESOURCE USAGE (except WAL)
#------------------------------------------------------------------------------

# - Memory -

#shared_buffers = 128MB                 # min 128kB
                                        # (change requires restart)
#huge_pages = try                       # on, off, or try
                                        # (change requires restart)
#temp_buffers = 8MB                     # min 800kB
#max_prepared_transactions = 0          # zero disables the feature
                                        # (change requires restart)
# Caution: it is not advisable to set max_prepared_transactions nonzero unless
# you actively intend to use prepared transactions.
#work_mem = 4MB                         # min 64kB
#maintenance_work_mem = 64MB            # min 1MB
#autovacuum_work_mem = -1               # min 1MB, or -1 to use maintenance_work_mem
#max_stack_depth = 2MB                  # min 100kB
#shared_memory_type = mmap              # the default is the first option
... (중간생략) ...
#------------------------------------------------------------------------------
# WRITE-AHEAD LOG
#------------------------------------------------------------------------------

# - Settings -

#wal_level = replica                    # minimal, replica, or logical
                                        # (change requires restart)
#fsync = on                             # flush data to disk for crash safety
                                        # (turning this off can cause
                                        # unrecoverable data corruption)
#synchronous_commit = on                # synchronization level;
... (중간생략) ...

#------------------------------------------------------------------------------
# CUSTOMIZED OPTIONS
#------------------------------------------------------------------------------

# Add settings for extensions here

listen_addresses = '192.168.0.158'
port = '5432'
max_connections = '100'
superuser_reserved_connections = '10'
shared_buffers = '2GB'
temp_buffers = '4MB'
work_mem = '8MB'
maintenance_work_mem = '1GB'
wal_buffers = '30MB'
effective_cache_size = '1GB'
min_wal_size = '1GB'
max_wal_size = '16GB'
default_statistics_target = '100'
autovacuum_vacuum_scale_factor = '0.0'
autovacuum_vacuum_threshold = '20000'
wal_level = 'replica'
archive_mode = 'on'
archive_command = 'cp %p /pg_arch/%f'
archive_timeout = '120'
log_destination = 'stderr'
logging_collector = 'on'
cluster_name = 'inseong_cluster_test'

 

반응형