Skip to content
Advertisement

Why am I getting SQL State: 28000 FATAL: Ident authentication failed for user error message when running a simple Java program?

I have a Postgres 11 database installed on a VirtualBox virtual machine running Centos7 (guest machine), and my host machine is a Mac OS Catalina. Both the guest (Centos) and host (Catalina) have JDK 8 installed.

I have the following simple Java code that uses a single dependency postgresql-42.2.5:

JavaScript

I compile and run this on my host (Catalina) :

JavaScript

and the output I get is:

JavaScript

So clearly this means I can connect to the Postgres database from my host to my guest. Next, I test whether I can connect directly from my guest. So I copy “JavaApplication5.jar” into guest Virtual Machine running Centos 7 and re-run the same command. However, this time I am getting the following message from the same executable jar file:

JavaScript

Does anybody know why I am getting this error on the guest virtual machine but not on the host?

Here is the relevant portion of my my pg_hba.conf file:

JavaScript

Advertisement

Answer

You must have port forwarding set up in your VirtualBox to capture connection attempts on the host to that port and route them to the VB. So while you specify 127.0.0.1, they are coming from someplace else as far as PostgreSQL is concerned. That matches the ‘md5’ line of your pg_hba.conf. When done from the guest, the connections really are coming from 127.0.0.1, and so match the earlier ‘ident’ line.

The ‘ident’ authentication is failing, for reasons surely mentioned in the log file. If you don’t want to use ‘ident’, remove those lines.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement