Thread: Request assistance connecting with Pg::connectdb

Request assistance connecting with Pg::connectdb

From
public@ryanwright.com (Ryan Wright)
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!

Re: Request assistance connecting with Pg::connectdb

From
Steve Crawford
Date:
Just curious, have you tried:

1. using only the dbname, user and password (ie. not host or port)?

2. tried starting postmaster with the -i flag?

3. specifying localhost and port 5432 when you finre up psql?

I don't have enough knowledge of the Perl modules to speak with authority but
I have this gut-level feeling that by adding the host and port to the
connectdb command that you are causing your program to attempt to use a
network socket instead of a local unix socket to connect. You need -i to
connect via the network.

Cheers,
Steve


On Wednesday 20 November 2002 1:55 pm, Ryan Wright 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!
>
> ---------------------------(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
wsheldah@lexmark.com
Date:
Just a few suggestions:

You *might* get more information if you add an 'or die $!' to the end of
the line that starts '$conn = Pg::connectdb'. If that connection fails,
$conn won't even get instantiated, so there won't be anything in
$conn->status or $conn->errorMessage.

I would suggest using DBI and DBD::Pg, rather than the Pg driver. At least
that's what I've used successfully.

This probably isn't related to your current problem, but I would also
strongly recommend upgrading to at least perl 5.6.1, if not the current
stable 5.8.0. Version 5.6.1 contains several bugfixes and improvements to
5.6.0.

Good luck,

Wes Sheldahl




public@ryanwright.com (Ryan Wright)@postgresql.org on 11/20/2002 04:55:16
PM

Sent by:    pgsql-general-owner@postgresql.org


To:    pgsql-general@postgresql.org
cc:
Subject:    [GENERAL] Request assistance connecting with Pg::connectdb


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!

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
    (send "unregister YourEmailAddressHere" to majordomo@postgresql.org)