Ubuntu PostgreSQL数据库忘记密码
1. find / -name pg_hba.conf
2. sudo vi /etc/postgresql/13/main/pg_hba.conf
3. 拉到最下面,把postgres所在行的md5改成trust
local all postgres md5
改后:
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=#