LoginSignup
128
110

More than 5 years have passed since last update.

peer認証の関係でpsqlログインできない時の対処法

Last updated at Posted at 2015-01-08

出つくしていくるんだろうけど、メモ

環境: ubuntu14ぐらい postgres9.3
現象:postgresでない自分のUNIXユーザーでログインしたシェルから、psqlを実行する際、postgresql上のユーザーの正しいパスワードを入力してもログインできない
こんな感じ

psqlログイン
hoge@ubuntu:~$ psql -U postgres -h localhost -W
Password for user postgres: 
psql: FATAL:  password authentication failed for user "postgres"

hogeがUNIXグループpostgresには参加済みでもこうなる。

問題はLinuxの仕組みではなくpostgresの認証の仕組みが関係していた。
postgresユーザー名とパスワードを指定してもローカルからのアクセスはUNIXユーザー名とパスワードがpostgresのものと同じでないとログインできないPeer認証というのがあった。
pg_hba.confに設定は
(ubuntuなら/etc/postgres/postgresのバージョン/main/pg_hba.confにあった)

いくつかのハマりパターンがあるんだろうけど、自分の場合
http://stackoverflow.com/questions/7695962/postgresql-password-authentication-failed-for-user-postgres
を参考にして以下の手順を行ったら自分のUNIXユーザーからpsqlログインに成功した

リンク先にまったく同じことは書いているけど、、、

  • postgresユーザー"postgres"のパスワードをもう一度設定。 このときmd5で保存した。

sudo su postgres -c 'psql --username=postgres'

psqlに入った後、

ALTER USER postgres with encrypted password 'your_password';

  • pg_hba.confを修正。

local all postgres md5

  • postgresを再起動

これで個人のUNIXユーザーからposgresユーザー'postgres'としてpsqlログインできる

hoge@ubuntu:~$ psql -U postgres -h localhost -W

128
110
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
128
110