LoginSignup
6

More than 5 years have passed since last update.

PostgreSQLでパスワード認証を行う方法

Posted at

HomebrewでPostgreSQLをインストールすると

pg_hba.conf に記載される初期設定では、 接続を無条件で許可する というせっていになっている。なので、 createuser コマンドでパスワードを設定するも、パスワード入力プロンプトが出ないと行ったような、おかしな現象にあたってしまう。

接続時にパスワードを要求するために

pg_hba.conf を、以下の様に修正する。

# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only
#local   all             all                                     trust
local   all             all                                     md5

# IPv4 local connections:
#host    all             all             127.0.0.1/32            trust
host    all             all             127.0.0.1/32            md5

# IPv6 local connections:
#host    all             all             ::1/128                 trust
host    all             all             ::1/128                 md5

上記中、 METHODtrust(=接続を無条件で許可) となっている箇所を、 md5(=認証時にMD5暗号化パスワードを要求する) ように設定変更を行った。

なお、参考にしたサイトはこちら

設定変更を終えたら

以下のコマンドを利用して、PostgreSQLの再起動を忘れずに行う事。

$ launchctl unload ./homebrew.mxcl.postgresql.plist

$ launchctl load -w ./homebrew.mxcl.postgresql.plist

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
6