Re: Unable to connect to Postgresql

From: John Iliffe <john(dot)iliffe(at)iliffe(dot)ca>
To: Joe Conway <mail(at)joeconway(dot)com>
Cc: pgsql-general(at)postgresql(dot)org, Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>
Subject: Re: Unable to connect to Postgresql
Date: 2017-04-09 18:33:10
Message-ID: 201704091433.10196.john.iliffe@iliffe.ca
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Saturday 08 April 2017 18:10:35 Joe Conway wrote:
> On 04/08/2017 01:23 PM, John Iliffe wrote:
> > On Saturday 08 April 2017 09:38:07 Adrian Klaver wrote:
> >> So what if you change the connection to use -h localhost?
> >
> > Can you please expand on that request? I'm not sure where you want me
> > to put that directive. I'm using the mod_php module in Apache.
>
> See the second example here:
>
> http://php.net/manual/en/function.pg-connect.php
>
> 8<-------------
> $dbconn2 = pg_connect("host=localhost port=5432 dbname=mary");
> // connect to a database named "mary" on "localhost" at port "5432"
> 8<-------------
>
> That will try to use a tcp connection on localhost instead of a unix
> socket.
>
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');
---------------------------

Even though "localhost" is in the /etc/hosts file the lookup failed to
resolve so I provided the full IP address. The error from Apache is:

------------------------------------------
[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
-------------------------------------------

PHP does not show anything in its log.

> Another question I don't believe has been asked is, what does your
> pg_hba.conf look like?

Note here that I have deleted a number of production users and the
associated databases from the file shown below for security reasons. The
user marked "XXXXXXX" has a real name but isn't the one we are using to
connect to the database, so the active line should be the "local all all
password" line. The UID being used to connect IS in the password list and
PSQL can still connect OK. The yrarc database does exist and contains
several tables.

--------------------------------------
# TYPE DATABASE USER ADDRESS METHOD

# "local" is for Unix domain socket connections only
#local all all md5

local yrarc XXXXXXX trust
local all all password
#local all all trust
# IPv4 local connections:
host all all 127.0.0.1/32 trust
---------------------------------------------

>
> Joe

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Joe Conway 2017-04-09 18:34:01 Re: Unable to connect to Postgresql
Previous Message Adrian Klaver 2017-04-09 15:36:01 Re: Aggregate query on large tables