1. find / -name pg_hba.conf
2. sudo vi /etc/postgresql/13/main/pg_hba.conf

3. 拉到最下面,把postgres所在行的md5改成trust

local all postgres md5

Ubuntu PostgreSQL数据库忘记密码

  改后:

Ubuntu PostgreSQL数据库忘记密码 

4. sudo service postgresql restart

5. 无需输入密码即可登陆:

psql -U postgres 

psql (13.1 (Ubuntu 13.1-1.pgdg20.04+1))
Type "help" for help.

postgres=#

6. 设置密码"postgres"后退出

ALTER USER postgres WITH PASSWORD 'postgres';
\q

7. 最后把trust改回md5:sudo vi /etc/postgresql/13/main/pg_hba.conf
8. sudo service postgresql restart
9. 用密码postgres正常登陆

psql -U postgres
Password for user postgres: 
psql (13.1 (Ubuntu 13.1-1.pgdg20.04+1))
Type "help" for help.

postgres=#

相关文章:

  • 2021-11-28
  • 2021-12-27
  • 2021-12-27
  • 2021-10-12
  • 2021-11-12
猜你喜欢
  • 2022-12-23
  • 2022-01-20
  • 2022-02-17
  • 2021-11-18
  • 2021-11-28
  • 2021-11-28
相关资源
相似解决方案