我已经在我的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"
现在有人知道如何解决这个问题吗?
当前回答
我有类似的问题,我在pg_hba.conf中修复了它,当删除所有识别方法时,即使是IP6地址(尽管我在机器上只有IP4)。
host all all 127.0.0.1/32 password
host all all ::1/128 password
#for pgAdmin running at local network
host all all 192.168.0.0/24 md5
其他回答
在Ubuntu 12.04中为Rails开发设置PostgreSQL之后,我也遇到了同样的问题
我尝试了其他答案,但我所要做的就是:“config/database.yml”
development:
adapter: postgresql
encoding: unicode
database: (appname)_development
pool: 5
username: (username you granted appname database priviledges to)
password:
在以上所有的答案中,没有一个对我有用。我不得不手动更改数据库中的用户密码,它突然工作了。
psql -U postgres -d postgres -c "alter user produser with password 'produser';"
我使用了以下设置:
pg_hba.conf
local all all peer
# IPv4 local connections:
host all all 127.0.0.1/32 password
# IPv6 local connections:
host all all ::1/128 password
以下命令连接成功:
psql -U produser -d dbname -h localhost -W
如果你在CentOS上使用它,你可能需要在做出上述解决方案后重新加载postgres:
systemctl restart postgresql-9.3.service
对于fedora26和postgres9.6
首先,以root用户登录,然后通过以下命令进入psql
$ su postgres
then
$ psql
在PSQL中查找hba_file ==>的位置意味着pg_hba.conf
postgres=# show hba_file ;
hba_file
--------------------------------------
/etc/postgresql/9.6/main/pg_hba.conf
(1 row)
在pg_hba.conf文件中将用户访问权限更改为this
host all all 127.0.0.1/32 md5
您得到这个错误是因为您没有通过客户端身份验证。根据错误消息,您可能有默认的postgres配置,它将所有PostgreSQL连接的客户端身份验证方法设置为“IDENT”。
你一定要阅读PostgreSQL手册中的19.1节客户端身份验证,以更好地理解可用的身份验证设置(对于pg_hba.conf中的每条记录),但下面是相关的代码片段,以帮助解决你遇到的问题(来自版本9.5手册):
trust Allow the connection unconditionally. This method allows anyone that can connect to the PostgreSQL database server to login as any PostgreSQL user they wish, without the need for a password or any other authentication. See Section 19.3.1 for details. reject Reject the connection unconditionally. This is useful for "filtering out" certain hosts from a group, for example a reject line could block a specific host from connecting, while a later line allows the remaining hosts in a specific network to connect. md5 Require the client to supply a double-MD5-hashed password for authentication. See Section 19.3.2 for details. password Require the client to supply an unencrypted password for authentication. Since the password is sent in clear text over the network, this should not be used on untrusted networks. See Section 19.3.2 for details. gss Use GSSAPI to authenticate the user. This is only available for TCP/IP connections. See Section 19.3.3 for details. sspi Use SSPI to authenticate the user. This is only available on Windows. See Section 19.3.4 for details. ident Obtain the operating system user name of the client by contacting the ident server on the client and check if it matches the requested database user name. Ident authentication can only be used on TCP/IP connections. When specified for local connections, peer authentication will be used instead. See Section 19.3.5 for details. peer Obtain the client's operating system user name from the operating system and check if it matches the requested database user name. This is only available for local connections. See Section 19.3.6 for details. ldap Authenticate using an LDAP server. See Section 19.3.7 for details. radius Authenticate using a RADIUS server. See Section 19.3.8 for details. cert Authenticate using SSL client certificates. See Section 19.3.9 for details. pam Authenticate using the Pluggable Authentication Modules (PAM) service provided by the operating system. See Section 19.3.10 for details.
所以…要解决您正在经历的问题,您可以执行以下操作之一:
Change the authentication method(s) defined in your pg_hba.conf file to trust, md5, or password (depending on your security and simplicity needs) for the local connection records you have defined in there. Update pg_ident.conf to map your operating system users to PostgreSQL users and grant them the corresponding access privileges, depending on your needs. Leave the IDENT settings alone and create users in your database for each operating system user that you want to grant access to. If a user is already authenticated by the OS and logged in, PostgreSQL won't require further authentication and will grant access to that user based on whatever privileges (roles) are assigned to it in the database. This is the default configuration.
注意:pg_hba.conf和pg_identity .conf的位置取决于操作系统。