Re: Logging SQL queries?

From: Stephane Bortzmeyer <bortzmeyer(at)nic(dot)fr>
To: Kevin Brannen <kevinb(at)nurseamerica(dot)net>
Cc: Stephane Bortzmeyer <bortzmeyer(at)nic(dot)fr>, PostgreSQL General Mailing List <pgsql-general(at)postgresql(dot)org>
Subject: Re: Logging SQL queries?
Date: 2002-07-19 08:21:10
Message-ID: 20020719082110.GA19055@nic.fr
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Thu, Jul 18, 2002 at 02:42:32PM -0500,
Kevin Brannen <kevinb(at)nurseamerica(dot)net> wrote
a message of 25 lines which said:

> You can easily do it Perl, (I do :-) use the Unix::Syslog module.

OK, that's what I do, except that I use Sys::Syslog (Unix::Syslog does
not seem to work at my place). Here is the code:

CREATE FUNCTION log_creation (TEXT) RETURNS BOOLEAN AS '
use Sys::Syslog;
openlog "PostgreSQL", "pid", "local7";
syslog "info", "Created: %s", $_[0];
closelog;
return 1;
' LANGUAGE plperlu;
-- Installation on Debian needs:
-- apt-get install libpgperl
-- /usr/lib/postgresql/bin/createlang plperlu ${MYDATABASE}

CREATE FUNCTION do_log () RETURNS OPAQUE AS '
BEGIN
PERFORM log_creation(NEW.name);
RETURN NEW;
END;
' LANGUAGE PLPGSQL;

CREATE TRIGGER do_log
AFTER INSERT ON Domains
FOR EACH ROW
EXECUTE PROCEDURE do_log();

> Ignoring the argument about whether global vars are good or bad, global
> vars in Perl are merely fully [package] qualified named vars.
> Therefore, you can do:
>
> $main::mylog = "some value";
>
> and if you always reference it that way, e.g.
> print "Log file is $main::mylog\n"

Thanks but, anyway, openlog does not return anything, so global
variables would not help. I just call openlog each time, hoping it is
not too much overhead.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Cserna Zsolt 2002-07-19 08:27:33 sequence scan, but indexed tables
Previous Message Curt Sampson 2002-07-19 08:06:30 Re: OIDs (Or: another RTFM question?)