PostgreSQL - FATAL: Ident身份验证失败,用户无法登录。

14

我在Postgres中创建了一个名为employees的简单表,它位于数据库mytestdb中。

我想将这个表导入到HDFS中。

bin/sqoop import --connect 'jdbc:postgresql://127.0.0.1/mytestdb' --username user -P --table employees --target-dir /user/postgres

但是,我一直收到一个错误:

警告:连接到127.0.0.1:5432时发生了SQLException org.postgresql.util.PSQLException:用户"user"的标识验证失败 在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
2个回答

22

我从网上几个不同的来源结合起来找到了可行的解决方案。

编辑配置文件

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;


2
啊,谢谢。针对新用户的更新提示:您可能需要使用sudo service postgresql-XX.service restart(其中XX是您的Postgres版本,我的是11),而不是sudo systemctl restart postgresql - Giampaolo Ferradini
在某些版本中,该文件位于nano /var/lib/pgsql/data/pg_hba.conf - Amos Korir
我曾多次尝试编辑.conf文件,但在此之后使用了sudo systemctl restart。但是,使用service restart命令对我有效。 - NightOwl19

2

查看日志文件(对于CentOS系统,可能位于/var/lib/pgsql/data/pg_log),以获取更多详细信息。

如果用户不存在,则创建用户。使用 psql,您可以像下面这样创建一个用户

create role hduser with login, superuser;

或者从命令行中创建:

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

你的服务器是否在TCP端口113上运行identd?PostgreSQL日志显示什么(在CentOS上,可能是/var/lib/pgsql/data/logs)? - Andomar
我怎么知道identd正在运行?我没有/var/lib/pgsql/data/logs,但是有/var/lib/pgsql/data/pg_log,然后在这个目录中有今天的日志:postgresql-Sun.log。 - usr
1
这是正确的日志,里面有什么有用的信息吗?使用命令如 service identd statusps afx | grep identdtelnet localhost 113netstat -a 检查 identd 是否正在运行。 - Andomar
我怎么知道identd是否在运行? telnet localhost 113 #ftfy - wildplasser

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接