postgresql mac 上用户“postgres”的密码验证失败
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18555352/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
password authentication failed for user "postgres" on mac
提问by ycshao
I have problem creating new psql user because I cannot log in psql as "postgres", I have tried
我在创建新的 psql 用户时遇到问题,因为我无法以“postgres”的身份登录 psql,我试过了
1. sudo -u postgres psql
2. sudo -u postgres createuser img_site -P -s -e
and they are all ask for password of "postgres" which I don't know. I have tried to change unix password of user "postgres"(I know it's dangerous) and it still tells me: password authentication failed for user "postgres". I also have tried GUI pgAdmin but it's the same error.
他们都要求输入我不知道的“postgres”密码。我试图更改用户“postgres”的 unix 密码(我知道这很危险),但它仍然告诉我:用户“postgres”的密码身份验证失败。我也试过 GUI pgAdmin 但它是同样的错误。
I don't know if it's related: I have created a symbolic link
我不知道是否相关:我创建了一个符号链接
sudo ln -s /private/tmp/.s.PGSQL.5432 /var/pgsql_socket/
in order to get rid of error
为了摆脱错误
createuser: could not connect to database postgres: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/pgsql_socket/.s.PGSQL.5432"?
回答by zaadeh
Check pg_hba.conf
. it should have a line like this at the top (before all other entries):
检查pg_hba.conf
。它的顶部应该有这样一行(在所有其他条目之前):
local all postgres peer
this allows local unix socket access by postgres
db user to all databases with no password required.
这允许postgres
db 用户在不需要密码的情况下访问所有数据库的本地 unix 套接字。
Also clear and redefine password for postgres
system user:
还为postgres
系统用户清除并重新定义密码:
sudo passwd -d postrges
sudo su postgres -c passwd
then run:
然后运行:
su postgres -c psql template1
psql> ALTER USER postgres WITH PASSWORD '<password>';
type \q
to quit psql and you are done with resetting password for postgres
user.
键入\q
退出 psql,您就完成了为postgres
用户重置密码。
回答by Gordon Davisson
sudo
doesn't want the password of the account you're switching to, it wants the password of the account you're switching from. It also requires that you be an admin (or otherwise listead in /etc/sudoers). su
, on the other hand, requires the password for the account you're switching to.
sudo
不希望帐户您切换到的密码,它希望该帐户您切换的密码从。它还要求您是管理员(或在 /etc/sudoers 中以其他方式代替)。su
,另一方面,需要您要切换到的帐户的密码。
回答by user33302
I was trying to setup postgres for Ruby on Rails and I was getting the the password authentication failed for user error. Check if the server is actually running:
我试图为 Ruby on Rails 设置 postgres,但由于用户错误而导致密码身份验证失败。检查服务器是否实际运行:
pg_ctl -D /usr/local/var/postgres status
pg_ctl -D /usr/local/var/postgres status
If you get
如果你得到
pg_ctl: no server running
pg_ctl: no server running
Run
跑
pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
Also you must include localhost in psql.
此外,您必须在 psql 中包含 localhost。
psql -U postgres -h localhost
psql -U postgres -h localhost
回答by Ajay
This worked for me:
这对我有用:
ALTER USER my_user WITH PASSWORD 'my_password';
ALTER USER my_user WITH PASSWORD 'my_password';