On Tue, Jan 13, 2009 at 4:58 PM, Tom Lane <t...@sss.pgh.pa.us> wrote:
> "Joshua D. Drake" <j...@commandprompt.com> writes:
>> I have perfectly good log rotation utility that exists on my OS. (yes I
>> am aware of the possibility of losing a log entry when using logrotate).
>
> You might think you do, but it won't work with PG; external rotators
> only work with programs that respond to SIGHUP by re-opening their log
> files.

If that were true, then we would surely want to change it so that it
always re-opens the log file in response to SIGHUP.  But I don't think
it is - it seems we have pg_rotate_logfile() for that purpose.
Standard utilities like the logrotate that ships with Fedora can run
an external command after rotating the log file, and that external
command can arrange to invoke pg_rotate_logfile().  Admittedly, this
may be a little bit clunky: maybe we should always reopen the logfiles
on receipt of a SIGHUP, since there doesn't seem to be much of a
downside.

(It's true that if we go that route more people will set up external
log rotators to SIGHUP PostgreSQL, and that could increase the chance
of SIGHUP causing the postgresql.conf file to be reloaded when the
user wasn't quite ready, but that doesn't seem to be much of an
argument for not doing it.  Apache does the same thing, and on one
occasion it took down my entire web server, but I don't blame the
Apache project for the fact that I left my configuration in a
screwed-up state before taking off for the weekend.)

Automatically adding the date is a much bigger problem for an external
rotator.  It means that there is no way to get a constant filename.  I
don't think there's a clean way to handle that situation using Red
Hat's logrotate, which may be why Red Hat's out-of-the-box PG
configuration doesn't handle PG logfiles the way it handles all of its
other log files, which may be why I wasn't really aware that PG even
HAD a log file until about six months ago.

Suggested patch attached.

...Robert
*** a/doc/src/sgml/config.sgml
--- b/doc/src/sgml/config.sgml
***************
*** 2399,2412 **** local0.*    /var/log/postgresql
          file names.  (Note that if there are
          any time-zone-dependent <literal>%</literal>-escapes, the computation
          is done in the zone specified by <xref linkend="guc-log-timezone">.)
!         If no <literal>%</literal>-escapes are present,
!         <productname>PostgreSQL</productname> will append the epoch of the new
!         log file's creation time.  For example, if
!         <varname>log_filename</varname> were <literal>server_log</literal>,
!         then the chosen file name would be <literal>server_log.1093827753</>
!         for a log starting at Sun Aug 29 19:02:33 2004 MST.
!         Note that the system's <systemitem>strftime</systemitem> is not used
!         directly, so platform-specific (nonstandard) extensions do not work.
         </para>
         <para>
          If CSV-format output is enabled in <varname>log_destination</>,
--- 2399,2412 ----
          file names.  (Note that if there are
          any time-zone-dependent <literal>%</literal>-escapes, the computation
          is done in the zone specified by <xref linkend="guc-log-timezone">.)
!        </para>
!        <para>
!         (In releases prior to 8.4, if no <literal>%</literal-escapes were
!         present, <productname>PostgreSQL</productname> would append the epoch
!         of the new log file's creation time; however, this is no longer the
!         case.  If you specify a file name without escapes, you should plan to
!         use a log rotation utility to avoid eventually filling the entire
!         disk.)
         </para>
         <para>
          If CSV-format output is enabled in <varname>log_destination</>,
*** a/src/backend/postmaster/syslogger.c
--- b/src/backend/postmaster/syslogger.c
***************
*** 1193,1210 **** logfile_getname(pg_time_t timestamp, char *suffix)
  
  	len = strlen(filename);
  
! 	if (strchr(Log_filename, '%'))
! 	{
! 		/* treat it as a strftime pattern */
! 		pg_strftime(filename + len, MAXPGPATH - len, Log_filename,
! 					pg_localtime(&timestamp, log_timezone));
! 	}
! 	else
! 	{
! 		/* no strftime escapes, so append timestamp to new filename */
! 		snprintf(filename + len, MAXPGPATH - len, "%s.%lu",
! 				 Log_filename, (unsigned long) timestamp);
! 	}
  
  	if (suffix != NULL)
  	{
--- 1193,1201 ----
  
  	len = strlen(filename);
  
! 	/* treat it as a strftime pattern */
! 	pg_strftime(filename + len, MAXPGPATH - len, Log_filename,
! 		pg_localtime(&timestamp, log_timezone));
  
  	if (suffix != NULL)
  	{
-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Reply via email to