Thread: wierd problems with DBI/DBD::pg?

wierd problems with DBI/DBD::pg?

From
Michelle Murrain
Date:
I recently upgraded from 6.5 to 7.1, and it mostly went smoothly (fixed the
PHP problem, thanks to a list member). But now some of my perl stuff is being
a bit strange, and I'm wondering whether other folks have noticed strangeness
when they upgraded their Postgres as well as upgraded to the new DBD::Pg.

First off, my error strings seem to be cut off - so when an error happens, I
only get the first few (not at all predictable, either) characters from the
error string.

Second, I have this strange situation where a script that does a query on one
table of a database gives a reasonable result, but returns an internal server
error when a different table is queried. (this worked prior to the upgrade) -
plus, the wierd thing is that this script has a graceful exit subroutine, and
shouldn't just barf like that.

And of course, part of what is going on is that it's really hard to debug,
since DBI is not returning the full error string, so it's hard to know what's
going on.

Thanks in advance.

Michelle
--
------------
Michelle Murrain, Ph.D.
President
Norwottuck Technology Resources
mpm@norwottuck.com
http://www.norwottuck.com

Re: wierd problems with DBI/DBD::pg?

From
Gilles DAROLD
Date:
Hi,

I widly use DBI/DBD::Pg and doesn't notice any problem. Perhaps because
there's no error or they are well handled :-)). I'm interested to know more
about this problem because I have many script to review in that case.

Could you please send more explanation of the problem and some source code
related to them. Do you use mod_perl ? I presume you're  'Internal error' is
from Apache log... What version of DBI and DBD are you using ?

Regards,

Gilles

I'm not here tomorow but can take a look on wenesday...

Michelle Murrain wrote:

> I recently upgraded from 6.5 to 7.1, and it mostly went smoothly (fixed the
> PHP problem, thanks to a list member). But now some of my perl stuff is being
> a bit strange, and I'm wondering whether other folks have noticed strangeness
> when they upgraded their Postgres as well as upgraded to the new DBD::Pg.
>
> First off, my error strings seem to be cut off - so when an error happens, I
> only get the first few (not at all predictable, either) characters from the
> error string.
>
> Second, I have this strange situation where a script that does a query on one
> table of a database gives a reasonable result, but returns an internal server
> error when a different table is queried. (this worked prior to the upgrade) -
> plus, the wierd thing is that this script has a graceful exit subroutine, and
> shouldn't just barf like that.
>
> And of course, part of what is going on is that it's really hard to debug,
> since DBI is not returning the full error string, so it's hard to know what's
> going on.
>
> Thanks in advance.
>
> Michelle
> --
> ------------
> Michelle Murrain, Ph.D.
> President
> Norwottuck Technology Resources
> mpm@norwottuck.com
> http://www.norwottuck.com
>
> ---------------------------(end of broadcast)---------------------------
> TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org


Re: wierd problems with DBI/DBD::pg?

From
Tom Lane
Date:
Michelle Murrain <mpm@norwottuck.com> writes:
> And of course, part of what is going on is that it's really hard to
> debug, since DBI is not returning the full error string, so it's hard
> to know what's going on.

You could look in the postmaster's log (you are keeping one I trust ;-))
to find the full error string reported by the backend.

No idea what's causing DBD::Pg to misbehave like that, though.  Perhaps
its latest release is a tad broken?  Which DBI/DBD versions are you
using, exactly?

            regards, tom lane

Re: wierd problems with DBI/DBD::pg?

From
Michelle Murrain
Date:
On Tuesday 01 May 2001 07:18 am, pmh@edison.ioppublishing.com wrote:
> On Mon, 30 Apr 2001 14:50:15 -0400, Michelle Murrain wrote:
> > I recently upgraded from 6.5 to 7.1, and it mostly went smoothly (fixed
> > the PHP problem, thanks to a list member). But now some of my perl stuff
> > is being  a bit strange, and I'm wondering whether other folks have
> > noticed strangeness  when they upgraded their Postgres as well as
> > upgraded to the new DBD::Pg.
>
> Here's a patch to DBD::Pg 0.98, which should fix the problems.

Thank you, thank you, thank you! Worked like a charm!!!

Michelle
------------
Michelle Murrain, Ph.D.
President
Norwottuck Technology Resources
mpm@norwottuck.com
http://www.norwottuck.com

Re: wierd problems with DBI/DBD::pg?

From
pmh@edison.ioppublishing.com
Date:
On Mon, 30 Apr 2001 14:50:15 -0400, Michelle Murrain wrote:
> I recently upgraded from 6.5 to 7.1, and it mostly went smoothly (fixed the
> PHP problem, thanks to a list member). But now some of my perl stuff is
> being  a bit strange, and I'm wondering whether other folks have noticed
> strangeness  when they upgraded their Postgres as well as upgraded to the
> new DBD::Pg.

Here's a patch to DBD::Pg 0.98, which should fix the problems.

--- dbdimp.c.orig       Tue May  1 11:46:47 2001
+++ dbdimp.c    Tue May  1 11:55:26 2001
@@ -72,18 +72,21 @@
     char *error_msg;
 {
     D_imp_xxh(h);
-    char *err, *src, *dst;
+    char *err, *src, *dst, *end;
     int  len  = strlen(error_msg);

-    err = (char *)malloc(strlen(error_msg + 1));
+    err = (char *)malloc(len + 1);
     if (!err) {
       return;
     }
+    /* Remove trailing newlines, allowing for multi-line messages */
+    for(end = error_msg + len; end > error_msg && end[-1] == '\n'; --end);
+
     src = error_msg;
     dst = err;

     /* copy error message without trailing newlines */
-    while (*dst != '\0' && *dst != '\n') {
+    while (src < end){
         *dst++ = *src++;
     }
     *dst = '\0';


--
    Peter Haworth    pmh@edison.ioppublishing.com
"It's gotten to the point where the only place you can get work done is at
home, because no one bugs you, and the best place to entertain yourself is
at work, because the Internet connections are faster."      -- Scott Adams

Re: wierd problems with DBI/DBD::pg?

From
pmh@edison.ioppublishing.com
Date:
On Mon, 30 Apr 2001 14:50:15 -0400, Michelle Murrain wrote:
> I recently upgraded from 6.5 to 7.1, and it mostly went smoothly (fixed the
> PHP problem, thanks to a list member). But now some of my perl stuff is
> being  a bit strange, and I'm wondering whether other folks have noticed
> strangeness  when they upgraded their Postgres as well as upgraded to the
> new DBD::Pg.
>
> First off, my error strings seem to be cut off - so when an error happens, I
> only get the first few (not at all predictable, either) characters from the
> error string.

Which version of DBD::Pg is it? Versions 0.96 and onwards remove the newlines
from the ends of errors, so that the file and line number which caused them
is appended. My patch (in 0.96 and 0.97) did this by working from the end of
the string, but the patch in 0.98 works from the beginning, and truncates the
error at the first newline. This prevents the core dumps which my patch
caused, but it will truncate multiline errors. If that's what's happening,
I'll submit another patch which starts from the end, but doesn't coredump.

> Second, I have this strange situation where a script that does a query on
> one table of a database gives a reasonable result, but returns an internal
> server  error when a different table is queried. (this worked prior to the
> upgrade) -  plus, the wierd thing is that this script has a graceful exit
> subroutine, and shouldn't just barf like that.

This could be the core dump problem that my patch caused, but you shouldn't
be seeing both core dumps and truncated errors.

--
    Peter Haworth    pmh@edison.ioppublishing.com
"The most important thing in the programming language is the name. A language
 will not succeed without a good name. I have recently invented a very good
 name and now I am looking for a suitable language." -- D. E. Knuth, 1967