Thread: syslog facilites and postgres ?

syslog facilites and postgres ?

From
"Day, David"
Date:

 


Hi,

 

Should I be able to run two syslog facilities simultaneously ( postgres local0, and a  trigger function to  local3 ) successfully ?

 

I have postgresql 9.3.1exit running on freebsd and sending errors  to “syslog_facility= local0”.

That works fine.

 

I have created an insert  trigger on one of my datatables using plperlu that opens syslog to facility local3 which directs

portions of that newly inserted record to local3. ( see below).  This works with the the following issue.

 

I find occasional notifications in my local3 log file that should I believe be in the local0 log file.  E.g. I will see some of

my RAISE LOG output in the local3 output log file rather than in the local0 output log file.   I suspect this is happening

during the window in which local3 is open and closed in the trigger function.   I note that the errant notification I find in local3 is not also found

in local0.

 

 

Any suggestions on this concept ?

 

 

Thanks

 

 

Dave Day

  

 

CREATE OR REPLACE FUNCTION log.connection_history_post_insert()

  RETURNS trigger AS

$BODY$

  use Sys::Syslog;

  openlog('smdr', 'ndelay,pid', 'local3');

  my $tmp = $_TD->{new} {orig_addr} .'->' . $_TD->{new} {term_addr} . '~' . $_TD->{new} {answer_datetime}

  syslog ("info", "data %s ", $tmp);

  closelog();

  return;

$BODY$

  LANGUAGE plperlu VOLATILE

Re: syslog facilites and postgres ?

From
Tom Lane
Date:
"Day, David" <dday@redcom.com> writes:
> Should I be able to run two syslog facilities simultaneously ( postgres local0, and a  trigger function to  local3 )
successfully? 

Probably not.  libc's support for writing to syslog is not re-entrant.

> I have created an insert  trigger on one of my datatables using plperlu that opens syslog to facility local3 which
directs
> portions of that newly inserted record to local3. ( see below).  This works with the the following issue.

> I find occasional notifications in my local3 log file that should I believe be in the local0 log file.  E.g. I will
seesome of 
> my RAISE LOG output in the local3 output log file rather than in the local0 output log file.   I suspect this is
happening
> during the window in which local3 is open and closed in the trigger function.   I note that the errant notification I
findin local3 is not also found 
> in local0.

TBH, I'm astonished that this doesn't break logging to local0 entirely.
Quite aside from the effect you're complaining of, I'd expect it to bollix
subsequent syslog output.  After your closelog(), the next syslog() call
would do an implicit openlog(), but with default parameters --- or so I'd
expect anyway.

You could probably un-break that aspect by duplicating Postgres' normal
openlog call after closing the local3 descriptor:

        openlog(syslog_ident ? syslog_ident : "postgres",
                LOG_PID | LOG_NDELAY | LOG_NOWAIT,
                syslog_facility);

but this seems awfully fragile, and it certainly won't do anything for
any messages Postgres tries to emit while you've got the syslog connection
redirected to local3.

Do you really need to have it work like that?

            regards, tom lane


Re: syslog facilites and postgres ?

From
"Day, David"
Date:
Tom,

I will not claim I've totally observed all the fallout of attempting this.
You may be correct about subsequent local0 output being bollixed but I certainly have seen some continued output to
local0after the trigger. 

I am not committed to this method. It was primarily an experiment for proof of concept.
Based on your reservations,  I will pursue some other ideas.

Thanks much for the feedback and preventing me from wasting to much time on this avenue.


Rgds

Dave





-----Original Message-----
From: Tom Lane [mailto:tgl@sss.pgh.pa.us]
Sent: Tuesday, February 18, 2014 4:02 PM
To: Day, David
Cc: pgsql-general@postgresql.org
Subject: Re: [GENERAL] syslog facilites and postgres ?

"Day, David" <dday@redcom.com> writes:
> Should I be able to run two syslog facilities simultaneously ( postgres local0, and a  trigger function to  local3 )
successfully? 

Probably not.  libc's support for writing to syslog is not re-entrant.

> I have created an insert  trigger on one of my datatables using
> plperlu that opens syslog to facility local3 which directs portions of that newly inserted record to local3. ( see
below). This works with the the following issue. 

> I find occasional notifications in my local3 log file that should I believe be in the local0 log file.  E.g. I will
seesome of 
> my RAISE LOG output in the local3 output log file rather than in the local0 output log file.   I suspect this is
happening
> during the window in which local3 is open and closed in the trigger function.   I note that the errant notification I
findin local3 is not also found 
> in local0.

TBH, I'm astonished that this doesn't break logging to local0 entirely.
Quite aside from the effect you're complaining of, I'd expect it to bollix subsequent syslog output.  After your
closelog(),the next syslog() call would do an implicit openlog(), but with default parameters --- or so I'd expect
anyway.

You could probably un-break that aspect by duplicating Postgres' normal openlog call after closing the local3
descriptor:

        openlog(syslog_ident ? syslog_ident : "postgres",
                LOG_PID | LOG_NDELAY | LOG_NOWAIT,
                syslog_facility);

but this seems awfully fragile, and it certainly won't do anything for any messages Postgres tries to emit while you've
gotthe syslog connection redirected to local3. 

Do you really need to have it work like that?

            regards, tom lane