14

I've created a simple table in postgres called employees in database mytestdb

I would like to import this table into hdfs.

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

But, I keep receiving an error:

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 set up as follows:

# 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
usr
  • 782
  • 1
  • 7
  • 25

2 Answers2

22

I found a workable solution from a combination of several different sources on the web.

Edit the configuration file

nano /var/lib/pgsql/data/pg_hba.configuration

Replace the first two ident's with md5, like so:

# 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

Save file.

Then, restart the server

sudo systemctl restart postgresql

Lastly, grant all privileges on database testdb to hduser;

usr
  • 782
  • 1
  • 7
  • 25
  • 2
    Ah, thanks. An update for newer users: you might need `sudo service postgresql-XX.service restart` (where XX is your Postgres release, 11 in my case) instead than `sudo systemctl restart postgresql` – Giampaolo Ferradini May 03 '20 at 23:23
  • In some versions, the file is located at nano /var/lib/pgsql/data/pg_hba.conf – Amos Korir Jan 08 '21 at 07:48
  • I'd been trying editing the .conf file multiple times but was using `sudo systemctl restart` post that. But, using the `service restart` command worked for me. – NightOwl19 Mar 24 '22 at 17:52
2

Check the log file in (for CentOS, probably in /var/lib/pgsql/data/pg_log) for more details.

If the user doesn't exist, create it. With psql, you can create a user like:

create role hduser with login, superuser;

Or from the command line:

createuser -s -e hduser

If identd is not installed, install it:

yum install authd xinetd

Then edit /etc/xinet.d/auth and change disable = yes to disable = no:

service auth 
{ 
        disable = no 
        socket_type = stream 
        ....
}

And restart the xinetd service:

systemctl restart xinetd
Andomar
  • 232,371
  • 49
  • 380
  • 404
  • Is your server running [`identd`](https://www.postgresql.org/docs/current/static/auth-methods.html#AUTH-IDENT) on tcp port 113? What do the postgres logs say (on centos, probably /var/lib/pgsql/data/logs) ? – Andomar Apr 29 '18 at 10:04
  • How would I know identd is running? I don't have /var/lib/pgsql/data/logs, but there's /var/lib/pgsql/data/pg_log and then today's log: postgresql-Sun.log in this directory – usr Apr 29 '18 at 10:12
  • 1
    That's the right log, anything useful in it? Check if identd is running with commands like `service identd status`, `ps afx | grep identd`, `telnet localhost 113`, `netstat -a` – Andomar Apr 29 '18 at 10:16
  • How would I know identd is running? `telnet localhost 113` #ftfy – wildplasser Apr 29 '18 at 10:38