How to reset postgres password

  1. Find the file pg_hba.conf - it may be located, for example in /etc/postgresql/9.6/main/pg_hba.conf.
cd /etc/postgresql/9.6/main
  1. Back it up.
cp pg_hba.conf pg_hba.conf-backup
  1. Place the following line (as either the first uncommented line, or as the only one):
local  all   all   trust
  1. Restart your PostgreSQL server (e.g., on Linux:)
sudo /etc/init.d/postgresql restart

If the service (daemon) doesn't start reporting in log file:

local connections are not supported by this build

you should change

local  all   all   trust

to

host  all   all  127.0.0.1/32  trust
  1. you can now connect as any user. Connect as the superuser postgres (note, the superuser name may be different in your installation. In some systems it is called pgsql, for example.)
psql -U postgres

or

psql -h 127.0.0.1 -U postgres

(note that with the first command you will not always be connected with local host)

  1. Reset password
ALTER USER my_user_name with password 'my_secure_password';
  1. Restore the old pg_hba.conf as it is very dangerous to keep around
cp pg_hba.conf-backup pg_hba.conf
  1. restart the server, in order to run with the safe pg_hba.conf
sudo /etc/init.d/postgresql restart
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • pyspark.sql模块 模块上下文 Spark SQL和DataFrames的重要类: pyspark.sql...
    mpro阅读 9,507评论 0 13
  • NAME dnsmasq - A lightweight DHCP and caching DNS server....
    ximitc阅读 2,936评论 0 0
  • 小时候,每当一天的劳作结束,爸爸都很喜欢搬个板凳,坐在我们中间讲故事,而这个带有神秘色彩的故事也由此开始。 相传,...
    稀里糊糊的小生活阅读 280评论 1 2
  • 2018年7月24日 星期二 雨 题外记:波伏娃的《第二性》里写道: “女人的不幸在于被几乎不可抗拒的诱惑包围着,...
    花海云裳阅读 1,401评论 41 37
  • 仅致电视剧《康熙王朝》中康熙爷身边那位聪明美丽忠诚的苏麻喇大姑姑(不考据不代入史上真人)。 一抹娉娉影,一缕婉婉香...
    琳达123阅读 1,058评论 0 4