Re: Connection to database failed: FATAL: no pg_hba.conf entry for host - Mailing list pgsql-sql
From | Dhaval Patel |
---|---|
Subject | Re: Connection to database failed: FATAL: no pg_hba.conf entry for host |
Date | |
Msg-id | CAKLWWMX9n8N2MWCu1+yn5dYpVT3YZv0TMTwVgDR7xqx-dON48w@mail.gmail.com Whole thread Raw |
In response to | Re: Connection to database failed: FATAL: no pg_hba.conf entry for host (Adrian Klaver <adrian.klaver@aklaver.com>) |
List | pgsql-sql |
<p dir="ltr">Hi, <p dir="ltr">Please look into postgresql.conf file for listen_addresses and set to "*".<div class="gmail_quote">OnApr 13, 2016 4:27 AM, "Adrian Klaver" <<a href="mailto:adrian.klaver@aklaver.com">adrian.klaver@aklaver.com</a>>wrote:<br type="attribution" /><blockquote class="gmail_quote"style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On 04/11/2016 03:31 PM, Chris wrote:<br/><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"> Introduction:<br/><br /> I am working on an application that connects to a postgres database using<br /> the libpq API. Asa requirement the remote host uses SSL.<br /><br /> The scenario involves two Mac computers. We also have two differentusers,<br /> each with their own account to access the database.<br /><br /> On one computer, the application worksfine and both users can connect to<br /> the database using SSL.<br /><br /> On the other computer, both users failto connect to a database and the “no<br /> pg_hba.cong entry for host …” error is returned from PQerrorMessage.<br /><br/> All users can connect to the database on both computers using either psql,<br /> or pgAdmin.<br /><br /> Code Syntax:<br/><br /> Development is done on Mac with code written in Cocoa / Objectice-C, and C<br /> language.<br /><br />I am using the following include file:<br /><br /> #include <libpq-fe.h><br /><br /> I create the connection stringusing the following format. Then<br /><br /> NSString *connstr = [NSString stringWithFormat:@"sslmode='prefer' host='%@'<br/> port='%@' user='%@' password='%@' dbname='%@'", host, port, user, pass, db];<br /><br /> const char *conninfo= [connstr cStringUsingEncoding:NSASCIIStringEncoding];<br /><br /> PGconn *conn = PQconnectdb (conninfo);<br /><br/> /*<br /> conninfo = "sslmode='prefer' host='<a href="http://host.domain.com" rel="noreferrer" target="_blank">host.domain.com</a>'port='' user='username'<br /> password='password' dbname='database'"<br /> */<br /><br/> if (PQstatus(conn) != CONNECTION_OK)<br /> {<br /> // no pg_hba.conf entry for host error occurs<br /> }<br/><br /><br /> Configuration Settings:<br /><br /> pg_hba.conf contains<br /><br /> hostssl all all <ahref="http://0.0.0.0/0" rel="noreferrer" target="_blank">0.0.0.0/0</a> md5<br /><br /><br /> postgresql.conf contains<br/><br /> ssl on on<br /> ssl_cert_file server.crt server.crt<br /> ssl_key_file server.key server.key<br /><br /><br /> Since I able to connect to both computers using psql and pgAdmin,I suspect<br /> the problem is with the connection within the Application. The connection<br /> string in the applicationis correct, and I verified the user name and<br /> password being passed properly.<br /></blockquote><br /> Haveyou verified the other parameters, in particular the port. I am suspicious of the port='' in the above. The error ispretty straight forward, the correct host name is not being found in the the pg_hba.conf file. That means either the hostname is not specified correctly in the file or you are connecting to a different cluster(port) then you think are andare picking up a different pg_hba.conf.<br /><br /><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px#ccc solid;padding-left:1ex"><br /><br /><br /> --<br /> View this message in context: <a href="http://postgresql.nabble.com/Connection-to-database-failed-FATAL-no-pg-hba-conf-entry-for-host-tp5898099.html" rel="noreferrer" target="_blank">http://postgresql.nabble.com/Connection-to-database-failed-FATAL-no-pg-hba-conf-entry-for-host-tp5898099.html</a><br />Sent from the PostgreSQL - sql mailing list archive at Nabble.com.<br /><br /><br /></blockquote><br /><br /> -- <br />Adrian Klaver<br /><a href="mailto:adrian.klaver@aklaver.com" target="_blank">adrian.klaver@aklaver.com</a><br /><br /><br/> -- <br /> Sent via pgsql-sql mailing list (<a href="mailto:pgsql-sql@postgresql.org" target="_blank">pgsql-sql@postgresql.org</a>)<br/> To make changes to your subscription:<br /><a href="http://www.postgresql.org/mailpref/pgsql-sql"rel="noreferrer" target="_blank">http://www.postgresql.org/mailpref/pgsql-sql</a><br/></blockquote></div>