本文最后更新于 698 天前,其中的信息可能已经有所发展或是发生改变。
这应该也算学习笔记吧......
1、信任所有的本地连接
修改配置文件:
vi /var/lib/pgsql/12/data/pg_hba.conf
从 md5 的认证方式改为 trust
...
...
# "local" is for Unix domain socket connections only
local all all trust
# IPv4 local connections:
host all all 127.0.0.1/32 trust
...
...
如果你更改过 PostgreSQL 数据库的端口的话,也需要改回到 5432,否则直接访问会显示认证失败:psql: error: FATAL: Ident authentication failed for user "postgres"
vi /var/lib/pgsql/12/data/postgresql.conf
改回 5432 端口:
port = 5432 # (change requires restart)
之后重启数据库:
sudo systemctl restart postgresql-12
2、切换至 postgres 用户并连接数据库
切换用户:
su - postgres
连接数据库:
-bash-4.2$ psql
3、修改密码
ALTER USER postgres WITH PASSWORD 'newpassword';
4、恢复原配置并重启
恢复之前的配置后进行重启:
sudo systemctl restart postgresql-12
结束。