Connection to database failed: FATAL: no pg_hba.conf entry for host

From: Chris <cglenstark(at)apple(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: Connection to database failed: FATAL: no pg_hba.conf entry for host
Date: 2016-04-11 22:31:26
Message-ID: 1460413886714-5898099.post@n5.nabble.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Introduction:

I am working on an application that connects to a postgres database using
the libpq API. As a requirement the remote host uses SSL.

The scenario involves two Mac computers. We also have two different users,
each with their own account to access the database.

On one computer, the application works fine and both users can connect to
the database using SSL.

On the other computer, both users fail to connect to a database and the “no
pg_hba.cong entry for host …” error is returned from PQerrorMessage.

All users can connect to the database on both computers using either psql,
or pgAdmin.

Code Syntax:

Development is done on Mac with code written in Cocoa / Objectice-C, and C
language.

I am using the following include file:

#include <libpq-fe.h>

I create the connection string using the following format. Then

NSString *connstr = [NSString stringWithFormat:@"sslmode='prefer' host='%@'
port='%@' user='%@' password='%@' dbname='%@'", host, port, user, pass, db];

const char *conninfo = [connstr cStringUsingEncoding:NSASCIIStringEncoding];

PGconn *conn = PQconnectdb (conninfo);

/*
conninfo = "sslmode='prefer' host='host.domain.com' port='' user='username'
password='password' dbname='database'"
*/

if (PQstatus(conn) != CONNECTION_OK)
{
// no pg_hba.conf entry for host error occurs
}

Configuration Settings:

pg_hba.conf contains

hostssl all all 0.0.0.0/0 md5

postgresql.conf contains

ssl on on
ssl_cert_file server.crt server.crt
ssl_key_file server.key server.key

Since I able to connect to both computers using psql and pgAdmin, I suspect
the problem is with the connection within the Application. The connection
string in the application is correct, and I verified the user name and
password being passed properly.

--
View this message in context: http://postgresql.nabble.com/Connection-to-database-failed-FATAL-no-pg-hba-conf-entry-for-host-tp5898099.html
Sent from the PostgreSQL - sql mailing list archive at Nabble.com.

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Adrian Klaver 2016-04-12 22:56:44 Re: Connection to database failed: FATAL: no pg_hba.conf entry for host
Previous Message Michael Moore 2016-04-08 23:11:59 ST_DWithin not using meters even when SRID unit = "metre"