天天看点

postgre 忘记密码后的补救方法

1、首先停止正在运行的postgre服务

2、找到数据库data目录下的 pg_hba.conf 文件

3、打开编辑内容,host后边的 md5 修改为 trust。(下列所有步骤操作完成后记得恢复原样。)

# TYPE  DATABASE        USER            ADDRESS                 METHOD

# IPv4 local connections:
host    all             all             127.0.0.1/32            trust
# IPv6 local connections:
host    all             all             ::1/128                 trust
# Allow replication connections from localhost, by a user with the
# replication privilege.
#host    replication     all             127.0.0.1/32            md5
#host    replication     all             ::1/128                 md5
           

4、启动服务,然后输入下边命令可直接进入到命令行模式

psql -U postgres
           

5、修改用户 Postgres 密码为 123456

ALTER USER Postgres WITH PASSWORD '123456';