Thread: connection fails

connection fails

From
paula@cyberlazarus.net
Date:
Hello,

I\'m trying to connect using an extremely simple php script:

$conn = pg_Connect(\"host=localhost dbname=db name user=postgres password=postgres\");

if ($conn) { echo \"ok\"; }
else { echo \"failed\"; }

I get this error message:

Warning: Unable to connect to PostgreSQL server: connectDBStart() -- connect() failed: Connection refused Is the
postmasterrunning (with -i) at \'localhost\' and accepting connections on TCP/IP port 5432? in
/var/www/sts.twcable.com/launch_plan/test/c.phpon line 3 
failed

I also tried to work from the command line and get similar error messages.
The weird thing is that phpPgAdmin is working fine and this script works:

 $database = pg_Connect (\"dbname=dbname\");
 pg_exec ($database, \"begin\");
 $oid = pg_locreate ($database);
 echo (\"$oid\\n\");
 $handle = pg_loopen ($database, $oid, \"w\");
 echo (\"$handle\\n\");
 pg_lowrite ($handle, \"gaga\");
 pg_loclose ($handle);
 pg_exec ($database, \"commit\");

[script coming from php.net]

Any ideas??

thnx!
/paula


----------------------------------------------------------------
:: www.nervemail.net :: free access to POP3 accounts


Re: connection fails

From
Keary Suska
Date:
Postgres already gave you the first idea:

> failed: Connection refused Is the postmaster running (with -i) at
> \'localhost\' and accepting connections on TCP/IP port 5432? in
> /var/www/sts.twcable.com/launch_plan/test/c.php on line 3
> failed

Since you are using TCP to connect, have you verified that postmaster is
actually listening and on the expected port? It doesn't by default--by
default it uses a unix domain socket. You have to specify TCP using the -i
option.

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

> From: paula@cyberlazarus.net
> Reply-To: paula@cyberlazarus.net
> Date: 21 Sep 2001 19:25:25 -0000
> To: pgsql-general@postgresql.org
> Subject: [GENERAL] connection fails
>
> Hello,
>
> I\'m trying to connect using an extremely simple php script:
>
> $conn = pg_Connect(\"host=localhost dbname=db name user=postgres
> password=postgres\");
>
> if ($conn) { echo \"ok\"; }
> else { echo \"failed\"; }
>
> I get this error message:
>
> Warning: Unable to connect to PostgreSQL server: connectDBStart() -- connect()
>
> I also tried to work from the command line and get similar error messages.
> The weird thing is that phpPgAdmin is working fine and this script works:
>
> $database = pg_Connect (\"dbname=dbname\");
> pg_exec ($database, \"begin\");
> $oid = pg_locreate ($database);
> echo (\"$oid\\n\");
> $handle = pg_loopen ($database, $oid, \"w\");
> echo (\"$handle\\n\");
> pg_lowrite ($handle, \"gaga\");
> pg_loclose ($handle);
> pg_exec ($database, \"commit\");
>
> [script coming from php.net]
>
> Any ideas??
>
> thnx!
> /paula
>
>
> ----------------------------------------------------------------
> :: www.nervemail.net :: free access to POP3 accounts
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Don't 'kill -9' the postmaster
>


Re: connection fails

From
"Nick Fankhauser"
Date:
I'm not a PHP-er, but I notice that a difference between the script that
works & the one that doesn't is the "host=... portion. Could it be that
phpPgAdmin & the script that works do *not* use tcpip to connect & while the
failing script does?

If so, the message you got also contains the answer- you need to turn the
tcpip_socket on in the .conf file, or change the first script to not specify
a host.

-Nick

> -----Original Message-----
> From: pgsql-general-owner@postgresql.org
> [mailto:pgsql-general-owner@postgresql.org]On Behalf Of
> paula@cyberlazarus.net
> Sent: Friday, September 21, 2001 2:25 PM
> To: pgsql-general@postgresql.org
> Subject: [GENERAL] connection fails
>
>
> Hello,
>
> I\'m trying to connect using an extremely simple php script:
>
> $conn = pg_Connect(\"host=localhost dbname=db name user=postgres
> password=postgres\");
>
> if ($conn) { echo \"ok\"; }
> else { echo \"failed\"; }
>
> I get this error message:
>
> Warning: Unable to connect to PostgreSQL server: connectDBStart()
> -- connect() failed: Connection refused Is the postmaster running
> (with -i) at \'localhost\' and accepting connections on TCP/IP
> port 5432? in /var/www/sts.twcable.com/launch_plan/test/c.php on line 3
> failed
>
> I also tried to work from the command line and get similar error messages.
> The weird thing is that phpPgAdmin is working fine and this script works:
>
>  $database = pg_Connect (\"dbname=dbname\");
>  pg_exec ($database, \"begin\");
>  $oid = pg_locreate ($database);
>  echo (\"$oid\\n\");
>  $handle = pg_loopen ($database, $oid, \"w\");
>  echo (\"$handle\\n\");
>  pg_lowrite ($handle, \"gaga\");
>  pg_loclose ($handle);
>  pg_exec ($database, \"commit\");
>
> [script coming from php.net]
>
> Any ideas??
>
> thnx!
> /paula
>
>
> ----------------------------------------------------------------
> :: www.nervemail.net :: free access to POP3 accounts
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Don't 'kill -9' the postmaster
>


Re: connection fails

From
"Joe Conway"
Date:
> I'm not a PHP-er, but I notice that a difference between the script that
> works & the one that doesn't is the "host=... portion. Could it be that
> phpPgAdmin & the script that works do *not* use tcpip to connect & while
the
> failing script does?
>
> If so, the message you got also contains the answer- you need to turn the
> tcpip_socket on in the .conf file, or change the first script to not
specify
> a host.
>

You may also have to modify pg_hba.conf (in addition to postgresql.conf).
See the comments in the file for details, but you need a line something
like:

host       all         172.16.0.0    255.255.0.0        password

where 172.16.0.0 is replaced by the appropriate network and 255.255.0.0 by
the appropriate netmask.

Hope this helps,

Joe



Re: connection fails

From
"Nick Fankhauser"
Date:
You may be able to get away without this if localhost is the only host
involved- I'm pretty sure the default pg_hba.conf file already has localhost
set up in it. (I'm sure it does in the Debian package, and would guess this
is true of the others.)

> You may also have to modify pg_hba.conf (in addition to postgresql.conf).
> See the comments in the file for details, but you need a line something
> like:
>
> host       all         172.16.0.0    255.255.0.0        password
>
> where 172.16.0.0 is replaced by the appropriate network and 255.255.0.0 by
> the appropriate netmask.


-Nick