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 の設定方法について説明した。