Background

How should we do if forgot our postgres User password . For some reason, after installing PostgreSQL, you may forget the password of the postgres user. In this case, you need to know how to reset the password.

如果忘记了我们的postgres用户密码,该怎么办。 由于某些原因,在安装PostgreSQL之后,您可能会忘记postgres用户的密码。 在这种情况下,您需要知道如何重设密码。

Importance Info : PostgreSQL uses the pg_hba.conf configuration file stored in the database data directory (e.g., C:\Program Files\PostgreSQL\12\data on Windows) to control the client authentication. The pg_hba.conf means host-based authentication.

  • Set the value to “trust” means that u can login as postgres without a password
  • Set the value to default value “md5” means that u should login as postgres with a password

这里有个重要信息:PostgreSQL使用存储在数据库数据目录中的pg_hba.conf配置文件来控制客户端的连接认证参数。

-将该值设置为“trust”意味着您可以以postgres`的身份登录,而无需输入密码。

-将值设置为“md5”的默认值意味着您应使用密码以postgres`身份登录

Solution

So our first step is to edit the pg_dba.conf file and change IPv4 connections from md5 to trust

所以我们第一步就是去设置pg_dba.conf 文件,把IPv4的属性改为md5

# 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                 md5
# 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

Restart the PostgreSQL server. If you are on Windows, you can restart the PostgreSQL from Services:

重启pgsql的服务,可以通过windows的服务中心,或者使用命令进行重启

Or run the following command from the window terminal:

pg_ctl -D “C:\Program Files\PostgreSQL\12\data” restart

Connect to PostgreSQL database server using any tool such as psql or pgAdmin (PostgreSQL will not require a password to login as we set to trust):

因为我们前面设置过trust,所以这里连接数据库是不需要密码的,使用以下命令直接登陆:

psql -U postgres

Execute the following command to set a new password for the postgres user.

输入sql语句执行重置密码操作:

ALTER USER postgres WITH PASSWORD ‘new_password’;

Restore the pg_dba.conf file ,set the trust back to md5, restart the PostgreSQL database server and connect to the PostgreSQL database server with the new password.

最后,还原 pg_dba.conf 文件,属性从trust设置回md5 ,重启pgsql服务.并尝试使用新密码连接数据库!

Done!

恭喜你,重置成功!

如何重置pgsql的密码(Reset Forgotten Password For postgres User)相关推荐

  1. 重置域管理员密码_如何在Server 2008 R2上重置忘记的域管理员密码

    重置域管理员密码 Forgetting your password is always a pain, but luckily there's an easy way to reset your Do ...

  2. mysql修改初始密码/ 重置默认密码 You must reset your password using ALTER USER statement

    初次使用mysql键入任何命令都会报以下错: You must reset your password using ALTER USER statement before executing this ...

  3. mysql 密码 You must reset your password using ALTER USER statement before executing this statement....

    mysql error You must reset your password using ALTER USER statement before executing this statement. ...

  4. MySQL 重置 root 密码以及修改密码时报错password字段不存在

    一.MySQL 重置 root 密码 关闭 MySQL 服务器: service mysql stop 进入目录, cd /usr/local/mysql/bin 以安全模式启动 MySQL ./my ...

  5. php 修改域密码,Self Service Password AD域密码自助重置服务配置指引

    Self Service Password AD域密码自助重置服务配置指引 一.安装Self Service Password 1.到官网获取安装包或安装方法 2.dev为开发者版本,stable为最 ...

  6. mysql ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing t

    前言:这篇转载的文章是我很久以前写的,但是后来手机换号了,又注册新号开始继续写blog.旧文章不能合并到新账号,就以转载的形式纪念下过去 环境:ubuntu 16.04/mysql 5.7.16 今天 ...

  7. Elasticsearch8重置elastic用户密码

    Elasticsearch8重置elastic用户密码 elastic可以说是es中预留的一个用户名,在按照官网yum安装方法安装启动后通过下面的方式测试是否正确运行 curl --cacert /e ...

  8. MySQL重置root用户密码的方法

    MySQL重置root用户密码的方法 转自:http://www.xunmeinet.com/help/info.asp?id=45 本教程适用于采用Win2003.WinXP操作系统的迅美VPS和云 ...

  9. MAC 重置MySQL root 密码

    MAC 重置MySQL root 密码   重置MySQL root 密码: 当忘记密码,或者想要强行重置 MySQL 密码的时候,可以像下面这样: 1.停止 MySQL 服务 1 2 sudo /u ...

最新文章

  1. AJAX是否能够取代桌面应用程序
  2. ubuntu/debian/centos/rhel使用镜像源一键安装gitlab-ce服务
  3. 计算机视觉与模式识别(1)—— A4纸边缘提取
  4. linux C++ 多进程初步02
  5. 关于[super dealloc]
  6. boost::asio的C/S结构笔记
  7. java 无法import_ImportError:无法导入名称X
  8. UVA10190 Divide, But Not Quite Conquer!【等差数列】
  9. java中int和Integer对比的一些坑
  10. python中不包不包括_Python文件部分(不包括数据)
  11. SAP ABAP 字符串替换
  12. pandownload 替代品_Pandownload倒下了,还有它,又一款百度云下载神器,10M/s
  13. 模型推理速度与硬件算力
  14. html 正则表达式 正整数,javascript如何判断数字是否为正整数?
  15. 【亚伦博客】《蝙蝠侠前传2:黑暗骑士》里发生了什么
  16. Linux扩容swap分区
  17. 一缕烟香起静中开鸿蒙意思,一缕青烟暗指什么意思 千古萦回一缕香
  18. 阿里云携手开源中国平台发百万悬赏项目
  19. Datawhale团队第二期录取名单!
  20. 苹果A14和高通骁龙888性能对比,A13都笑了

热门文章

  1. 算力寻租或将终结中本聪的POW机制?深度解析BCH“司机补贴战”
  2. wlan连接的笔记本电脑+开启移动热点+手机无法连接【已解决】
  3. 【灵修】人不迷失方向一定是心中有了目标(转)
  4. mybatis foreach
  5. Builder模式总结
  6. 2014-2022年4月全国空气质量数据分析
  7. esim办理出现差错_中国联通科普eSIM卡使用攻略 关于eSIM卡常见问题答疑
  8. 硬件趣学python_硬的解释|硬的意思|汉典“硬”字的基本解释
  9. delphiXE关于线程和多线程、线程的同步与异步执行
  10. STM32控制电机简易教程