Re: Unable to connect to Postgresql

From: Joe Conway <mail(at)joeconway(dot)com>
To: John Iliffe <john(dot)iliffe(at)iliffe(dot)ca>, pgsql-general(at)postgresql(dot)org
Cc: Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>
Subject: Re: Unable to connect to Postgresql
Date: 2017-04-09 19:41:12
Message-ID: 6e7db8bf-43f9-1de1-2942-f81c39a1cf16@joeconway.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 04/09/2017 12:37 PM, John Iliffe wrote:
>> > Thanks Joe. I Changed the pg_connect line in the script to:
>> > $db_handle = pg_connect('dbname=yrarc host=192.168.1.6 port=5432
>> > user=xxxx password=xxxxxx');

> If I may be permitted a rant at this point, the Fedora documentation is
> almost useless for SELinux and much of the underlying operating system.

Maybe so, but as I said earlier if you are in permissive, then blaming
any of these issues on selinux is wrong -- selinux does no enforcement
in permissive.

>> You have no pg_hba.conf rule for host=192.168.1.6 so it is not
>> surprising that cannot connect. You need something like:
>>
>> # only allow connections from one host using tcp
>> host all all 192.168.1.6/32 md5
>>
>> - or maybe -
>>
>> # only allow connections from same subnet using tcp
>> host all all 192.168.1.0/24 md5
>>
> I don't think I should need that since httpd/mod_php is on the same machine
> so should be 127.0.0.1 should cover it.

No, not if your connection string is

'dbname=yrarc host=192.168.1.6 port=5432 user=xxxx password=xxxxxx'

as you said it was. In this case you must have one of the two pg_hba
lines above or something more broad. With that connection string you are
not connecting to localhost, you are connecting to 192.168.1.6 and there
MUST be a pg_hba line to support it.

> "trust" to avoid any problems with permissions in Postgresql.

Trust has nothing whatsoever to do with the problems you have shown us
so far.

> PHP and Postgresql are both running on same box. It does have two
> interfaces, 192.168.1.6 and 192.168.1.7, and the test programme is
> available on either. The reference to 192.168.1.10 is the client machine,
> in this case my workstation, which is 192.168.1.10.

Here is the error message you said came from the box running PHP:

>> > ------------------------------------------
>> > [Sun Apr 09 14:08:16.178126 2017] [php7:warn] [pid 24917:tid
>> > 139671464015616] [client 192.168.1.10:59260] PHP Warning:
>> > pg_connect(): Unable to connect to PostgreSQL server: could not
>> > connect to server: Connection refused\n\tIs the server running on
>> > host &quot;192.168.1.6&quot; and accepting\n\tTCP/IP connections on
>> > port 5432? in
>> > /httpd/iliffe/testfcgi.php on line 132
>> > -------------------------------------------

Now, if your workstation is 192.168.1.10, then I can only conclude that
you are running PHP on your workstation and *not* on the box with
Postgres which you say uses 192.168.1.6 and 192.168.1.7.

Joe

--
Crunchy Data - http://crunchydata.com
PostgreSQL Support for Secure Enterprises
Consulting, Training, & Open Source Development

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message John Iliffe 2017-04-09 19:43:59 Re: Unable to connect to Postgresql
Previous Message Adrian Klaver 2017-04-09 19:38:10 Re: Unable to connect to Postgresql