Postgresql problem

David Keen keend at btinternet.com
Sun Apr 18 14:53:19 UTC 2004


On Sun, 2004-04-18 at 03:32, gm wrote:
>  
> 
>  
> 
> Hey guys
> 
>  
> 
> I get this error in php:
> 
>  
> 
> Warning: pg_connect(): Unable to connect to PostgreSQL server: could
> not connect to server: Connection refused Is the server running on
> host localhost and accepting TCP/IP connections on port 5432? . in
> /www/index.php on line 7
> 
>  
> 
> PHP code
> 
>  
> 
> $conn = pg_connect("host=localhost user=***** password=****
> 
> dbname=***** ");
> 
>  
> 
>  
> 
>  
> 
> I’ve taken down the iptables and I know psql is working since I
> created a table and populated with data. What could be missing/wrong?

Sounds like PostgreSQL is only listening on unix domain sockets.  You
can change this setting in your postgresql.conf file.  Also Look in your
pg_hba.conf for authentication settings.

Unless you need to connect to your database via tcp/ip you should change
your connection string to connect via unix sockets.  If you use PEARDB
(which I would recommend) you can use something like:
pgsql://$username:$password@unix+$hostname/$dbname.

I'm not sure about pg_connect() but this is the very first comment on
the PHP site under pg_connect():
If you use pg_connect('host=localhost port=5432 user=my_username
password=my_password dbname=my_dbname') and you get the following error:
"Warning: pg_connect(): Unable to connect to PostgreSQL server: could
not connect to server: Connection refused Is the server running on host
localhost and accepting TCP/IP connections on port 5432?"
then you should try to leave the host= and port= parts out of the
connection string. This sounds strange, but this is an "option" of
Postgre. If you have not activated the TCP/IP port in postgresql.conf
then postgresql doesn't accept any incoming requests from an TCP/IP
port. If you use host= in your connection string you are going to
connect to Postgre via TCP/IP, so that's not going to work. If you leave
the host= part out of your connection string you connect to Postgre via
the Unix domain sockets, which is faster and more secure, but you can't
connect with the database via any other PC as the localhost.

Cheers
-- 
David Keen <keend at btinternet.com>





More information about the fedora-list mailing list