Обсуждение: rotatelogs integration in pg_ctl

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

rotatelogs integration in pg_ctl

От
Andrew Hammond
Дата:
I've attached a patch for pg_ctl which integrates the Apache project's
rotatelogs for logging. Is there any interested in the community for
such a thing? I have not yet added the appropriate stuff to autoconf to
completely integrate this.

I would appreciate any suggestions for improvement.

Drew
--- pg_ctl    2004-03-19 14:01:40.000000000 -0500
+++ pg_ctl_new    2004-03-24 15:30:29.000000000 -0500
@@ -39,6 +39,9 @@
 Options for start or restart:
   -l FILENAME             write (or append) server log to FILENAME.  The
                           use of this option is highly recommended.
+  -r ROTATIONTIME         use apache's rotatelogs instead of writing
+                          dirrectly tto FILENAME. Rotate the logs every
+              ROTATIONTIME seconds (see man for rotatelogs)
   -o OPTIONS              command line options to pass to the postmaster
                           (PostgreSQL server executable)
   -p PATH-TO-POSTMASTER   normally not necessary
@@ -62,6 +65,10 @@
 VERSION='7.4.2'
 DEF_PGPORT='5432'

+# have autoconf detect this?
+apache_bindir='/opt/OXRS/apache/bin'
+rotatelogs_path="$apache_bindir/rotatelogs"
+
 # protect the log file
 umask 077

@@ -114,6 +121,7 @@
 wait=
 wait_seconds=60
 logfile=
+rotation_time=
 silence_echo=
 shutdown_mode=smart
 PGDATAOPTS=""
@@ -143,6 +151,12 @@
     -l*)
         logfile=`echo "$1" | sed 's/^-l//'`
         ;;
+    -r)
+        rotation_time="$2"
+        shift;;
+    -r*)
+        rotation_time=`echo "$1" | sed 's/^-m//'`
+        ;;
     -m)
         shutdown_mode="$2"
         shift;;
@@ -207,6 +221,18 @@
     exit 1
 fi

+if [ ! x"$rotation_time" = x"" ]; then
+    if [ ! -x $rotatelogs_path ]; then
+        echo "$CMDNAME: log rotation specified but can't find $rotatelogs_path" 1>&2
+        exit 1
+    fi
+
+    if [ x"$logfile" = x"" ]; then
+        echo "$CMDNAME: log rotation specified but no logfile given. Try the -l option." 1>&2
+        exit 1
+    fi
+fi
+
 if [ -z "$wait" ]; then
     case "$op" in
     start)      wait=no;;
@@ -338,7 +364,11 @@
     fi

     if [ -n "$logfile" ]; then
+        if [ -n "$rotation_time" ]; then         # use rotatelogs for logging
+            "$po_path" ${1+"$@"} ${PGDATAOPTS+$PGDATAOPTS} </dev/null 2>&1 | "$rotatelogs_path" $logfile
$rotation_time& 
+    else
         "$po_path" ${1+"$@"} ${PGDATAOPTS+$PGDATAOPTS} </dev/null >>$logfile 2>&1 &
+    fi
     else
         # when starting without log file, redirect stderr to stdout, so
         # pg_ctl can be invoked with >$logfile and still have pg_ctl's

Re: rotatelogs integration in pg_ctl

От
Tom Lane
Дата:
Andrew Hammond <ahammond@ca.afilias.info> writes:
> I've attached a patch for pg_ctl which integrates the Apache project's 
> rotatelogs for logging.

Why bother?  You just pipe pg_ctl's output to rotatelogs and you're
done.
        regards, tom lane


Re: rotatelogs integration in pg_ctl

От
Andrew Hammond
Дата:
Tom Lane wrote:
> Andrew Hammond <ahammond@ca.afilias.info> writes:
> 
>>I've attached a patch for pg_ctl which integrates the Apache project's 
>>rotatelogs for logging.
> 
> Why bother?  You just pipe pg_ctl's output to rotatelogs and you're
> done.

It's not difficult to do, once you know how and once you know that there 
aren't any gotchas. However, the question comes up often enough it's 
clear that not everybody knows how. This provides a simple, clean, 
standardized way of using rotatelog. The patch is simple, low risk, and 
limited impact. So, why not?

Drew


Re: rotatelogs integration in pg_ctl

От
"Thomas Swan"
Дата:
<quote who="Andrew Hammond">
> Tom Lane wrote:
>> Andrew Hammond <ahammond@ca.afilias.info> writes:
>>>I've attached a patch for pg_ctl which integrates the Apache project's
rotatelogs for logging.
>> Why bother?  You just pipe pg_ctl's output to rotatelogs and you're done.
>
> It's not difficult to do, once you know how and once you know that there
aren't any gotchas. However, the question comes up often enough it's
clear that not everybody knows how. This provides a simple, clean,
standardized way of using rotatelog. The patch is simple, low risk, and
limited impact. So, why not?
>

Is there a reason the postmasters cannot just close/reopen-recreate the
log file when a SIGHUP or other signal is issued like apache?  This would
allow for almost any scheme for log rotation to be handled by the system
or third party like logrotate and removes any duplicate effort between
projects.

I know on most distributions /var/log is not world writeable, so renaming
and and opening a file as postgres will not succeed.   If the log files
are put in, for example, /var/log/pgsql with pgsql being rwx by postgres,
then it will work.  The current packaging may need to be redone if you
want to enable loggin by default (if only startup and shutdown messages)







Re: rotatelogs integration in pg_ctl

От
Bruno Wolff III
Дата:
On Tue, Apr 13, 2004 at 09:33:42 -0500, Thomas Swan <tswan@idigx.com> wrote:
> 
> Is there a reason the postmasters cannot just close/reopen-recreate the
> log file when a SIGHUP or other signal is issued like apache?  This would
> allow for almost any scheme for log rotation to be handled by the system
> or third party like logrotate and removes any duplicate effort between
> projects.

Wouldn't that break logs piped to a program?


Re: rotatelogs integration in pg_ctl

От
Peter Eisentraut
Дата:
Thomas Swan wrote:
> Is there a reason the postmasters cannot just close/reopen-recreate
> the log file when a SIGHUP or other signal is issued like apache? 

Yes, because there is no "log file".  The postmaster writes to stdout or 
stderr.



Re: rotatelogs integration in pg_ctl

От
"Thomas Swan"
Дата:
<quote who="Peter Eisentraut">
> Thomas Swan wrote:
>> Is there a reason the postmasters cannot just close/reopen-recreate
>> the log file when a SIGHUP or other signal is issued like apache?
>
> Yes, because there is no "log file".  The postmaster writes to stdout or
> stderr.
>
>

Ok, my misunderstanding.  stdout/stderr are redirected to a file on
startup.  This is why when I move/rename the logfile I have to stop/start
postgresql to start appending to the empty file.

Would there be any interest in modifying postmaster to support native file
logging in addition to stderr and stdout output?  Are there any terrible
drawbacks that you could foresee?




Re: rotatelogs integration in pg_ctl

От
Peter Eisentraut
Дата:
Thomas Swan wrote:
> Would there be any interest in modifying postmaster to support native
> file logging in addition to stderr and stdout output?  Are there any
> terrible drawbacks that you could foresee?

We have about 8 years of mailing list archives describing them.