LoginSignup
0
1

More than 3 years have passed since last update.

pg_hba.confファイル内のクライアント認証の優先順位

Posted at

「現場で使える Ruby on Rails 5 速習実践ガイド」のChapter 6-9-3 「production環境用のデータベースを作成する」で詰まったのでメモ書きします。

実行環境

PostgreSQL 10.15
Ruby 2.7.1
Vagrant 2.2.9
CentOS 7.8.2003

問題点

production環境用のデータベースを作成する以下のところでエラー発生

RAILS_ENV=production bin/rails db:create db:migrate

原因はPostgreSQLのユーザー認証がパスワード認証になっていないことのようだった。

修正点

修正にはpg_hba.confというファイルを書き換えてパスワードを使った認証ができるように、設定する必要があるようだった。

ユーザーtaskleafはパスワード認証、元々使っていたユーザーvagrant, rootはそのままにしておきたかったので、できないか調べたところ、pg_hba.confは上方にある記述が優先されるとの記載があった。

接続形式、クライアントアドレス、要求されたデータベース、およびユーザ名に一致する最初のレコードが認証処理に使用されます。

リンク:日本PostgreSQLユーザ会

以下のようにmd5(パスワード認証にするための設定)の行を追加、
vagrant, rootユーザーは元のとおりpeerに設定して意図どおり修正できた。
修正前

pb_hba.conf
# listen on a non-local interface via the listen_addresses
# configuration parameter, or via the -i or -h command line switches.
local   all             all                                     peer

修正後

pb_hba.conf
# listen on a non-local interface via the listen_addresses
# configuration parameter, or via the -i or -h command line switches.
local   all             vagrant                                 peer
local   all             root                                    peer
local   all             all                                     md5
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1