PostgreSQL | PostgreSQL 설정 파일 | postgresql.conf 파일 설정 방법

postgresql.conf 파일은 PostgreSQL에 대한 기본 설정하는 파일이다. 여기에서는 postgresql.conf 파일의 설정 방법에 대해 설명한다.

postgresql.conf 파일 위치

postgresql.conf은 기본적으로 PostgreSQL을 설치한 data 디렉터리에 저장되어 있다.

C:\Program Files\PostgreSQL\12\data>dir
 C 드라이브의 볼륨에는 이름이 없습니다.
 볼륨 일련 번호: XXXX-XXXX

 C:\Program Files\PostgreSQL\12\data 디렉터리

2020-07-08  오전 12:00    <DIR>          .
2020-07-08  오전 12:00    <DIR>          ..
2020-07-08  오전 12:28    <DIR>          base
2020-07-08  오전 12:00                45 current_logfiles
2020-07-08  오전 12:20    <DIR>          global
2020-07-08  오전 12:00    <DIR>          log
2020-03-10  오전 12:24    <DIR>          pg_commit_ts
2020-03-10  오전 12:24    <DIR>          pg_dynshmem
2020-03-10  오전 12:24             4,156 pg_hba.conf
2020-03-10  오전 12:24             1,678 pg_ident.conf
2020-07-08  오전 12:38    <DIR>          pg_logical
2020-03-10  오전 12:24    <DIR>          pg_multixact
2020-07-07  오후 11:20    <DIR>          pg_notify
2020-03-10  오전 12:24    <DIR>          pg_replslot
2020-03-10  오전 12:24    <DIR>          pg_serial
2020-03-10  오전 12:24    <DIR>          pg_snapshots
2020-07-07  오후 11:20    <DIR>          pg_stat
2020-07-08  오후 11:35    <DIR>          pg_stat_tmp
2020-03-10  오전 12:24    <DIR>          pg_subtrans
2020-03-10  오전 12:24    <DIR>          pg_tblspc
2020-03-10  오전 12:24    <DIR>          pg_twophase
2020-03-10  오전 12:24                 3 PG_VERSION
2020-03-10  오전 12:24    <DIR>          pg_wal
2020-03-10  오전 12:24    <DIR>          pg_xact
2020-03-10  오전 12:24                90 postgresql.auto.conf
2020-03-10  오전 12:24            27,377 postgresql.conf <------------- 여기 저장되어 있다.
2020-07-07  오후 11:20                91 postmaster.opts
2020-07-07  오후 11:20                70 postmaster.pid
               8개 파일              33,510 바이트
              20개 디렉터리  424,537,530,368 바이트 남음

C:\Program Files\PostgreSQL\12\data>

postgresql.conf 파일은 텍스트 파일으로 되어 있어, 내용을 확인하거나 편집하려면 텍스트 편집기에서 파일을 열 수 있다.

# -----------------------------
# PostgreSQL configuration file
# -----------------------------
#
# This file consists of lines of the form:
#
#   name = value
#
# (The "=" is optional.)  Whitespace may be used.  Comments are introduced with
# "#" anywhere on a line.  The complete list of parameter names and allowed
# values can be found in the PostgreSQL documentation.
#
# The commented-out settings shown in this file represent the default values.
# Re-commenting a setting is NOT sufficient to revert it to the default value;
# you need to reload the server.
#
# This file is read on server startup and when the server receives a SIGHUP
# signal.  If you edit the file on a running system, you have to SIGHUP the
# server for the changes to take effect, run "pg_ctl reload", or execute
# "SELECT pg_reload_conf()".  Some parameters, which are marked below,
# require a server shutdown and restart to take effect.
#
# Any parameter can also be given as a command-line option to the server, e.g.,
# "postgres -c log_connections=on".  Some parameters can be changed at run time
# with the "SET" SQL command.
#
# Memory units:  kB = kilobytes        Time units:  ms  = milliseconds
#                MB = megabytes                     s   = seconds
#                GB = gigabytes                     min = minutes
#                TB = terabytes                     h   = hours
#                                                   d   = days

... 이하 생략 ...

postgresql.conf 설정

각 항목은 “매개 변수 이름 = 설정 값” 형식으로 되어 있다. 예를 들어 postgresql.conf 파일을 보면 다음과 같은 내용을 볼 수 있다.

# - Connection Settings -

listen_addresses = '*'		# 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)

첫 번째 listen_addresses 매개 변수는 PostgreSQL에 대한 클라이언트의 연결을 허용 할 호스트와 IP 주소를 설정한다. 현재는 '*'가 설정되어 있으며, 모든 클라이언트의 연결을 허용한다는 것을 뜻한다. (실제 어떤 데이터베이스에 연결을 허용할지 등의 자세한 설정은 pg_hba.conf 파일로 설정한다. 이 설정은 그 이전 단계이다.)

# 다음에 작성된 문장은 모두 주석으로 처리된다. 설정에 대한 주석을 작성하거나 파라메타에 대한 설정을 해제할 경우에 사용된다. 예를 들어 설정 파일을 보면 다음과 같은 내용이 있다.

# - Authentication -

#authentication_timeout = 1min		# 1s-600s
#password_encryption = md5		# md5 or scram-sha-256
#db_user_namespace = off

매개 변수에 대한 설명이 있지만 앞에 #이 있기 때문에 현재는 주석이 되고 설정이 되어 있지 않는다. 매개 변수에 대한 설정을 할 경우 첫 번째 #을 제거하고 필요에 따라 값을 변경하면 된다. (물론 #이 붙은 문장은 그 상태로 처음부터 기술해도 상관 없다). 예를 들어, authentication_timeout 매개 변수에 대한 설정을 해보자.

# - Authentication -

authentication_timeout = 1min		# 1s-600s
#password_encryption = md5		# md5 or scram-sha-256
#db_user_namespace = off

설정 내용을 변경하는 경우에는 PostgreSQL을 다시 시작 하지 않으면 설정 내용이 반영되지 않는 것과 바로 반영이 되는 것이 있다. 설정 파일 (change requires restart)라고 작성되 있는 것은 다시 시작해야 한다.

각각의 매개 변수에 대해서는 이후 설정이 필요할 때 설명하겠다.

postgresql.conf의 설정 방법에 대해 설명하였다.




최종 수정 : 2020-11-12