LoginSignup
118
128

More than 5 years have passed since last update.

Postgresでパスワードを忘れた場合の対策

Posted at

Postgresでパスワードを忘れました。
やばいやばいと思いつつ、アンインストールしなきゃかなぁ...ヽ(´Д`ヽ)(/´Д`)/イヤァ~
とか思っていたら、意外となんとかなりました。

環境は
- Vagrant 1.6.5
- Virtual Box 4.3.16
- CentOS6.5
- Postgres: psql 8.4.20, server 9.3
です。

アクセス権限の変更 & パスワードなしでのログインを可能に

アクセス権限ファイルを修正

まずはpg_hba.confを探して編集します。

探す
$ sudo find / -name pg_hba.conf
 -> /var/lib/pgsql/9.3/data/pg_hba.conf
編集する
$ sudo vi /var/lib/pgsql/9.3/data/pg_hba.conf
---
host    all         all         127.0.0.1/32          md5
もしくは
host    all         all         127.0.0.1/32          password
こんな感じな行を下の様に
↓↓↓↓

host    all         all         127.0.0.1/32          trust

ローカルホスト(127.0.0.1/32)では、パスワード指定なくてもtrustするからログインできますよ。って感じです。

Postgres を再読み込み

$ sudo /etc/rc.d/init.d/postgresql-9.3 reload

パスワードを変更する

PgAdminなりpsqlなりで、postgresユーザーでログイン出来るようになってます。
そしたら、パスワードを変更しちゃえばいいです。

$ psql -U postgres

postgres=# \password
postgres=# alter role postgres with password 'パスワード文字列';
postgres=# \q

パスワードなくてもいいよ設定をもどす

pg_hba.confファイルのtrustをpasswordなりmd5なりに戻して再読み込み。

References

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