Обсуждение: Silencing NOTICEs in Perl Pg

Поиск
Список
Период
Сортировка

Silencing NOTICEs in Perl Pg

От
"David F. Skoll"
Дата:
Hi,

Libpq has a way to set the notice processor:
http://www.postgresql.org/idocs/index.php?libpq-control.html

Is there any way from within the Perl Pg module to turn off the printing
of NOTICEs to stderr?  It's a bit annoying in one of my projects.

Regards,

David.


Re: Silencing NOTICEs in Perl Pg

От
Andrew Perrin
Дата:
Sure - when you create the database handle, do:

$dbh =
DBI->connect('dbi:Pg:dbname=<dbname>',"<user>","<password>",{RaiseError=>0});

(use the RaiseError feature)

ap

----------------------------------------------------------------------
Andrew J Perrin - http://www.unc.edu/~aperrin
Assistant Professor of Sociology, U of North Carolina, Chapel Hill
clists@perrin.socsci.unc.edu * andrew_perrin (at) unc.edu


On Thu, 29 Aug 2002, David F. Skoll wrote:

> Hi,
>
> Libpq has a way to set the notice processor:
> http://www.postgresql.org/idocs/index.php?libpq-control.html
>
> Is there any way from within the Perl Pg module to turn off the printing
> of NOTICEs to stderr?  It's a bit annoying in one of my projects.
>
> Regards,
>
> David.
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org
>


Re: Silencing NOTICEs in Perl Pg

От
"David F. Skoll"
Дата:
On Thu, 29 Aug 2002, Andrew Perrin wrote:

> $dbh =
> DBI->connect('dbi:Pg:dbname=<dbname>',"<user>","<password>",{RaiseError=>0});

except I'm using the Pg Perl module directly, not DBI.  Will this
option (RaiseError) work with that module?

--
David.


Re: Silencing NOTICEs in Perl Pg

От
David Wheeler
Дата:
On Thursday, August 29, 2002, at 11:19  AM, David F. Skoll wrote:

> except I'm using the Pg Perl module directly, not DBI.  Will this
> option (RaiseError) work with that module?

Um, no, RaiseError is a DBI attribute. But, what Pg Perl module do you
mean? DBD::Pg only works with DBI, AFAIK.

Regards,

David

--
David Wheeler                                     AIM: dwTheory
david@wheeler.net                                 ICQ: 15726394
http://david.wheeler.net/                      Yahoo!: dew7e
                                                Jabber: Theory@jabber.org


Re: Silencing NOTICEs in Perl Pg

От
"David F. Skoll"
Дата:
On Thu, 29 Aug 2002, David Wheeler wrote:

> Um, no, RaiseError is a DBI attribute. But, what Pg Perl module do you
> mean? DBD::Pg only works with DBI, AFAIK.

PostgreSQL comes with its own "Pg" module, completely unrelated to DBI.
That's what I'm using.

Regards,

David.


Re: Silencing NOTICEs in Perl Pg

От
David Wheeler
Дата:
On Thursday, August 29, 2002, at 11:29  AM, David F. Skoll wrote:

> PostgreSQL comes with its own "Pg" module, completely unrelated to DBI.
> That's what I'm using.

Oh, never noticed that before.

May I suggest to the PostgreSQL developers that this be deprecated in
favor of DBI/DBD::Pg? That really is the standard way to interface to
databases in Perl.

Regards,

David

--
David Wheeler                                     AIM: dwTheory
david@wheeler.net                                 ICQ: 15726394
http://david.wheeler.net/                      Yahoo!: dew7e
                                                Jabber: Theory@jabber.org


Re: Silencing NOTICEs in Perl Pg

От
"Adam Erickson"
Дата:
FWIW, I've seen people use the DBD:: libs directly without DBI.

That doesn't mean you should! :)

> -----Original Message-----
> From: pgsql-admin-owner@postgresql.org
> [mailto:pgsql-admin-owner@postgresql.org]On Behalf Of David Wheeler
> Sent: Thursday, August 29, 2002 1:33 PM
> To: David F. Skoll
> Cc: Andrew Perrin; pgsql-admin@postgresql.org
> Subject: Re: [ADMIN] Silencing NOTICEs in Perl Pg
>
>
> On Thursday, August 29, 2002, at 11:29  AM, David F. Skoll wrote:
>
> > PostgreSQL comes with its own "Pg" module, completely unrelated to DBI.
> > That's what I'm using.
>
> Oh, never noticed that before.
>
> May I suggest to the PostgreSQL developers that this be deprecated in
> favor of DBI/DBD::Pg? That really is the standard way to interface to
> databases in Perl.
>
> Regards,
>
> David
>
> --
> David Wheeler                                     AIM: dwTheory
> david@wheeler.net                                 ICQ: 15726394
> http://david.wheeler.net/                      Yahoo!: dew7e
>                                                 Jabber: Theory@jabber.org
>

> ---------------------------(end of broadcast)---------------------------
> TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org

Re: Silencing NOTICEs in Perl Pg

От
Andrew Perrin
Дата:
Sorry, I didn't know that existed. Can't tell you how to use it,
therefore. What's the advantage over the DBI standard?

----------------------------------------------------------------------
Andrew J Perrin - http://www.unc.edu/~aperrin
Assistant Professor of Sociology, U of North Carolina, Chapel Hill
clists@perrin.socsci.unc.edu * andrew_perrin (at) unc.edu


On Thu, 29 Aug 2002, David F. Skoll wrote:

> On Thu, 29 Aug 2002, David Wheeler wrote:
>
> > Um, no, RaiseError is a DBI attribute. But, what Pg Perl module do you
> > mean? DBD::Pg only works with DBI, AFAIK.
>
> PostgreSQL comes with its own "Pg" module, completely unrelated to DBI.
> That's what I'm using.
>
> Regards,
>
> David.
>
>


Re: Silencing NOTICEs in Perl Pg

От
Bruno Wolff III
Дата:
On Thu, Aug 29, 2002 at 11:33:22 -0700,
  David Wheeler <david@wheeler.net> wrote:
> On Thursday, August 29, 2002, at 11:29  AM, David F. Skoll wrote:
>
> >PostgreSQL comes with its own "Pg" module, completely unrelated to DBI.
> >That's what I'm using.
>
> Oh, never noticed that before.
>
> May I suggest to the PostgreSQL developers that this be deprecated in
> favor of DBI/DBD::Pg? That really is the standard way to interface to
> databases in Perl.

Just because it is the standard way doesn't mean its the best way.
Pg is tied closely to libpg which may provide advantages in some cases.

For example, I believe DBI has a lame way to do things when autocommit is off.
It immediately starts a transaction rather than wait for a begin statement
to be sent. This has consequences that may not always be desirable.

Re: Silencing NOTICEs in Perl Pg

От
David Wheeler
Дата:
On Thursday, August 29, 2002, at 11:47  AM, Adam Erickson wrote:

> FWIW, I've seen people use the DBD:: libs directly without DBI.
>
> That doesn't mean you should! :)

I don't even know where to start on that one. People are crazy, too! ;-)

Regards,

David

--
David Wheeler                                     AIM: dwTheory
david@wheeler.net                                 ICQ: 15726394
http://david.wheeler.net/                      Yahoo!: dew7e
                                                Jabber: Theory@jabber.org


Re: Silencing NOTICEs in Perl Pg

От
David Wheeler
Дата:
On Thursday, August 29, 2002, at 12:04  PM, Bruno Wolff III wrote:

> Just because it is the standard way doesn't mean its the best way.
> Pg is tied closely to libpg which may provide advantages in some cases.

DBD::Pg is built with libpg, too, IIRC.

> For example, I believe DBI has a lame way to do things when autocommit
> is off.
> It immediately starts a transaction rather than wait for a begin
> statement
> to be sent. This has consequences that may not always be desirable.

Hrm, I've never head DBI called "lame" before. But its advantages lie
in its standardization of database access. But yes, some might consider
that a limitation.

BTW, the relatively new DBI begin_work() method may have overcome the
issue you raise.

Regards,

David

--
David Wheeler                                     AIM: dwTheory
david@wheeler.net                                 ICQ: 15726394
http://david.wheeler.net/                      Yahoo!: dew7e
                                                Jabber: Theory@jabber.org


Re: Silencing NOTICEs in Perl Pg

От
Bruno Wolff III
Дата:
On Thu, Aug 29, 2002 at 12:11:09 -0700,
  David Wheeler <david@wheeler.net> wrote:
>
> Hrm, I've never head DBI called "lame" before. But its advantages lie
> in its standardization of database access. But yes, some might consider
> that a limitation.

That was in reference to that specific detail (doing begin immediately
rather than when needed), not the library as a whole.

I actually use DBI and in some things I am doing for work I use both
DBI and Pg in the same perl script (that talks to both oracle and postgres).

> BTW, the relatively new DBI begin_work() method may have overcome the
> issue you raise.

Thanks for this information.

Re: Silencing NOTICEs in Perl Pg

От
David Wheeler
Дата:
BTW, I missed the beginning of this thread, but based on the subject,
I'd sure like to find out if there's a simple way to suppress NOTICEs
using DBI/DBD::Pg. I've tried a number of tricks, but short of closing
STDOUT and STDERR in my Perl script, I've not found a way to do it.
PrintError => 0 doesn't do the trick.

Thanks,

David

--
David Wheeler                                     AIM: dwTheory
david@wheeler.net                                 ICQ: 15726394
http://david.wheeler.net/                      Yahoo!: dew7e
                                                Jabber: Theory@jabber.org


Re: Silencing NOTICEs in Perl Pg

От
Bruno Wolff III
Дата:
On Thu, Aug 29, 2002 at 12:17:16 -0700,
  David Wheeler <david@wheeler.net> wrote:
> BTW, I missed the beginning of this thread, but based on the subject,
> I'd sure like to find out if there's a simple way to suppress NOTICEs
> using DBI/DBD::Pg. I've tried a number of tricks, but short of closing
> STDOUT and STDERR in my Perl script, I've not found a way to do it.
> PrintError => 0 doesn't do the trick.

I do the following before doing anything with the database:
open(OLDERR, '>&STDERR');
close(STDERR);
open(STDERR, '>/dev/null');

I then print my error messages to OLDERR instead of STDERR.

Re: Silencing NOTICEs in Perl Pg

От
David Wheeler
Дата:
On Thursday, August 29, 2002, at 01:02  PM, Bruno Wolff III wrote:

> On Thu, Aug 29, 2002 at 12:17:16 -0700,
>   David Wheeler <david@wheeler.net> wrote:
>> BTW, I missed the beginning of this thread, but based on the subject,
>> I'd sure like to find out if there's a simple way to suppress NOTICEs
>> using DBI/DBD::Pg. I've tried a number of tricks, but short of closing
>> STDOUT and STDERR in my Perl script, I've not found a way to do it.
>> PrintError => 0 doesn't do the trick.
>
> I do the following before doing anything with the database:
> open(OLDERR, '>&STDERR');
> close(STDERR);
> open(STDERR, '>/dev/null');

Thanks for the suggestion. Unfortunately, that doesn't allow me to
filter out just the NOTICEs, and let everything else be printed. The
solution I've come up with, for those who are interested, is either
this:

open STDERR, "| perl -e 'while (<>) { print unless /^NOTICE:  / }'"
   or die "Cannot pipe STDERR: $!\n";

Or this:

open STDERR, "| grep -v '^NOTICE:  '"
   or die "Cannot pipe STDERR to grep\n";

The former will be more portable, since we already know we have Perl ;-)

Thanks for the help!

David

--
David Wheeler                                     AIM: dwTheory
david@wheeler.net                                 ICQ: 15726394
http://david.wheeler.net/                      Yahoo!: dew7e
                                                Jabber: Theory@jabber.org


Re: Silencing NOTICEs in Perl Pg

От
Bruce Momjian
Дата:
7.3 will have client_min_message, which if set to WARNING will note show
notices.  7.3 is due out in a few months, beta starts next week.

---------------------------------------------------------------------------

David Wheeler wrote:
> On Thursday, August 29, 2002, at 01:02  PM, Bruno Wolff III wrote:
>
> > On Thu, Aug 29, 2002 at 12:17:16 -0700,
> >   David Wheeler <david@wheeler.net> wrote:
> >> BTW, I missed the beginning of this thread, but based on the subject,
> >> I'd sure like to find out if there's a simple way to suppress NOTICEs
> >> using DBI/DBD::Pg. I've tried a number of tricks, but short of closing
> >> STDOUT and STDERR in my Perl script, I've not found a way to do it.
> >> PrintError => 0 doesn't do the trick.
> >
> > I do the following before doing anything with the database:
> > open(OLDERR, '>&STDERR');
> > close(STDERR);
> > open(STDERR, '>/dev/null');
>
> Thanks for the suggestion. Unfortunately, that doesn't allow me to
> filter out just the NOTICEs, and let everything else be printed. The
> solution I've come up with, for those who are interested, is either
> this:
>
> open STDERR, "| perl -e 'while (<>) { print unless /^NOTICE:  / }'"
>    or die "Cannot pipe STDERR: $!\n";
>
> Or this:
>
> open STDERR, "| grep -v '^NOTICE:  '"
>    or die "Cannot pipe STDERR to grep\n";
>
> The former will be more portable, since we already know we have Perl ;-)
>
> Thanks for the help!
>
> David
>
> --
> David Wheeler                                     AIM: dwTheory
> david@wheeler.net                                 ICQ: 15726394
> http://david.wheeler.net/                      Yahoo!: dew7e
>                                                 Jabber: Theory@jabber.org
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Don't 'kill -9' the postmaster
>

--
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073

Re: Silencing NOTICEs in Perl Pg

От
David Wheeler
Дата:
On Thursday, August 29, 2002, at 05:50  PM, Bruce Momjian wrote:

> 7.3 will have client_min_message, which if set to WARNING will note
> show
> notices.  7.3 is due out in a few months, beta starts next week.

Yay!

It sounds like 7.3 is going to have a *lot* of great new features that
people have been wanting forever. Thanks, Bruce!

David

--
David Wheeler                                     AIM: dwTheory
david@wheeler.net                                 ICQ: 15726394
http://david.wheeler.net/                      Yahoo!: dew7e
                                                Jabber: Theory@jabber.org


Re: Silencing NOTICEs in Perl Pg

От
Tim Ellis
Дата:
> open STDERR, "| perl -e 'while (<>) { print unless /^NOTICE:  / }'"
>    or die "Cannot pipe STDERR: $!\n";

perl --help
 . . .
  -n              assume 'while (<>) { ... }' loop around program
  -p              assume loop like -n but print line also, like sed
 . . .

Thus,

perl -ne 'print unless /^NOTICE:  /'

--
Tim Ellis
Senior Database Architect
Gamet, Inc.

Re: Silencing NOTICEs in Perl Pg

От
David Wheeler
Дата:
On Thursday, August 29, 2002, at 03:36  PM, Tim Ellis wrote:

> perl -ne 'print unless /^NOTICE:  /'

D'oh! Can you tell that I'm not much of a Perl golfer? ;-) Thanks for
the tip!

Regards,

David

--
David Wheeler                                     AIM: dwTheory
david@wheeler.net                                 ICQ: 15726394
http://david.wheeler.net/                      Yahoo!: dew7e
                                                Jabber: Theory@jabber.org


Re: Silencing NOTICEs in Perl Pg

От
Andrew Perrin
Дата:
I don't know the Pg module at all, but if it uses warn() to dump those
notices to STDERR, you can use a sig handler to catch them:

$SIG{'__WARN__'} = sub {
    return if $_[0] =~ /^NOTICE:/;
    print STDERR join ("\n",@_);
    print STDERR "...at line " . caller(1) . "\n";
}



----------------------------------------------------------------------
Andrew J Perrin - http://www.unc.edu/~aperrin
Assistant Professor of Sociology, U of North Carolina, Chapel Hill
clists@perrin.socsci.unc.edu * andrew_perrin (at) unc.edu


On Thu, 29 Aug 2002, David Wheeler wrote:

> On Thursday, August 29, 2002, at 01:02  PM, Bruno Wolff III wrote:
>
> > On Thu, Aug 29, 2002 at 12:17:16 -0700,
> >   David Wheeler <david@wheeler.net> wrote:
> >> BTW, I missed the beginning of this thread, but based on the subject,
> >> I'd sure like to find out if there's a simple way to suppress NOTICEs
> >> using DBI/DBD::Pg. I've tried a number of tricks, but short of closing
> >> STDOUT and STDERR in my Perl script, I've not found a way to do it.
> >> PrintError => 0 doesn't do the trick.
> >
> > I do the following before doing anything with the database:
> > open(OLDERR, '>&STDERR');
> > close(STDERR);
> > open(STDERR, '>/dev/null');
>
> Thanks for the suggestion. Unfortunately, that doesn't allow me to
> filter out just the NOTICEs, and let everything else be printed. The
> solution I've come up with, for those who are interested, is either
> this:
>
> open STDERR, "| perl -e 'while (<>) { print unless /^NOTICE:  / }'"
>    or die "Cannot pipe STDERR: $!\n";
>
> Or this:
>
> open STDERR, "| grep -v '^NOTICE:  '"
>    or die "Cannot pipe STDERR to grep\n";
>
> The former will be more portable, since we already know we have Perl ;-)
>
> Thanks for the help!
>
> David
>
> --
> David Wheeler                                     AIM: dwTheory
> david@wheeler.net                                 ICQ: 15726394
> http://david.wheeler.net/                      Yahoo!: dew7e
>                                                 Jabber: Theory@jabber.org
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Don't 'kill -9' the postmaster
>


Re: Silencing NOTICEs in Perl Pg

От
David Wheeler
Дата:
On Friday, August 30, 2002, at 09:01  AM, Andrew Perrin wrote:

> I don't know the Pg module at all, but if it uses warn() to dump those
> notices to STDERR, you can use a sig handler to catch them:

I actually tried that, too. It didn't work. DDB::Pg just uses libpq,
and that C library is what generates the NOTICES. I think it uses C's
printf internally, but there was no way to capture that in Perl short
of filtering STDERR's output through a forked perl or grep.

Regards,

David

--
David Wheeler                                     AIM: dwTheory
david@wheeler.net                                 ICQ: 15726394
http://david.wheeler.net/                      Yahoo!: dew7e
                                                Jabber: Theory@jabber.org