pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
prob with PERL/Postgres
8+ messages / 7 participants
[nested] [flat]

* prob with PERL/Postgres
@ 2001-08-06 19:05  Kristopher Yates <kris@grinz.com>
  0 siblings, 3 replies; 8+ messages in thread

From: Kristopher Yates @ 2001-08-06 19:05 UTC (permalink / raw)
  To: pgsql-sql

PERL SNIPPET:

# build arrays from file (OMITTED)

use Pg;
$dbhost='127.0.0.1';
$dbname='mpact';
#$connstr="dbname=$dbname";
$connstr="host=$dbhost dbname=$dbname";
$conn = Pg::connectdb($connstr);

#more code related to date omitted

    $result=$conn->exec($sql);
    (PGRES_COMMAND_OK eq $result->resultStatus)
    or  die $conn->errorMessage;

WHY DO I GET PQsendQuery() -- There is no connection to the 
backend.  I have tried leaving host blank, using IP 127.0.0.1 and 
hostname localhost.  This script should work - the problem is 
something with postgres but I dont know what.  Any ideas out 
there?  Thanks,  Kris



^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* Re: prob with PERL/Postgres
@ 2001-08-06 19:59  Kate Collins <kcollins@wsi.com>
  parent: Kristopher Yates <kris@grinz.com>
  2 siblings, 0 replies; 8+ messages in thread

From: Kate Collins @ 2001-08-06 19:59 UTC (permalink / raw)
  To: kris@grinz.com; +Cc: pgsql-sql

I use the Perl DBI module to connect to a postgres data base on the local
system.  I don't specify the host name.  This is the syntax I use to connect to
the data base:

use DBI;

$dbname = "foo";
$connstr = "dbi:Pg:dbname=$dbname";
$dbh = DBI->connect($connstr);

Kristopher Yates wrote:

> PERL SNIPPET:
>
> # build arrays from file (OMITTED)
>
> use Pg;
> $dbhost='127.0.0.1';
> $dbname='mpact';
> #$connstr="dbname=$dbname";
> $connstr="host=$dbhost dbname=$dbname";
> $conn = Pg::connectdb($connstr);
>
> #more code related to date omitted
>
>     $result=$conn->exec($sql);
>     (PGRES_COMMAND_OK eq $result->resultStatus)
>     or  die $conn->errorMessage;
>
> WHY DO I GET PQsendQuery() -- There is no connection to the
> backend.  I have tried leaving host blank, using IP 127.0.0.1 and
> hostname localhost.  This script should work - the problem is
> something with postgres but I dont know what.  Any ideas out
> there?  Thanks,  Kris
>
> ---------------------------(end of broadcast)---------------------------
> TIP 5: Have you checked our extensive FAQ?
>
> http://www.postgresql.org/users-lounge/docs/faq.html

--
=================================================
Katherine (Kate) L. Collins
Senior Software Engineer/Meteorologist
Weather Services International (WSI Corporation)
900 Technology Park Drive
Billerica, MA 01821
EMAIL: kcollins@wsi.com
PHONE: (978) 262-0610
FAX: (978) 262-0700
http://www.intellicast.com





^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* Re: prob with PERL/Postgres
@ 2001-08-06 20:02  Kate Collins <klcollins@wsicorp.com>
  0 siblings, 1 reply; 8+ messages in thread

From: Kate Collins @ 2001-08-06 20:02 UTC (permalink / raw)
  To: kris@grinz.com; +Cc: pgsql-sql

I use the Perl DBI module to connect to a postgres data base on the local
system.  I don't specify the host name.  This is the syntax I use to connect to
the data base:

use DBI;

$dbname = "foo";
$connstr = "dbi:Pg:dbname=$dbname";
$dbh = DBI->connect($connstr);

Kristopher Yates wrote:

> PERL SNIPPET:
>
> # build arrays from file (OMITTED)
>
> use Pg;
> $dbhost='127.0.0.1';
> $dbname='mpact';
> #$connstr="dbname=$dbname";
> $connstr="host=$dbhost dbname=$dbname";
> $conn = Pg::connectdb($connstr);
>
> #more code related to date omitted
>
>     $result=$conn->exec($sql);
>     (PGRES_COMMAND_OK eq $result->resultStatus)
>     or  die $conn->errorMessage;
>
> WHY DO I GET PQsendQuery() -- There is no connection to the
> backend.  I have tried leaving host blank, using IP 127.0.0.1 and
> hostname localhost.  This script should work - the problem is
> something with postgres but I dont know what.  Any ideas out
> there?  Thanks,  Kris
>
> ---------------------------(end of broadcast)---------------------------
> TIP 5: Have you checked our extensive FAQ?
>
> http://www.postgresql.org/users-lounge/docs/faq.html


--
=================================================
Katherine (Kate) L. Collins
Senior Software Engineer/Meteorologist
Weather Services International (WSI Corporation)
900 Technology Park Drive
Billerica, MA 01821
EMAIL: kcollins@wsi.com
PHONE: (978) 262-0610
FAX: (978) 262-0700
http://www.intellicast.com





^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* Re: prob with PERL/Postgres
@ 2001-08-06 20:37  clayton <drfrog@smartt.com>
  parent: Kristopher Yates <kris@grinz.com>
  2 siblings, 0 replies; 8+ messages in thread

From: clayton @ 2001-08-06 20:37 UTC (permalink / raw)
  To: kris@grinz.com; +Cc: pgsql-sql

Kristopher Yates wrote:

>PERL SNIPPET:
>
># build arrays from file (OMITTED)
>
>use Pg;
>$dbhost='127.0.0.1';
>$dbname='mpact';
>#$connstr="dbname=$dbname";
>$connstr="host=$dbhost dbname=$dbname";
>$conn = Pg::connectdb($connstr);
>
>#more code related to date omitted
>
>    $result=$conn->exec($sql);
>    (PGRES_COMMAND_OK eq $result->resultStatus)
>    or  die $conn->errorMessage;
>
>WHY DO I GET PQsendQuery() -- There is no connection to the 
>backend.  I have tried leaving host blank, using IP 127.0.0.1 and 
>hostname localhost.  This script should work - the problem is 
>something with postgres but I dont know what.  Any ideas out 
>there?  Thanks,  Kris
>
>---------------------------(end of broadcast)---------------------------
>TIP 5: Have you checked our extensive FAQ?
>
>http://www.postgresql.org/users-lounge/docs/faq.html
>
>

have you checked your /etc/host file?
as well is your loopback on ?

what about your pg_hba.conf
it should probably have ,by default:
---pg_hba.conf----
# By default, allow anything over UNIX domain sockets and localhost.
local        all                                           trust
host         all         127.0.0.1     255.255.255.255     trust
---pg_hba.conf----
you can use stonger security consult the Pg docs on that!
its been a while since ive looked at them


here is how i connect::

#!/usr/bin/perl
use strict;
use warnings;
use Pg;
my $command="select * from write;";
my $conninfo = "dbname=write  user=www password=Apache1312 host=localhost";
my $conn = Pg::connectdb($conninfo);
if (Pg::PGRES_CONNECTION_OK == $conn->status){
my  $result = $conn->exec($command);
if (Pg::PGRES_TUPLES_OK == $result->resultStatus) {
            while (my @row = $result->fetchrow) {
print join (" ",@row);
        }
    }
}




^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* Re: prob with PERL/Postgres
@ 2001-08-06 20:54  Allan Engelhardt <allane@cybaea.com>
  parent: Kristopher Yates <kris@grinz.com>
  2 siblings, 0 replies; 8+ messages in thread

From: Allan Engelhardt @ 2001-08-06 20:54 UTC (permalink / raw)
  To: Kristopher Yates <kris@grinz.com>

1.   I'm assuming that psql works fine?  psql -h 127.0.0.1 mpact?
1b. Have you checked the port??  You ARE running postmaster with the '-i' option, aren't you?

The recommended solutions are typically to use the DBI and DBD modules.  Try man DBD::Pg.

Alternatively: have you tried the setdbLogin method instead:


           $conn = Pg::setdbLogin($pghost, $pgport, $pgoptions, $pgtty, $dbname, $login, $pwd)

       Opens a new connection to the backend. The connection
       identifier $conn ( a pointer to the PGconn structure )
       must be used in subsequent commands for unique identifica-
       tion. Before using $conn you should call $conn->status to
       ensure, that the connection was properly made.  Closing a
       connection is done by deleting the connection handle, eg
       'undef $conn;'.


Hope this helps a little......


Allan


Kristopher Yates wrote:

> PERL SNIPPET:
>
> # build arrays from file (OMITTED)
>
> use Pg;
> $dbhost='127.0.0.1';
> $dbname='mpact';
> #$connstr="dbname=$dbname";
> $connstr="host=$dbhost dbname=$dbname";
> $conn = Pg::connectdb($connstr);
>
> #more code related to date omitted
>
>     $result=$conn->exec($sql);
>     (PGRES_COMMAND_OK eq $result->resultStatus)
>     or  die $conn->errorMessage;
>
> WHY DO I GET PQsendQuery() -- There is no connection to the
> backend.  I have tried leaving host blank, using IP 127.0.0.1 and
> hostname localhost.  This script should work - the problem is
> something with postgres but I dont know what.  Any ideas out
> there?  Thanks,  Kris
>
> ---------------------------(end of broadcast)---------------------------
> TIP 5: Have you checked our extensive FAQ?
>
> http://www.postgresql.org/users-lounge/docs/faq.html




^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* Re: prob with PERL/Postgres
@ 2001-08-06 21:14  Thomas Good <tomg@admin.nrnet.org>
  parent: Kate Collins <klcollins@wsicorp.com>
  0 siblings, 1 reply; 8+ messages in thread

From: Thomas Good @ 2001-08-06 21:14 UTC (permalink / raw)
  To: Kate Collins <klcollins@wsicorp.com>; +Cc: kris@grinz.com; pgsql-sql

On Mon, 6 Aug 2001, Kate Collins wrote:

> I use the Perl DBI module to connect to a postgres data base on the local
> system.  I don't specify the host name.  This is the syntax I use to connect to
> the data base:
> 
> use DBI;
> 
> $dbname = "foo";
> $connstr = "dbi:Pg:dbname=$dbname";
> $dbh = DBI->connect($connstr);

Kate, he uses a diff module by the same author (Edmund Mergl) but with
a very diff syntax.  The advantage of the DBI  -  Kris, if you're interested -
is that the syntax is much like ESQL/C and the code is much more portable.
For example I use DBI to access both pg and oracle.

Cheers,
Tom

> Kristopher Yates wrote:
> 
> > PERL SNIPPET:
> >
> > # build arrays from file (OMITTED)
> >
> > use Pg;
> > $dbhost='127.0.0.1';
> > $dbname='mpact';
> > #$connstr="dbname=$dbname";
> > $connstr="host=$dbhost dbname=$dbname";
> > $conn = Pg::connectdb($connstr);
> >
> > #more code related to date omitted
> >
> >     $result=$conn->exec($sql);
> >     (PGRES_COMMAND_OK eq $result->resultStatus)
> >     or  die $conn->errorMessage;
> >
> > WHY DO I GET PQsendQuery() -- There is no connection to the
> > backend.  I have tried leaving host blank, using IP 127.0.0.1 and
> > hostname localhost.  This script should work - the problem is
> > something with postgres but I dont know what.  Any ideas out
> > there?  Thanks,  Kris
> >
> > ---------------------------(end of broadcast)---------------------------
> > TIP 5: Have you checked our extensive FAQ?
> >
> > http://www.postgresql.org/users-lounge/docs/faq.html
> 
> 
> --
> =================================================
> Katherine (Kate) L. Collins
> Senior Software Engineer/Meteorologist
> Weather Services International (WSI Corporation)
> 900 Technology Park Drive
> Billerica, MA 01821
> EMAIL: kcollins@wsi.com
> PHONE: (978) 262-0610
> FAX: (978) 262-0700
> http://www.intellicast.com
> 
> 
> 
> ---------------------------(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
> 


--------------------------------------------------------------------
               SVCMC - Center for Behavioral Health                  
--------------------------------------------------------------------
Thomas Good                          tomg@ { admin | q8 } .nrnet.org
Programmer/Analyst                              Phone:  718-354-5528 
Residential Services                            Mobile: 917-282-7359  
--------------------------------------------------------------------
/*           Die Wahrheit Ist Irgendwo Da Draussen...             */
--------------------------------------------------------------------




^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* Re: prob with PERL/Postgres
@ 2001-08-06 21:39  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Thomas Good <tomg@admin.nrnet.org>
  0 siblings, 1 reply; 8+ messages in thread

From: Tom Lane @ 2001-08-06 21:39 UTC (permalink / raw)
  To: Thomas Good <tomg@admin.nrnet.org>; +Cc: Kate Collins <klcollins@wsicorp.com>; kris@grinz.com; pgsql-sql

Thomas Good <tomg@admin.nrnet.org> writes:
> Kate, he uses a diff module by the same author (Edmund Mergl) but with
> a very diff syntax.  The advantage of the DBI - Kris, if you're
> interested - is that the syntax is much like ESQL/C and the code is
> much more portable.  For example I use DBI to access both pg and
> oracle.

DBI is a good alternative, but is unlikely to act much differently as
far as connection problems go.

> use Pg;
> $dbhost='127.0.0.1';
> $dbname='mpact';
> #$connstr="dbname=$dbname";
> $connstr="host=$dbhost dbname=$dbname";
> $conn = Pg::connectdb($connstr);
> 
> #more code related to date omitted
> 
> $result=$conn->exec($sql);
> (PGRES_COMMAND_OK eq $result->resultStatus)
> or  die $conn->errorMessage;
> 
> WHY DO I GET PQsendQuery() -- There is no connection to the
> backend.

It's hard to tell with only that much information.  I think the real
mistake in this code is not checking for failure of the connectdb()
call.  Had you checked at that point, you would have gotten a more
useful error message.  The examples in the Pg documentation recommend

	$conn = Pg::connectdb(whatever);
	die $conn->errorMessage unless PGRES_CONNECTION_OK eq $conn->status;

Try that, and if you're still in the dark, let us see the error
message...

			regards, tom lane



^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* Re: prob with PERL/Postgres
@ 2001-08-07 11:42  Thomas Good <tomg@admin.nrnet.org>
  parent: Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 8+ messages in thread

From: Thomas Good @ 2001-08-07 11:42 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Kate Collins <klcollins@wsicorp.com>; kris@grinz.com; pgsql-sql

On Mon, 6 Aug 2001, Tom Lane wrote:

> Thomas Good <tomg@admin.nrnet.org> writes:
> > Kate, he uses a diff module by the same author (Edmund Mergl) but with
> > a very diff syntax.  The advantage of the DBI - Kris, if you're
> > interested - is that the syntax is much like ESQL/C and the code is
> > much more portable.  For example I use DBI to access both pg and
> > oracle.
> 
> DBI is a good alternative, but is unlikely to act much differently as
> far as connection problems go.

You know Thomas, after I build Pg (including 7.1.2) and fire up initdb
there comes a message about starting the db with -D and the location of
the datafiles.  Nothing about using -i...it might be good to include,
no?


Cheers,
Tom 

--------------------------------------------------------------------
               SVCMC - Center for Behavioral Health                  
--------------------------------------------------------------------
Thomas Good                          tomg@ { admin | q8 } .nrnet.org
Programmer/Analyst                              Phone:  718-354-5528 
Residential Services                            Mobile: 917-282-7359  
--------------------------------------------------------------------
/*           Die Wahrheit Ist Irgendwo Da Draussen...             */
--------------------------------------------------------------------




^ permalink  raw  reply  [nested|flat] 8+ messages in thread


end of thread, other threads:[~2001-08-07 11:42 UTC | newest]

Thread overview: 8+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2001-08-06 19:05 prob with PERL/Postgres Kristopher Yates <kris@grinz.com>
2001-08-06 19:59 ` Kate Collins <kcollins@wsi.com>
2001-08-06 20:37 ` clayton <drfrog@smartt.com>
2001-08-06 20:54 ` Allan Engelhardt <allane@cybaea.com>
2001-08-06 20:02 Re: prob with PERL/Postgres Kate Collins <klcollins@wsicorp.com>
2001-08-06 21:14 ` Thomas Good <tomg@admin.nrnet.org>
2001-08-06 21:39   ` Tom Lane <tgl@sss.pgh.pa.us>
2001-08-07 11:42     ` Thomas Good <tomg@admin.nrnet.org>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox