PostgreSQL | PostgreSQL Configuration Files | How to Configure the postgresql.conf File

The postgresql.conf file is used for the basic configuration of PostgreSQL. This page explains how to configure the postgresql.conf file.

Location of the postgresql.conf File

By default, postgresql.conf is stored in the data directory where PostgreSQL was installed.

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 <------------- stored here.
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>

The postgresql.conf file is a text file, so you can open it in a text editor to view or edit its contents.

# -----------------------------
# 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

... omitted ...

postgresql.conf Settings

Each item is written in the form parameter name = setting value. For example, the postgresql.conf file contains entries like the following.

# - 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)

The first parameter, listen_addresses, sets the hosts and IP addresses from which client connections to PostgreSQL are allowed. It is currently set to '*', which means connections from all clients are allowed. The detailed settings, such as which databases connections are allowed to access, are configured in the pg_hba.conf file; this setting is the preceding step.

Any text after # is treated as a comment. Use it to write comments about settings or to disable parameter settings. For example, the configuration file contains entries like the following.

# - Authentication -

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

Although these lines describe parameters, they are currently comments and are not configured because # appears at the beginning. To configure a parameter, remove the first # and change the value if needed. Of course, lines that begin with # can remain as comments. For example, configure the authentication_timeout parameter as follows.

# - Authentication -

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

When you change settings, some changes are applied only after restarting PostgreSQL, while others take effect immediately. Settings marked with (change requires restart) in the configuration file require a restart.

Each parameter will be explained later when that setting is needed.

This page explained how to configure postgresql.conf.