At 12:02 PM 5/24/04, Keary Suska wrote:
on 5/24/04 7:37 AM, fbax@xxxxxxxxxxxx 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.
telnet is disabled on OpenBSD by default by "ssh localhost" works fine.
Also check your nsswitch.conf.
No such file on the system.
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.
I couldn't figure out OpenBSD options for netstat. Do these prove the same
thing?
# netstat -l | grep 5432
0xd187f7d8 stream 0 0 0xe8844498 0x0 0x0 0x0
/tmp/.s.PGSQL.5432
# fstat | head -n 1 ; fstat | grep 5432
USER CMD PID FD MOUNT INUM MODE R/W DV|SZ
_pgsql postgres 5444 3* internet stream tcp 0xd18729dc *:5432
This also works:
$ psql -h localhost dbname dbname
> # 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.
Change order and/or removal of IPV6 entry has no effect.
Another possibility is that something is blocking the connection, like a
firewall.
I don't think any firewall software is installed/active by default and I
didn't install/activate any.
Frank