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

The pg_ident.conf file is used to map Ident user names to PostgreSQL role names when Ident authentication is used as the client authentication method. This page explains how to configure the pg_ident.conf file.

Location of the pg_ident.conf File

Like postgresql.conf, pg_ident.conf is stored by default 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 <------------- stored here.
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>

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

# PostgreSQL User Name Maps
# =========================
#
# Refer to the PostgreSQL documentation, chapter "Client
# Authentication" for a complete description.  A short synopsis
# follows.
#
# This file controls PostgreSQL user name mapping.  It maps external
# user names to their corresponding PostgreSQL user names.  Records
# are of the form:
#
# MAPNAME  SYSTEM-USERNAME  PG-USERNAME
#
# (The uppercase quantities must be replaced by actual values.)
#
# MAPNAME is the (otherwise freely chosen) map name that was used in
# pg_hba.conf.  SYSTEM-USERNAME is the detected user name of the
# client.  PG-USERNAME is the requested PostgreSQL user name.  The
# existence of a record specifies that SYSTEM-USERNAME may connect as
# PG-USERNAME.
#
# If SYSTEM-USERNAME starts with a slash (/), it will be treated as a
# regular expression.  Optionally this can contain a capture (a
# parenthesized subexpression).  The substring matching the capture
# will be substituted for \1 (backslash-one) if present in
# PG-USERNAME.

... omitted ...

pg_ident.conf Settings

At the end of the pg_ident.conf file, there is a section like the following.

# Put your actual configuration here
# ----------------------------------

# MAPNAME       SYSTEM-USERNAME         PG-USERNAME

Currently, no settings have been added. To add a mapping, set an arbitrary mapping name in MAPNAME, the Ident user name in SYSTEM-USERNAME, and the PostgreSQL role name in PG-USERNAME. For example, write the following.

# Put your actual configuration here
# ----------------------------------

# MAPNAME       SYSTEM-USERNAME         PG-USERNAME
mymap           kim                   kc

Then write the corresponding setting in the pg_hba.conf file described in “How to Configure the pg_hba.conf File”.

The MAPNAME specified when adding the mapping is used there.

Now a user authenticated by Ident as kim is allowed to connect to PostgreSQL as kc.

However, because I could not test this directly in my environment, I cannot confirm whether it is configured correctly.

This page explained how to configure pg_ident.conf.