Thread: Unable to connect to PostgreSQL server : Could not get socket error status

Unable to connect to PostgreSQL server : Could not get socket error status

From
Shankar Palaniappan
Date:
Hi,

Unable to connect to PostgreSQL server : Could not get socket error
status: No such file or directory in index.php on line 5

Can any one help me on this ?

I am getting the following error when I try to connect from PHP with
PostgreSQL server.
Operating System is HP-UX and I was able to connect through PostgreSQL
server from psql,

Re: Unable to connect to PostgreSQL server : Could not get socket error status

From
John R Pierce
Date:
On 12/22/11 1:31 AM, Shankar Palaniappan wrote:
> I am getting the following error when I try to connect from PHP with
> PostgreSQL server.
> Operating System is HP-UX and I was able to connect through PostgreSQL
> server from psql,

what postgres connection parameters are you passing to the php
connection function?  if you specified host=localhost, or some such,
then on psql use -h localhost to simulate this.



--
john r pierce                            N 37, W 122
santa cruz ca                         mid-left coast


Re: Unable to connect to PostgreSQL server : Could not get socket error status

From
Shankar Palaniappan
Date:
On Dec 22, 11:12 pm, pie...@hogranch.com (John R Pierce) wrote:
> On 12/22/11 1:31 AM, Shankar Palaniappan wrote:
>
> > I am getting the following error when I try to connect from PHP with
> > PostgreSQL server.
> > Operating System is HP-UX and I was able to connect through PostgreSQL
> > server from psql,
>
> what postgres connection parameters are you passing to the php
> connection function?  if you specified host=localhost, or some such,
> then on psql use -h localhost to simulate this.
>
> --
> john r pierce                            N 37, W 122
> santa cruz ca                         mid-left coast
>
> --
> Sent via pgsql-general mailing list (pgsql-gene...@postgresql.org)
> To make changes to your subscription:http://www.postgresql.org/mailpref/pgsql-general


Hi John,

Thanks for your response.

I am able to connect to the database through psql command. Please find
the commands that I have tried through PHP and no success for past 3
days.
Please let me know whether you can help me in this issue.

<?php
ini_set('track_errors','on');
// attempt a connection
$dbh = pg_connect("host=/tmp/ dbname=test_tool port=5495 user=apache
password=apache connect_timeout=20");
// $dbh = pg_connect("host=localhost port=5495 dbname=test_tool");
// $options = " host='localhost' port='5495' user='gls' password=''
dbname='test_tool' ";
// $dbh=pg_connect($options);
if (!$dbh) {
    die("Error in connection: " . pg_last_error($dbh));
print_r($dbh);
}

else
{
echo "Connection is success";
}

?>

Re: Re: Unable to connect to PostgreSQL server : Could not get socket error status

From
Adrian Klaver
Date:
On Friday, December 23, 2011 1:32:49 am Shankar Palaniappan wrote:

> Hi John,
>
> Thanks for your response.
>
> I am able to connect to the database through psql command. Please find
> the commands that I have tried through PHP and no success for past 3
> days.
> Please let me know whether you can help me in this issue.

Some questions:
1) What is the connection string are you using for psql?
2) How are you connecting in each case(PHP,psql), remotely or locally?
3) What is listen_addresses set to in postgresql.conf?


>
> <?php
> ini_set('track_errors','on');
> // attempt a connection
> $dbh = pg_connect("host=/tmp/ dbname=test_tool port=5495 user=apache
> password=apache connect_timeout=20");
> // $dbh = pg_connect("host=localhost port=5495 dbname=test_tool");
> // $options = " host='localhost' port='5495' user='gls' password=''
> dbname='test_tool' ";
> // $dbh=pg_connect($options);
> if (!$dbh) {
>     die("Error in connection: " . pg_last_error($dbh));
> print_r($dbh);
> }
>
> else
> {
> echo "Connection is success";
> }
>
> ?>

--
Adrian Klaver
adrian.klaver@gmail.com

Re: Unable to connect to PostgreSQL server : Could not get socket error status

From
Shankar Palaniappan
Date:
On Dec 23, 7:51 pm, adrian.kla...@gmail.com (Adrian Klaver) wrote:
> On Friday, December 23, 2011 1:32:49 am Shankar Palaniappan wrote:
>
> > Hi John,
>
> > Thanks for your response.
>
> > I am able to connect to the database through psql command. Please find
> > the commands that I have tried through PHP and no success for past 3
> > days.
> > Please let me know whether you can help me in this issue.
>
> Some questions:
> 1) What is the connection string are you using for psql?

psql -p 5495 -d support_tool -U gls -h localhost

> 2) How are you connecting in each case(PHP,psql), remotely or locally?
I am connecting the psql from local and PHP from remote system. I was
also able to access the postgres from the same system using C program

> 3) What is listen_addresses set to in postgresql.conf?

I am running the postmaster with

postmaster -i -D /path

I am running with the following version and I dont have the privilege
to update the existing versions.  listen_addresses option is not
available in the existing version

postmaster (PostgreSQL) 7.4.2
PHP 5.2.6

Today I found one issue.. where I was not able to run the postmaster
with -h option ( that is not other than localhost)

The error what I got is that it was not able to create the listening
socket.

LOG:  could not bind IPv4 socket: Can't assign requested address
HINT:  Is another postmaster already running on port 5496? If not,
wait a few seconds and retry.
FATAL:  could not create listen socket for "IP address"

Please help me to resolve the issue. I dont have root privilege to
access the system

Thanks,
Shankar

>
>
>
>
>
>
>
> > <?php
> > ini_set('track_errors','on');
> > // attempt a connection
> > $dbh = pg_connect("host=/tmp/ dbname=test_tool port=5495 user=apache
> > password=apache connect_timeout=20");
> > // $dbh = pg_connect("host=localhost port=5495 dbname=test_tool");
> > // $options = " host='localhost' port='5495' user='gls' password=''
> > dbname='test_tool' ";
> > // $dbh=pg_connect($options);
> > if (!$dbh) {
> >     die("Error in connection: " . pg_last_error($dbh));
> > print_r($dbh);
> > }
>
> > else
> > {
> > echo "Connection is success";
> > }
>
> > ?>
>
> --
> Adrian Klaver
> adrian.kla...@gmail.com
>
> --
> Sent via pgsql-general mailing list (pgsql-gene...@postgresql.org)
> To make changes to your subscription:http://www.postgresql.org/mailpref/pgsql-general- Hide quoted text -
>
> - Show quoted text -


Re: Re: Unable to connect to PostgreSQL server : Could not get socket error status

From
Raymond O'Donnell
Date:
On 24/12/2011 12:54, Shankar Palaniappan wrote:
> On Dec 23, 7:51 pm, adrian.kla...@gmail.com (Adrian Klaver) wrote:
>> On Friday, December 23, 2011 1:32:49 am Shankar Palaniappan wrote:
>>
>>> Hi John,
>>
>>> Thanks for your response.
>>
>>> I am able to connect to the database through psql command. Please find
>>> the commands that I have tried through PHP and no success for past 3
>>> days.
>>> Please let me know whether you can help me in this issue.
>>
>> Some questions:
>> 1) What is the connection string are you using for psql?
>
> psql -p 5495 -d support_tool -U gls -h localhost
>
>> 2) How are you connecting in each case(PHP,psql), remotely or locally?
> I am connecting the psql from local and PHP from remote system. I was
> also able to access the postgres from the same system using C program
>
>> 3) What is listen_addresses set to in postgresql.conf?
>
> I am running the postmaster with
>
> postmaster -i -D /path
>
> I am running with the following version and I dont have the privilege
> to update the existing versions.  listen_addresses option is not
> available in the existing version
>
> postmaster (PostgreSQL) 7.4.2
> PHP 5.2.6
>
> Today I found one issue.. where I was not able to run the postmaster
> with -h option ( that is not other than localhost)
>
> The error what I got is that it was not able to create the listening
> socket.
>
> LOG:  could not bind IPv4 socket: Can't assign requested address
> HINT:  Is another postmaster already running on port 5496? If not,
> wait a few seconds and retry.

I don't know if this will help, but you have port 5496 here, and port
5495 in your psql command above.

Also, PostgreSQL 7.* is VERY old, and as far as I know is no longer
being maintained - so if you're being bitten by a bug, it's probably not
going to get fixed. You should upgrade if you can, or move to a
different service provider if you can't.

Ray.

--
Raymond O'Donnell :: Galway :: Ireland
rod@iol.ie

Re: Re: Unable to connect to PostgreSQL server : Could not get socket error status

From
Adrian Klaver
Date:
On Saturday, December 24, 2011 4:54:04 am Shankar Palaniappan wrote:
> On Dec 23, 7:51 pm, adrian.kla...@gmail.com (Adrian Klaver) wrote:
> > On Friday, December 23, 2011 1:32:49 am Shankar Palaniappan wrote:
> > > Hi John,
> > >
> > > Thanks for your response.
> > >
> > > I am able to connect to the database through psql command. Please find
> > > the commands that I have tried through PHP and no success for past 3
> > > days.
> > > Please let me know whether you can help me in this issue.
> >
> > Some questions:
> > 1) What is the connection string are you using for psql?
>
> psql -p 5495 -d support_tool -U gls -h localhost
>
> > 2) How are you connecting in each case(PHP,psql), remotely or locally?
>
> I am connecting the psql from local and PHP from remote system. I was
> also able to access the postgres from the same system using C program

Well in a previous post you indicated your connection strings for the PHP code
where:

$dbh = pg_connect("host=/tmp/ dbname=test_tool port=5495 user=apache
password=apache connect_timeout=20");
// $dbh = pg_connect("host=localhost port=5495 dbname=test_tool");
// $options = " host='localhost' port='5495' user='gls' password=''
dbname='test_tool' ";


The above would not work if you are trying to connect to a remote server. The
first tries to connect to a local socket and the other two are attempts to
connect to localhost.  Your host would need to be the hostname(ip address) of
the host that the Postgres server is running on.

>
> I am running the postmaster with
>
> postmaster -i -D /path
>
> I am running with the following version and I dont have the privilege
> to update the existing versions.  listen_addresses option is not
> available in the existing version
>
> postmaster (PostgreSQL) 7.4.2
> PHP 5.2.6
>
> Today I found one issue.. where I was not able to run the postmaster
> with -h option ( that is not other than localhost)
>
> The error what I got is that it was not able to create the listening
> socket.
>
> LOG:  could not bind IPv4 socket: Can't assign requested address
> HINT:  Is another postmaster already running on port 5496? If not,
> wait a few seconds and retry.
> FATAL:  could not create listen socket for "IP address"

This would seem to indicate what the HINT says, that another  Postgres server is
running.

>
> Please help me to resolve the issue. I dont have root privilege to
> access the system
>
> Thanks,
> Shankar


--
Adrian Klaver
adrian.klaver@gmail.com