如何在mac os x 10.8.2上重置postgresql 9.2默认用户(通常是'postgres')密码?

Hea*_*ers 30 postgresql macos

我刚安装了PostgreSQL 9.2EnterpriseDB的Mac OS X 10.8.2.我输错了postgres用户密码,所以无法连接.如何重置密码?

Hea*_*ers 72

找到方向:

sudo su postgres
Run Code Online (Sandbox Code Playgroud)

修改/Library/PostgreSQL/9.2/data/pg_hba.conf

-local all all   md5
+local all all   trust
Run Code Online (Sandbox Code Playgroud)

重启postgres

/Library/PostgreSQL/9.2/bin/pg_ctl restart -D /Library/PostgreSQL/9.2/data/
Run Code Online (Sandbox Code Playgroud)

连接到postgres:

psql
Run Code Online (Sandbox Code Playgroud)

在psql里面(\q要退出):

ALTER USER postgres WITH ENCRYPTED PASSWORD 'password';
Run Code Online (Sandbox Code Playgroud)

修改pg_hba.conf

+local all all   md5
-local all all   trust
Run Code Online (Sandbox Code Playgroud)

重启postgres

/Library/PostgreSQL/9.2/bin/pg_ctl restart -D /Library/PostgreSQL/9.2/data/
Run Code Online (Sandbox Code Playgroud)

  • 更改pg_hba.conf后无需重启Postgres.你只需要使用`pg_ctl reload`重新加载它. (5认同)