Postgres pg_hba.conf localhost confusion

810 views Asked by At

I've run into a scenario where an application couldn't see the database. My pg_hba.conf file had the following:

local   all             all                                     trust
host    all             all             127.0.0.1/32            trust
host    all             all             ::1/128                 trust

Security aside, the application was telling me it couldn't see the database at all, while other clients could see it:

PG::ConnectionBad: could not connect to server: Connection refused
    Is the server running on host "127.0.0.1" and accepting
    TCP/IP connections on port 5432?
 (Sequel::DatabaseConnectionError)

I had to point my application to the public IP of that box, and add that in my pg_hba.conf for it to work. Also, it was confused with localhost, as it apparently looked at the IP6 route then the IP4 route, both throwing an error:

Could not spawn process for application /var/www/pints: The application encountered the following error: PG::ConnectionBad: could not connect to server: Connection refused
  Is the server running on host "localhost" (::1) and accepting
  TCP/IP connections on port 5432?
could not connect to server: Connection refused
  Is the server running on host "localhost" (127.0.0.1) and accepting
  TCP/IP connections on port 5432?
 (Sequel::DatabaseConnectionError)

Question: What is the best way to force this into using the IP4 route, and to best use IP4 resources to handle communications while on the same box? localhost was blind, as was 127.0.0.1, so I'm confused. Cheers

0

There are 0 answers