PostgreSQL - 致命:用户身份验证失败
PostgreSQL - FATAL: Ident authentication failed for user
我在数据库 mytestdb
中创建了一个名为 employees
的简单 table
我想将此 table 导入 hdfs。
bin/sqoop import --connect 'jdbc:postgresql://127.0.0.1/mytestdb' --username user -P --table employees --target-dir /user/postgres
但是,我一直收到错误消息:
WARNING: SQLException occurred while connecting to 127.0.0.1:5432
org.postgresql.util.PSQLException: FATAL: Ident authentication failed
for user "user" at
org.postgresql.core.v3.ConnectionFactoryImpl.doAuthentication(ConnectionFactoryImpl.java:473)
/var/lib/pgsql/data/pg_hba.conf
设置如下:
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all md5
# IPv4 local connections:
host all all 127.0.0.1/32 ident
# IPv6 local connections:
host all all ::1/128 ident
# Allow replication connections from localhost, by a user with the
# replication privilege.
#local replication postgres peer
#host replication postgres 127.0.0.1/32 ident
#host replication postgres ::1/128 ident
查看日志文件(对于 CentOS,可能在 /var/lib/pgsql/data/pg_log
中)以获取更多详细信息。
如果用户不存在,请创建。使用 psql
,您可以 create a user 喜欢:
create role hduser with login, superuser;
或来自command line:
createuser -s -e hduser
如果没有安装identd
,请安装:
yum install authd xinetd
然后编辑 /etc/xinet.d/auth
并将 disable = yes
更改为 disable = no
:
service auth
{
disable = no
socket_type = stream
....
}
并重新启动 xinetd
服务:
systemctl restart xinetd
我从网络上的几个不同来源的组合中找到了一个可行的解决方案。
编辑配置文件
nano /var/lib/pgsql/data/pg_hba.configuration
将前两个 ident
替换为 md5,如下所示:
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all md5
# IPv4 local connections:
host all all 127.0.0.1/32 md5
# IPv6 local connections:
host all all ::1/128 md5
# Allow replication connections from localhost, by a user with the
# replication privilege.
#local replication postgres peer
#host replication postgres 127.0.0.1/32 ident
#host replication postgres ::1/128 ident
保存文件。
然后,重启服务器
sudo systemctl restart postgresql
最后,grant all privileges on database testdb to hduser;
我在数据库 mytestdb
employees
的简单 table
我想将此 table 导入 hdfs。
bin/sqoop import --connect 'jdbc:postgresql://127.0.0.1/mytestdb' --username user -P --table employees --target-dir /user/postgres
但是,我一直收到错误消息:
WARNING: SQLException occurred while connecting to 127.0.0.1:5432 org.postgresql.util.PSQLException: FATAL: Ident authentication failed for user "user" at org.postgresql.core.v3.ConnectionFactoryImpl.doAuthentication(ConnectionFactoryImpl.java:473)
/var/lib/pgsql/data/pg_hba.conf
设置如下:
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all md5
# IPv4 local connections:
host all all 127.0.0.1/32 ident
# IPv6 local connections:
host all all ::1/128 ident
# Allow replication connections from localhost, by a user with the
# replication privilege.
#local replication postgres peer
#host replication postgres 127.0.0.1/32 ident
#host replication postgres ::1/128 ident
查看日志文件(对于 CentOS,可能在 /var/lib/pgsql/data/pg_log
中)以获取更多详细信息。
如果用户不存在,请创建。使用 psql
,您可以 create a user 喜欢:
create role hduser with login, superuser;
或来自command line:
createuser -s -e hduser
如果没有安装identd
,请安装:
yum install authd xinetd
然后编辑 /etc/xinet.d/auth
并将 disable = yes
更改为 disable = no
:
service auth
{
disable = no
socket_type = stream
....
}
并重新启动 xinetd
服务:
systemctl restart xinetd
我从网络上的几个不同来源的组合中找到了一个可行的解决方案。
编辑配置文件
nano /var/lib/pgsql/data/pg_hba.configuration
将前两个 ident
替换为 md5,如下所示:
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all md5
# IPv4 local connections:
host all all 127.0.0.1/32 md5
# IPv6 local connections:
host all all ::1/128 md5
# Allow replication connections from localhost, by a user with the
# replication privilege.
#local replication postgres peer
#host replication postgres 127.0.0.1/32 ident
#host replication postgres ::1/128 ident
保存文件。
然后,重启服务器
sudo systemctl restart postgresql
最后,grant all privileges on database testdb to hduser;