3

I have a PostgreSQL DB sitting on my local machine (Windows) and I would like to import it into my Hortonworks Sandbox using Apache Sqoop. While something like this sounds great, the complicating factor is that my Sandbox is sitting in a Docker container, so statements such as sqoop list-tables --connect jdbc:postgresql://127.0.0.1/ambari --username ambari -P seem to run into authentication errors. I believe the issue comes from trying to connect to the local host from inside the docker container.

I looked at this post on connecting to a MySQL DB from within a container and this one to try to use PostgreSQL instead, but have so far been unsuccessful. I have tried connecting to '127.0.0.1' and '172.17.0.1' (the host's IP) in order to connect to my local host from within Docker. I have also adjusted PostgreSQL's configuration file to listen for connections on all IP addresses. However, I still get the following error messages when I run sqoop list-tables --connect jdbc:postgresql://<ip>:5432/<db_name> --username postgres -P (where <ip> is either 127.0.0.1 or 172.17.0.1, and <db_name> is the name of my database)

For connecting with 127.0.0.1:

ERROR sqoop.Sqoop: Got exception running Sqoop: java.lang.RuntimeException: org.postgresql.util.PSQLException: FATAL: Ident authentication failed for user "postgres"

For connecting with 172.17.0.1:

Connection refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.

Any suggestions would be very helpful!

tgordon18
  • 1,562
  • 1
  • 19
  • 31

1 Answers1

0

If this is just for local testing and not for production level coding, you can enable all trusted connections to your database by updating the pg_hba.conf file

  1. Locate your pg_hba.conf file inside your postgres data directory
  2. Vim the file and update it with the following lines:

    #TYPE DATABASE USER ADDRESS METHOD local all all trust host all all 0.0.0.0/0 trust host all all ::1/128 trust

  3. Restart your postgres service

If you do this, your first use case (using 127.0.0.1) should work

Alan Kavanagh
  • 9,425
  • 7
  • 41
  • 65
  • Sorry I should've mentioned that I'm doing this on Windows, which means the local/all/all/trust doesn't work (see [this article](https://stackoverflow.com/questions/16846363/postgresql-9-2-4-windows-7-service-wont-start-could-not-load-pg-hba-conf)) – tgordon18 Oct 17 '17 at 17:41