赞
踩
本文介绍了在PostgreSQL中如果密码忘记了怎么重置密码
找到pg_hba.conf文件,进行备份
cp pg_hba.conf pg_hba.conf.bak
- # 修改配置文件以信任本地连接不需要密码。 将配置文件中的 scram-sha-256 或者 md5 修改为 trust
- # TYPE DATABASE USER ADDRESS METHOD
-
- # "local" is for Unix domain socket connections only
- local all all trust
- # IPv4 local connections:
- host all all 127.0.0.1/32 trust
- host all all 0.0.0.0/0 md5
- # IPv6 local connections:
- host all all ::1/128 trust
- # Allow replication connections from localhost, by a user with the
- # replication privilege.
- local replication all trust
- host replication all 127.0.0.1/32 trust
- host replication all ::1/128 trust
- su - postgres -c "pg_ctl -D /usr/local/pgsql/data/ restart"
-
- # 如果使用yum安装的使用以下命令重启服务
- systemctl restart postgresql
- # 切换用户
- [root@bogon ~]# su - postgres
- Last login: Fri May 17 03:42:06 EDT 2024 on pts/0
-
- # 登录数据库
- [postgres@bogon ~]$ psql
- psql (16.3)
- Type "help" for help.
-
- # 修改密码,密码自定义
- postgres=# ALTER USER postgres WITH PASSWORD 'new_password';
- ALTER ROLE
pg_hba.conf
配置文件。 将 pg_hba.conf.bak
文件的内容覆盖 pg_hba.conf
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。