Thread: Request assistance connecting with Pg::connectdb

Request assistance connecting with Pg::connectdb

From
"Wright, Ryan P"
Date:
Hello,

I am having a heck of a time connecting to my postgres server, and was
hoping some kind soul would advise me on how to proceed.

The problem: Perl script dies with no error message.

Code snippet:

$conn = Pg::connectdb("dbname=testdb host=localhost port=5432 user=postgres
password=test");
print "status = ",$conn->status, "\n";
die $conn->errorMessage unless PGRES_CONNECTION_OK eq $conn->status;

Code output:

status = 0
Died at ./testscript.pl line 105.

Other relevant information:

- If I specify an incorrect database or username, I get appropriate error
messages from postgres.
- It doesn't matter whether I specify a correct or incorrect password; I get
the same empty error.
- "psql -U postgres -W testdb" works just fine. psql actually works perfect
in every respect. I can connect, grab records, and do everything I should be
able to do.
- Postgres has been started correctly and netstat shows it listening on tcp
port 5432. I accomplished this by changing tcpip_socket = true in
postgresql.conf.
- The machine running the script is the same machine running postgres.
- pg_hba.conf is configured as follows:
local      all                                          trust
host       all         127.0.0.1     255.255.255.255    trust
host       all         192.168.1.12  255.255.255.255    trust

I added the server's remote IP in testing to see if it made a difference. It
did not.

Installation notes:

- System is a Red Hat 7.2 box.
- Postgres v7.2.3 was installed from RPMs yesterday. No prior version of
Postgres has ever been installed on this server.
- Perl version 5.6.0.
- The Postgres Perl extensions were also installed from RPMs. They installed
into /usr/lib/perl5/site_perl/5.6.1/i386_linux. They didn't work from there,
so I moved the files Pg.pm, Pg.so, and autosplit.ix to /usr/lib/perl5/5.6.0
where my cgi-bin.pl resided.

Any advice would be greatly appreciated!

Thank you!

-Ryan

Re: Request assistance connecting with Pg::connectdb

From
Medi Montaseri
Date:
While I don't have a solution for you, I'd recommend using DBI.

Wright, Ryan P wrote:

>Hello,
>
>I am having a heck of a time connecting to my postgres server, and was
>hoping some kind soul would advise me on how to proceed.
>
>The problem: Perl script dies with no error message.
>
>Code snippet:
>
>$conn = Pg::connectdb("dbname=testdb host=localhost port=5432 user=postgres
>password=test");
>print "status = ",$conn->status, "\n";
>die $conn->errorMessage unless PGRES_CONNECTION_OK eq $conn->status;
>
>Code output:
>
>status = 0
>Died at ./testscript.pl line 105.
>
>Other relevant information:
>
>- If I specify an incorrect database or username, I get appropriate error
>messages from postgres.
>- It doesn't matter whether I specify a correct or incorrect password; I get
>the same empty error.
>- "psql -U postgres -W testdb" works just fine. psql actually works perfect
>in every respect. I can connect, grab records, and do everything I should be
>able to do.
>- Postgres has been started correctly and netstat shows it listening on tcp
>port 5432. I accomplished this by changing tcpip_socket = true in
>postgresql.conf.
>- The machine running the script is the same machine running postgres.
>- pg_hba.conf is configured as follows:
>local      all                                          trust
>host       all         127.0.0.1     255.255.255.255    trust
>host       all         192.168.1.12  255.255.255.255    trust
>
>I added the server's remote IP in testing to see if it made a difference. It
>did not.
>
>Installation notes:
>
>- System is a Red Hat 7.2 box.
>- Postgres v7.2.3 was installed from RPMs yesterday. No prior version of
>Postgres has ever been installed on this server.
>- Perl version 5.6.0.
>- The Postgres Perl extensions were also installed from RPMs. They installed
>into /usr/lib/perl5/site_perl/5.6.1/i386_linux. They didn't work from there,
>so I moved the files Pg.pm, Pg.so, and autosplit.ix to /usr/lib/perl5/5.6.0
>where my cgi-bin.pl resided.
>
>Any advice would be greatly appreciated!
>
>Thank you!
>
>-Ryan
>
>---------------------------(end of broadcast)---------------------------
>TIP 4: Don't 'kill -9' the postmaster
>
>




Re: Request assistance connecting with Pg::connectdb

From
"Nigel J. Andrews"
Date:
On Thu, 21 Nov 2002, Medi Montaseri wrote:

> While I don't have a solution for you, I'd recommend using DBI.
>
> Wright, Ryan P wrote:
>
> >Hello,
> >
> >I am having a heck of a time connecting to my postgres server, and was
> >hoping some kind soul would advise me on how to proceed.
> >
> >The problem: Perl script dies with no error message.
> >
> >Code snippet:
> >
> >$conn = Pg::connectdb("dbname=testdb host=localhost port=5432 user=postgres
> >password=test");
> >print "status = ",$conn->status, "\n";
> >die $conn->errorMessage unless PGRES_CONNECTION_OK eq $conn->status;

i think you want that test to read:

$conn->status == PGRES_CONNECTION_OK

You're getting the string equality test mixed up with another languages numeric
one. Or do I mean that the other way around


--
Nigel Andrews



Re: Request assistance connecting with Pg::connectdb

From
"Wright, Ryan P"
Date:
OK - I'm more than willing to give that a try! Where can I find some
FAQs/HOWTOs etc? I found DBI (v1.30) & installed it. But I'm having trouble
finding info on how to configure and use it. Can you point me to a web site
with that information?

Thank you,

-Ryan


> -----Original Message-----
> From: Medi Montaseri [mailto:medi.montaseri@intransa.com]
> Sent: Thursday, November 21, 2002 1:40 PM
> To: Wright, Ryan P
> Cc: 'pgsql-general@postgresql.org'
> Subject: Re: [GENERAL] Request assistance connecting with
> Pg::connectdb
>
>
> While I don't have a solution for you, I'd recommend using DBI.
>
> Wright, Ryan P wrote:
>
> >Hello,
> >
> >I am having a heck of a time connecting to my postgres
> server, and was
> >hoping some kind soul would advise me on how to proceed.
> >
> >The problem: Perl script dies with no error message.
> >
> >Code snippet:
> >
> >$conn = Pg::connectdb("dbname=testdb host=localhost port=5432
> >user=postgres password=test"); print "status = ",$conn->status, "\n";
> >die $conn->errorMessage unless PGRES_CONNECTION_OK eq $conn->status;
> >
> >Code output:
> >
> >status = 0
> >Died at ./testscript.pl line 105.
> >
> >Other relevant information:
> >
> >- If I specify an incorrect database or username, I get appropriate
> >error messages from postgres.
> >- It doesn't matter whether I specify a correct or incorrect
> password;
> >I get the same empty error.
> >- "psql -U postgres -W testdb" works just fine. psql actually works
> >perfect in every respect. I can connect, grab records, and do
> >everything I should be able to do.
> >- Postgres has been started correctly and netstat shows it
> listening on
> >tcp port 5432. I accomplished this by changing tcpip_socket
> = true in
> >postgresql.conf.
> >- The machine running the script is the same machine running
> postgres.
> >- pg_hba.conf is configured as follows:
> >local      all                                          trust
> >host       all         127.0.0.1     255.255.255.255    trust
> >host       all         192.168.1.12  255.255.255.255    trust
> >
> >I added the server's remote IP in testing to see if it made a
> >difference. It did not.
> >
> >Installation notes:
> >
> >- System is a Red Hat 7.2 box.
> >- Postgres v7.2.3 was installed from RPMs yesterday. No
> prior version
> >of Postgres has ever been installed on this server.
> >- Perl version 5.6.0.
> >- The Postgres Perl extensions were also installed from RPMs. They
> >installed into /usr/lib/perl5/site_perl/5.6.1/i386_linux.
> They didn't
> >work from there, so I moved the files Pg.pm, Pg.so, and
> autosplit.ix to
> >/usr/lib/perl5/5.6.0 where my cgi-bin.pl resided.
> >
> >Any advice would be greatly appreciated!
> >
> >Thank you!
> >
> >-Ryan
> >
> >---------------------------(end of
> >broadcast)---------------------------
> >TIP 4: Don't 'kill -9' the postmaster
> >
> >
>
>
>

Re: Request assistance connecting with Pg::connectdb

From
"Wright, Ryan P"
Date:
Ah, nevermind! I found all of the info I need, & after some fudging around,
it's working great now with DBD::Pg.

Thank you!

-Ryan



> -----Original Message-----
> From: Wright, Ryan P
> Sent: Thursday, November 21, 2002 2:26 PM
> To: 'Medi Montaseri'
> Cc: 'pgsql-general@postgresql.org'
> Subject: Re: [GENERAL] Request assistance connecting with
> Pg::connectdb
>
>
> OK - I'm more than willing to give that a try! Where can I
> find some FAQs/HOWTOs etc? I found DBI (v1.30) & installed
> it. But I'm having trouble finding info on how to configure
> and use it. Can you point me to a web site with that information?
>
> Thank you,
>
> -Ryan
>
>
> > -----Original Message-----
> > From: Medi Montaseri [mailto:medi.montaseri@intransa.com]
> > Sent: Thursday, November 21, 2002 1:40 PM
> > To: Wright, Ryan P
> > Cc: 'pgsql-general@postgresql.org'
> > Subject: Re: [GENERAL] Request assistance connecting with
> > Pg::connectdb
> >
> >
> > While I don't have a solution for you, I'd recommend using DBI.
> >
> > Wright, Ryan P wrote:
> >
> > >Hello,
> > >
> > >I am having a heck of a time connecting to my postgres
> > server, and was
> > >hoping some kind soul would advise me on how to proceed.
> > >
> > >The problem: Perl script dies with no error message.
> > >
> > >Code snippet:
> > >
> > >$conn = Pg::connectdb("dbname=testdb host=localhost port=5432
> > >user=postgres password=test"); print "status =
> ",$conn->status, "\n";
> > >die $conn->errorMessage unless PGRES_CONNECTION_OK eq
> $conn->status;
> > >
> > >Code output:
> > >
> > >status = 0
> > >Died at ./testscript.pl line 105.
> > >
> > >Other relevant information:
> > >
> > >- If I specify an incorrect database or username, I get appropriate
> > >error messages from postgres.
> > >- It doesn't matter whether I specify a correct or incorrect
> > password;
> > >I get the same empty error.
> > >- "psql -U postgres -W testdb" works just fine. psql actually works
> > >perfect in every respect. I can connect, grab records, and do
> > >everything I should be able to do.
> > >- Postgres has been started correctly and netstat shows it
> > listening on
> > >tcp port 5432. I accomplished this by changing tcpip_socket
> > = true in
> > >postgresql.conf.
> > >- The machine running the script is the same machine running
> > postgres.
> > >- pg_hba.conf is configured as follows:
> > >local      all                                          trust
> > >host       all         127.0.0.1     255.255.255.255    trust
> > >host       all         192.168.1.12  255.255.255.255    trust
> > >
> > >I added the server's remote IP in testing to see if it made a
> > >difference. It did not.
> > >
> > >Installation notes:
> > >
> > >- System is a Red Hat 7.2 box.
> > >- Postgres v7.2.3 was installed from RPMs yesterday. No
> > prior version
> > >of Postgres has ever been installed on this server.
> > >- Perl version 5.6.0.
> > >- The Postgres Perl extensions were also installed from RPMs. They
> > >installed into /usr/lib/perl5/site_perl/5.6.1/i386_linux.
> > They didn't
> > >work from there, so I moved the files Pg.pm, Pg.so, and
> > autosplit.ix to
> > >/usr/lib/perl5/5.6.0 where my cgi-bin.pl resided.
> > >
> > >Any advice would be greatly appreciated!
> > >
> > >Thank you!
> > >
> > >-Ryan
> > >
> > >---------------------------(end of
> > >broadcast)---------------------------
> > >TIP 4: Don't 'kill -9' the postmaster
> > >
> > >
> >
> >
> >
>
> ---------------------------(end of
> broadcast)---------------------------
> TIP 2: you can get off all lists at once with the unregister command
>     (send "unregister YourEmailAddressHere" to
> majordomo@postgresql.org)
>

Re: Request assistance connecting with Pg::connectdb

From
Medi Montaseri
Date:
Actually in Perl the equality operator 'eq' means that the operands
engade in this
operation are of type string.

Since C programmer use symbolic constants for improved readability, then
your suggestiion....


Nigel J. Andrews wrote:

>On Thu, 21 Nov 2002, Medi Montaseri wrote:
>
>
>
>>While I don't have a solution for you, I'd recommend using DBI.
>>
>>Wright, Ryan P wrote:
>>
>>
>>
>>>Hello,
>>>
>>>I am having a heck of a time connecting to my postgres server, and was
>>>hoping some kind soul would advise me on how to proceed.
>>>
>>>The problem: Perl script dies with no error message.
>>>
>>>Code snippet:
>>>
>>>$conn = Pg::connectdb("dbname=testdb host=localhost port=5432 user=postgres
>>>password=test");
>>>print "status = ",$conn->status, "\n";
>>>die $conn->errorMessage unless PGRES_CONNECTION_OK eq $conn->status;
>>>
>>>
>
>i think you want that test to read:
>
>$conn->status == PGRES_CONNECTION_OK
>
>You're getting the string equality test mixed up with another languages numeric
>one. Or do I mean that the other way around
>
>
>--
>Nigel Andrews
>
>
>
>---------------------------(end of broadcast)---------------------------
>TIP 3: if posting/reading through Usenet, please send an appropriate
>subscribe-nomail command to majordomo@postgresql.org so that your
>message can get through to the mailing list cleanly
>
>




Re: Request assistance connecting with Pg::connectdb

From
Medi Montaseri
Date:
One good resouce is

perldoc DBI
and in your case also


from your unix command line...else check out www.perldoc.com or nearest
search engine.

Here is a primer....

use DBI;
my $DSN = 'dbname=SomeDB;' ;
$DSN .= 'host=some.host.acme.com;' ;

my $dbh = DBI->connect ( "dbi:Pg:$DSN", "username", "password") || do
{
    die (" $DBI::errstr \n");
};

my $sth = $dbh->prepare( "select c1 from t1");
$sth->execute();

while ( @list = $sth->fetchrow_array() )
{
    print "@list \n";
}
$dbh->disconnect();

The good news is, whence you learn this API, you can switch your backend
engine
to Oracle, PG, or whatever and you code does not have to change.

Wright, Ryan P wrote:

>OK - I'm more than willing to give that a try! Where can I find some
>FAQs/HOWTOs etc? I found DBI (v1.30) & installed it. But I'm having trouble
>finding info on how to configure and use it. Can you point me to a web site
>with that information?
>
>Thank you,
>
>-Ryan
>
>
>
>
>>-----Original Message-----
>>From: Medi Montaseri [mailto:medi.montaseri@intransa.com]
>>Sent: Thursday, November 21, 2002 1:40 PM
>>To: Wright, Ryan P
>>Cc: 'pgsql-general@postgresql.org'
>>Subject: Re: [GENERAL] Request assistance connecting with
>>Pg::connectdb
>>
>>
>>While I don't have a solution for you, I'd recommend using DBI.
>>
>>Wright, Ryan P wrote:
>>
>>
>>
>>>Hello,
>>>
>>>I am having a heck of a time connecting to my postgres
>>>
>>>
>>server, and was
>>
>>
>>>hoping some kind soul would advise me on how to proceed.
>>>
>>>The problem: Perl script dies with no error message.
>>>
>>>Code snippet:
>>>
>>>$conn = Pg::connectdb("dbname=testdb host=localhost port=5432
>>>user=postgres password=test"); print "status = ",$conn->status, "\n";
>>>die $conn->errorMessage unless PGRES_CONNECTION_OK eq $conn->status;
>>>
>>>Code output:
>>>
>>>status = 0
>>>Died at ./testscript.pl line 105.
>>>
>>>Other relevant information:
>>>
>>>- If I specify an incorrect database or username, I get appropriate
>>>error messages from postgres.
>>>- It doesn't matter whether I specify a correct or incorrect
>>>
>>>
>>password;
>>
>>
>>>I get the same empty error.
>>>- "psql -U postgres -W testdb" works just fine. psql actually works
>>>perfect in every respect. I can connect, grab records, and do
>>>everything I should be able to do.
>>>- Postgres has been started correctly and netstat shows it
>>>
>>>
>>listening on
>>
>>
>>>tcp port 5432. I accomplished this by changing tcpip_socket
>>>
>>>
>>= true in
>>
>>
>>>postgresql.conf.
>>>- The machine running the script is the same machine running
>>>
>>>
>>postgres.
>>
>>
>>>- pg_hba.conf is configured as follows:
>>>local      all                                          trust
>>>host       all         127.0.0.1     255.255.255.255    trust
>>>host       all         192.168.1.12  255.255.255.255    trust
>>>
>>>I added the server's remote IP in testing to see if it made a
>>>difference. It did not.
>>>
>>>Installation notes:
>>>
>>>- System is a Red Hat 7.2 box.
>>>- Postgres v7.2.3 was installed from RPMs yesterday. No
>>>
>>>
>>prior version
>>
>>
>>>of Postgres has ever been installed on this server.
>>>- Perl version 5.6.0.
>>>- The Postgres Perl extensions were also installed from RPMs. They
>>>installed into /usr/lib/perl5/site_perl/5.6.1/i386_linux.
>>>
>>>
>>They didn't
>>
>>
>>>work from there, so I moved the files Pg.pm, Pg.so, and
>>>
>>>
>>autosplit.ix to
>>
>>
>>>/usr/lib/perl5/5.6.0 where my cgi-bin.pl resided.
>>>
>>>Any advice would be greatly appreciated!
>>>
>>>Thank you!
>>>
>>>-Ryan
>>>
>>>---------------------------(end of
>>>broadcast)---------------------------
>>>TIP 4: Don't 'kill -9' the postmaster
>>>
>>>
>>>
>>>
>>
>>
>>