无法登录 PostgreSQL 数据库
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4565494/
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
Can't log into PostgreSQL database
提问by Jason Swett
I created a user like this:
我创建了一个这样的用户:
create user blog with password 'blog';
Then I made it the owner of a database:
然后我使它成为数据库的所有者:
alter database blog_development owner to blog;
Then I tried to log in and it didn't work:
然后我尝试登录,但没有成功:
$ psql -d blog_development -U blog -W
Password for user blog:
psql: FATAL: Ident authentication failed for user "blog"
Any idea why?
知道为什么吗?
One thing I've tried is editing pg_hba.conf
我尝试过的一件事是编辑 pg_hba.conf
76 # Database administrative login by UNIX sockets
77 local all postgres ident
78
79 # TYPE DATABASE USER CIDR-ADDRESS METHOD
80
81 # "local" is for Unix domain socket connections only
82 local all all ident
83 # IPv4 local connections:
84 host all all 127.0.0.1/32 md5
85 host blog_development blog 127.0.0.1/32 md5
86 # IPv6 local connections:
87 host all all ::1/128 md5
Line 85 is the one I added. I restarted PostgreSQL after that but it didn't seem to change anything.
第 85 行是我添加的那一行。之后我重新启动了 PostgreSQL,但它似乎没有改变任何东西。
回答by Jason Swett
I was just trying to connect in the wrong way. Here's the right way:
我只是想以错误的方式连接。这是正确的方法:
psql -h localhost -U blog -d blog_development
回答by nate c
psql uses a local socket by default (check out -h flag in man) - that should match line 82 when you log in.
psql 默认使用本地套接字(查看 man 中的 -h 标志) - 登录时应该匹配第 82 行。
82 local all all ident
82 本地所有所有标识
ident
needs a real user in the system to check the password against. So you can either connect by host or add an user so it matches you new config line.
ident
需要系统中的真实用户来检查密码。因此,您可以通过主机连接或添加用户,使其与您的新配置行匹配。
回答by Peter Eisentraut
Before line 82, add
在第 82 行之前,添加
local blog_development blog md5
and reload, or connect using -h localhost
.
并重新加载,或使用-h localhost
.
回答by John P
Have you added the user to pg_hba.conf? Here is the documentation.
您是否已将用户添加到 pg_hba.conf?这是文档。
http://www.postgresql.org/docs/8.4/static/auth-pg-hba-conf.html
http://www.postgresql.org/docs/8.4/static/auth-pg-hba-conf.html
I don't really remember the exact syntax but you should add something like this:
我不太记得确切的语法,但您应该添加如下内容:
host blog_development blog 127.0.0.1/32 md5
You might need to reload or restart the server so that pg_hba.conf is reread.
您可能需要重新加载或重新启动服务器,以便重新读取 pg_hba.conf。