开发者

Can't log into PostgreSQL database

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

 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 # IPv开发者_开发问答6 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.


I was just trying to connect in the wrong way. Here's the right way:

psql -h localhost -U blog -d blog_development


psql uses a local socket by default (check out -h flag in man) - that should match line 82 when you log in.

82 local all all ident

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.


Before line 82, add

local   blog_development   blog   md5

and reload, or connect using -h localhost.


Have you added the user to pg_hba.conf? Here is the documentation.

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜