今天晚上突然数据库连接不上了,检查Postgresql的日志,发现如下一句:
FATAL: password authentication Failed for user "xxx"
DETAIL: User "xxx" has an expired password.
Connection matched pg_hba.conf line 84: "local all all password"
意思是之前设置了xxx用户的密码过期时间,现在时间到了…
解决办法如下:
2.将pg_hba.conf(我mac下的路径为:/usr/local/var/postgres/pg_hba.conf)中127.0.0.1那行的认证方式改为trust.
3.用pgadmin以管理员登录进数据库,此时应该不需要输入密码
5.别忘了将第一步的trust改回password,或任何原先的认证方式
1.将pg_hba.conf中的local一行最后改为trust
2.用psql -U admin_name postgres 登录,此时应该也不需要密码
3.输入\d pg_user查看字段
postgres=# \d pg_user
View "pg_catalog.pg_user"
Column | Type | Modifiers
-------------+---------+-----------
usename | name |
usesysid | oid |
usecreatedb | boolean |
usesuper | boolean |
usecatupd | boolean |
userepl | boolean |
passwd | text |
valuntil | abstime |
useconfig | text[] |
4.输入select * from pg_user; 查看valuntil行的过期时间,注意别忘了命令最后的;号!
postgres=# select * from pg_user;
usename | usesysid | usecreatedb | usesuper | usecatupd | userepl | passwd | valuntil | useconfig
---------+----------+-------------+----------+-----------+---------+----------+----------+-----------
vvv | 12345 | t | f | f | f | ******** | |
aaa | 10000 | t | t | t | t | ******** | |
bbb | 15034 | t | f | f | f | ******** | infinity |
(3 rows)
如上所示infinity表示永不过期.