Re: unable to connect to pgsql server

From: Keary Suska <hierophant(at)pcisys(dot)net>
To: Postgres-PHP <pgsql-php(at)postgresql(dot)org>, Frank Bax <fbax(at)sympatico(dot)ca>
Subject: Re: unable to connect to pgsql server
Date: 2004-05-24 16:02:03
Message-ID: BCD7789B.11230%hierophant@pcisys.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-php

on 5/24/04 7:37 AM, fbax(at)sympatico(dot)ca purportedly said:

> I have a working system on OpenBSD 2.9 / PHP 4.0.4pl1 / pgsql 7.1 / phplib 7.4
> I created a new system on OpenBSD 3.5 / PHP 4.3.5RC3 / pgsql 7.3.5 / phplib
> 7.4
> I copied an existing database and php/phplib application to the new box for
> testing, but when I try to access the application webpage, I get the
> following message in apache error log:
> PHP Warning: pg_connect(): Unable to connect to PostgreSQL server: unknown
> host name: localhost in /php/class/phplib-7.4/db_pgsql.inc on line 51

Usually, this is either because PHP can't resolve localhost, or the Postgres
server can't/isn't responding. Can you use localhost otherwise? E.g.:
$ telnet localhost
Even if telnetd isn't running, you should get two different messages--one
that indicates the host won't resolve, and the other indicating that the
host isn't responding (if telnetd isn't running). If you cannot use
localhost from the command line you probably have some other configuration
problem. Also check your nsswitch.conf.

If the above works, make sure the postmaster (Postgres server) has enabled
IP connections. First check if Postmaster is listening using netstat. On my
Linux box, I would use netstat -lnp (but your options may be different). If
it is, check to make sure you are using the correct port. The default is
5432, so if you don't specify the port in the connect string the default
port will be used.

Another possibility is that something is blocking the connection, like a
firewall.

> # cat /etc/hosts | grep -v ^#
> ::1 localhost
> 127.0.0.1 localhost

If nothing else works, this is a wild guess, but I don't know if PHP has
IPv6 support. Just for the heck of it, you may want to try reversing the
above lines in your hosts file so PHP sees the IPv4 address first.

Best,

Keary Suska
Esoteritech, Inc.
"Leveraging Open Source for a better Internet"

In response to

Responses

Browse pgsql-php by date

  From Date Subject
Next Message Frank Bax 2004-05-24 20:59:21 Re: unable to connect to pgsql server
Previous Message Frank Bax 2004-05-24 14:36:34 Re: unable to connect to pgsql server