PostgreSQL | PostgreSQL 設定ファイル | pg_ident.conf ファイルの設定方法
pg_ident.conf ファイルは、クライアントの認証方式として Ident 認証を使用する場合に、Ident ユーザー名を PostgreSQL のロール名にマッピングするために使用するファイルである。ここでは、pg_ident.conf ファイルの設定方法について説明する。
pg_ident.conf ファイルの場所
pg_ident.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>
pg_ident.conf ファイルはテキストファイルなので、内容を確認したり編集したりするにはテキストエディタで開くことができる。
# 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.
... 以下省略 ...
pg_ident.conf の設定
pg_ident.conf ファイルの最後の部分を見ると、次のような箇所がある。
# Put your actual configuration here
# ----------------------------------
# MAPNAME SYSTEM-USERNAME PG-USERNAME
現在は何も設定が追加されていない状態である。マッピングを追加する場合、MAPNAME にはマッピングに対する任意の名前を設定し、SYSTEM-USERNAME には Ident ユーザー名、PG-USERNAME には PostgreSQL のロール名を指定する。たとえば、次のように記述する。
# Put your actual configuration here
# ----------------------------------
# MAPNAME SYSTEM-USERNAME PG-USERNAME
mymap kim kc
そして、「pg_hba.conf ファイルの設定方法」で説明した pg_hba.conf ファイルに対応する設定を記述する。
先ほどマッピングを追加するときに指定した MAPNAME を指定する。
これにより、Ident で kim として認証されたユーザーが、kc として PostgreSQL に接続することを許可される。
ただし、自分の環境では直接テストできなかったため、正しく設定されているかは確認できない。
–
pg_ident.conf の設定方法について説明した。