pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: pgsql-admin <pgsql-admin@fc.emc.com.ph>
To: peter_e@gmx.net
Cc: bjames@inetmi.com
Cc: pgsql-admin@postgresql.org
Subject: Re(2): Postgres/Postmaster logging and log rotation
Date: Thu, 08 Mar 2001 21:50:33 +0800
Message-ID: <fc.000f567200a25ab5000f567200a25ab5.a25ae7@fc.emc.com.ph> (raw)

peter_e@gmx.net writes:
>William L James writes:
>
>> script - su -l postgresql -c "/usr/bin/pg_ctl -D $PGDATA -p
>> /usr/bin/postmaster start >>/var/log/postgresql 2>&1"), but
>> when the weekly logrotate.d function kicks in, Postgres logging
>> stops.
>
>The logging probably continues to go to the rotated-away file.  The
>typical log rotation cron job presumes that the daemons close the log
>files periodically.  This is not the case with PostgreSQL.  A good
>solution is to pipe your log output to a small program that does the log
>rotating (or simply closes the log file once in a while), like rotatelogs
>from Apache.

I also have this problem in our Posgresql 6.5.3 (too old) server.
Actually we have already migrated to 7.0.3 but there are still programs 
that uses the old one.

In 7.0.3, it was no problem. I just set pg_option to
   verbose=2
   query=2
   syslog=1   
and added 
    local0.*                                        /var/log/postgresql   
in syslog.conf.

In 6.5.3, I tried your suggestion.
I put this in /etc/rc.d/init.d/postgresql:
 su -l postgres -c '/usr/bin/postmaster -B 2048 -o "-S 1024" -i -D
/var/lib/pgsql -d 2 | /root/logger.pl >/dev/null 2>&1 &' 
and added 
    local0.*                                        /var/log/postgresql   
in syslog.conf.
 
It is working but aside from writing to /var/log/postgresql it is also
writing to the console where the portmaster was started.
And what I can't  understand is that what was written in the console is
different from the log file.
The writings to the console was something like this:

% (/dev/pts/4) /etc/rc.d/init.d/postgresql restart
Stopping postgresql service:                               [  OK  ]
Checking postgresql installation: looks good!
Starting postgresql service: FindExec: found "/usr/bin/postgres" using
argv[0]
binding ShmemCreate(key=52e2c1, size=17994752)
postmaster [25489]
/usr/bin/postmaster: ServerLoop:         handling reading 5
/usr/bin/postmaster: ServerLoop:                handling reading 5
/usr/bin/postmaster: ServerLoop:                handling writing 5
/usr/bin/postmaster: BackendStartup: pid 25530 user root db testing socket
5
/usr/bin/postmaster child[25530]: starting with (/usr/bin/postgres -d2 -B
2048 -S 1024 -v131072 -p testing )

and in /var/log/postgresql was something like this:

Mar  8 21:08:36 tae postgres[27378]: StartTransactionCommand
Mar  8 21:08:36 tae postgres[27378]: query: SELECT * FROM office
Mar  8 21:08:36 tae postgres[27378]: ProcessQuery
Mar  8 21:08:36 tae postgres[27378]: CommitTransactionCommand
Mar  8 21:08:36 tae postgres[27378]: proc_exit(0) [#0]
Mar  8 21:08:36 tae postgres[27378]: shmem_exit(0) [#0]
Mar  8 21:08:36 tae postgres[27378]: exit(0)           

Can anybody tell me what's going on here? Thanks.

Anyway here's the logger.pl (taken from Cute tricks with Perl & Apache)
   note: I forgot the whole url where I got it and I also modified it a
little bit

#!/usr/bin/perl
use Sys::Syslog;
 
$SERVER_NAME = shift || 'postgres';
$FACILITY = 'local0';
$PRIORITY = 'debug';
 
Sys::Syslog::setlogsock('unix');
openlog ($SERVER_NAME,'ndelay,pid',$FACILITY);
while (<>) {
  chomp;
  syslog($PRIORITY,$_);
}
closelog;    




Message-ID: <fc.000f567200a25ab5000f567200a25ab5.a25ae7@fc.emc.com.ph>
Permalink:  ../fc.000f567200a25ab5000f567200a25ab5.a25ae7@fc.emc.com.ph/
Also on:    postgresql.org/message-id/fc.000f567200a25ab5000f567200a25ab5.a25ae7@fc.emc.com.ph

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-admin@postgresql.org
  Cc: pgsql-admin@fc.emc.com.ph, peter_e@gmx.net, bjames@inetmi.com
  Subject: Re: Postgres/Postmaster logging and log rotation
  In-Reply-To: <fc.000f567200a25ab5000f567200a25ab5.a25ae7@fc.emc.com.ph>
  References: <fc.000f567200a25ab5000f567200a25ab5.a25ae7@fc.emc.com.ph>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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