我忘记或者在安装过程中输入了PostgreSQL默认用户的密码。我似乎不能运行它,我得到以下错误:

psql: FATAL:  password authentication failed for user "hisham"
hisham-agil: hisham$ psql

是否有方法重置密码或如何创建具有超级用户权限的新用户?

我是PostgreSQL的新手,只是第一次安装它。我正在尝试使用Ruby on Rails,我正在运行Mac OS X v10.7 (Lion)。


当前回答

Edit the file /etc/postgresql/<version>/main/pg_hba.conf and find the following line: local all postgres md5 Edit the line and change md5 at the end to trust and save the file Reload the postgresql service sudo service postgresql reload This will load the configuration files. Now you can modify the postgres user by logging into the psql shell psql -U postgres Update the postgres user's password alter user postgres with password 'secure-passwd-here'; Edit the file /etc/postgresql/<version>/main/pg_hba.conf and change trust back to md5 and save the file Reload the postgresql service sudo service postgresql reload Verify that the password change is working psql -U postgres -W

其他回答

我只是在Windows 10上有这个问题,在我的情况下,问题是我只是运行psql,它默认试图登录与我的Windows用户名(“内森”),但没有PostgreSQL用户的名字,它没有告诉我。

所以解决方案是运行psql -U postgres而不是仅仅运行psql,然后我在安装时输入的密码就可以工作了。

Edit the file /etc/postgresql/<version>/main/pg_hba.conf and find the following line: local all postgres md5 Edit the line and change md5 at the end to trust and save the file Reload the postgresql service sudo service postgresql reload This will load the configuration files. Now you can modify the postgres user by logging into the psql shell psql -U postgres Update the postgres user's password alter user postgres with password 'secure-passwd-here'; Edit the file /etc/postgresql/<version>/main/pg_hba.conf and change trust back to md5 and save the file Reload the postgresql service sudo service postgresql reload Verify that the password change is working psql -U postgres -W

按照步骤1找到最佳答案。

如果你使用Windows操作系统,这是我的补充。只遵循第1步,然后在web上打开pgAdmin或postgres,并单击顶部导航上的file。单击reset layout,最后重新加载应用程序。不管你输入什么密码都可以。我用的是1234。

对于Windows安装,将创建Windows用户。“psql”使用该用户连接到端口。如果您更改了PostgreSQL用户的密码,它不会更改Windows用户的密码。 只有当您可以访问命令行时,下面的命令行才能工作。

相反,您可以使用Windows GUI应用程序“c:\Windows\system32\lusrmgr.exe”。这个应用程序管理由Windows创建的用户。现在可以修改密码了。

注意:在Linux上,您可以简单地运行sudo su - postgres来成为postgres用户,然后使用psql更改所需的内容。