我已经在我的Ubuntu karma box上安装了PostgreSQL和pgAdminIII。

我能够成功地使用pgAdminIII(即连接/登录),但是当我尝试在命令行(使用psql)上使用相同的用户名/pwd登录到服务器时,我得到错误:

psql: FATAL:  Ident authentication failed for user "postgres"

现在有人知道如何解决这个问题吗?


当前回答

问题仍然是pg_hba.conf文件。这一行:你可以在/etc/postgres/ vary /main目录下找到这个文件

local   all             postgres                                peer
Should be

local   all             postgres                                md5

下面是官方PostgreSQL文档中关于身份验证方法的两个选项的简要描述。

对等的身份验证

对等身份验证方法的工作原理是从内核获取客户机的操作系统用户名,并将其用作允许的数据库用户名(可选的用户名映射)。此方法仅在本地连接上受支持。

密码身份验证

基于密码的认证方式有md5和password。除了通过连接发送密码的方式(分别为md5散列和明文)外,这些方法的操作类似。

如果您完全担心密码“嗅探”攻击,那么首选md5。尽量避免使用简单的密码。但是,md5不能与db_user_namespace特性一起使用。如果连接受SSL加密保护,则可以安全地使用密码(如果依赖于使用SSL,则SSL证书身份验证可能是更好的选择)。

修改此文件后,不要忘记重新启动PostgreSQL服务器。如果你在Linux上,那将是sudo service postgresql重启。

其他回答

编辑/etc/postgresql/8.4/main/pg_hba.conf文件,并将ident或peer替换为md5或trust,这取决于您是否希望它在您自己的计算机上询问密码。 然后重新加载配置文件:

/etc/init.d/postgresql reload

我在Mac OSX的PostgreSQL 9.3上的解决方案是在bash shell中使用sudo进入数据文件夹,然后将必要的行追加到pg_hba.conf文件,以允许所有用户都是可信的,并能够登录。这就是我所做的:

# in bash_profile edit PGDATA environmental variable
open ~/.bash_profile

# append this line to bash_profile
export PGDATA="/Library/PostgreSQL/9.3/data"

# reload bash_profile
source ~/.bash_profile

# open pg_hba.conf in vim
sudo vi /Library/PostgreSQL/9.3/data/pg_hba.conf

# append these two lines to the end of the pg_hba.conf file
local   all   all                  trust
host    all   all   127.0.0.1/32   trust

# can now login as user in bash
psql -d <db_name> -U <user_name> -W

我只需要简单地添加-h localhost位就可以工作了

解决这个问题的一个方法是编辑pg_hba.conf

sudo vi /etc/postgresql/9.3/main/pg_hba.conf

暂时

# Database administrative login by Unix domain socket
local   all             postgres                                   trust

至此,您就完成了。为了安全,那就去吧

sudo -u postgres psql template1
ALTER USER postgres with encrypted password 'your_password';

然后返回,将pg_hba.conf设置为

# Database administrative login by Unix domain socket
local   all             postgres                                   md5

我不得不重新安装pdAdmin来解决这个问题

brew cask reinstall pgadmin4