无法登录PostgreSQL数据库 [英] Can't log into PostgreSQL database

查看:92
本文介绍了无法登录PostgreSQL数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我这样创建了一个用户:

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"

知道为什么吗?

一个我尝试过的事情是编辑 pg_hba.conf

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 # IPv6 local connections:
 87 host    all                all         ::1/128               md5

第85行是我添加的。在那之后我重新启动了PostgreSQL,但是它似乎没有任何改变。

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

这篇关于无法登录PostgreSQL数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆