我已经在我的Ubuntu karma box上安装了PostgreSQL和pgAdminIII。
我能够成功地使用pgAdminIII(即连接/登录),但是当我尝试在命令行(使用psql)上使用相同的用户名/pwd登录到服务器时,我得到错误:
psql: FATAL: Ident authentication failed for user "postgres"
现在有人知道如何解决这个问题吗?
我已经在我的Ubuntu karma box上安装了PostgreSQL和pgAdminIII。
我能够成功地使用pgAdminIII(即连接/登录),但是当我尝试在命令行(使用psql)上使用相同的用户名/pwd登录到服务器时,我得到错误:
psql: FATAL: Ident authentication failed for user "postgres"
现在有人知道如何解决这个问题吗?
当前回答
这招对我很管用: http://tecadmin.net/fatal-ident-authentication-failed-for-user-postgres/#
local all postgres trust
local all myapp_usr trust
# IPv4 local connections:
host all all 127.0.0.1/32 trust
# IPv6 local connections:
#host all all ::1/128 trust
其他回答
我在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
问题仍然是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重启。
关于PostgreSQL安装的配置问题:
在下面提到的conf文件中配置# TYPE数据库用户地址方法部分
查找并编辑/var/lib/pgsql/10/data/pg_hba.conf或根据您的文件位置更新方法(md5)。如果你的配置中不存在,更新文件中的条目,如下所示:
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all trust
local all all md5
# IPv4 local connections:
host all all 127.0.0.1/32 md5
host all all 0.0.0.0/0 md5
# IPv6 local connections:
host all all ::1/128 md5
在下面提到的conf文件中配置连接和验证部分
查找并编辑/var/lib/pgsql/10/data/postgresql.conf或根据您的文件位置 更新监听地址和端口
listen_addresses = '*' // # what IP address(es) to listen on;
# comma-separated list of addresses;
# defaults to 'localhost'; use '*' for all
port = 5432 // Set port as 5432
重新启动PostgreSQL:
sudo systemctl restart postgresql-10 # Update service name based on your installation
这招对我很管用: http://tecadmin.net/fatal-ident-authentication-failed-for-user-postgres/#
local all postgres trust
local all myapp_usr trust
# IPv4 local connections:
host all all 127.0.0.1/32 trust
# IPv6 local connections:
#host all all ::1/128 trust
以下步骤适用于在Ubuntu 12.04上重新安装postgres 9.1。(也适用于Ubuntu 14.04上的postgres 9.3.9)
默认情况下,postgres会创建一个名为'postgres'的用户。我们以她的身份登录,给她一个密码。
$ sudo -u postgres psql
\password
Enter password: ...
...
通过输入\q或ctrl+d退出psql。然后我们用postgres来联系。-h localhost部分很重要:它告诉psql客户端我们希望使用TCP连接(配置为使用密码身份验证)进行连接,而不是通过PEER连接(不关心密码)。
$ psql -U postgres -h localhost