Re: Log rotation - Mailing list pgsql-hackers

From Bruce Momjian
Subject Re: Log rotation
Date
Msg-id 200403142042.i2EKgVn24655@candle.pha.pa.us
Whole thread Raw
In response to Re: Log rotation  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: Log rotation
Re: Log rotation
List pgsql-hackers
Tom Lane wrote:
> Bruce Momjian <pgman@candle.pha.pa.us> writes:
> > I wonder if this fsync for PostgreSQL messages is some change made to
> > Linux syslog.
> 
> You're missing the point: by default syslog fsyncs *all* messages.
> You can turn this off on a per-output-file basis by putting "-" on the
> desired lines of the syslog config file.  It has nothing whatever to do
> with Postgres.
> 
> The fact that you don't see any fsync calls doesn't prove anything.  How
> about O_SYNC or O_DSYNC flags when opening the output files?  That would
> be the natural way to implement it given the spec.

Well, doing a grep for sync, I see:
(2) grep -i -4 SYNC syslogd.c/* Flags to logmsg(). */#define IGN_CONS        0x001   /* don't print on console
*/#defineSYNC_FILE       0x002   /* do fsync on file after printing */#define ADDDATE         0x004   /* add a date to
themessage */#define MARK            0x008   /* this message is a mark *//* Types of actions */--        char *lp;
 lp = msg + msglen;        for (p = msg; p < lp; p = q + 1) {                flags = SYNC_FILE | ADDDATE;    /* fsync
fileafter write */                if (parse_pri(&p, &pri)) {                        if (pri &
~(LOG_FACMASK|LOG_PRIMASK))                               pri = DEFSPRI;                } else {--
             f->f_name));                        }                } else {                        f->f_warning = 0;
                  if (flags & SYNC_FILE)                                (void)fsync(f->f_file);                }
       break;        case F_USER:--                p += snprintf(p, sizeof(buf) + buf - p, ": %s",
       strerror(errno));        dprintf(("%s\n", buf));        logmsg(LOG_SYSLOG|LOG_ERR, NULL, buf, p - buf,
LocalHostName,           ADDDATE|SYNC_FILE);}
 

Which basically shows one fsync, no O_SYNC's, and setting of the flag
only for klog reads.

> strace'ing syslogd on my HPUX box shows that it doesn't issue explicit
> fsync calls either, but I don't know of any way to tell whether it's got
> the log files opened O_SYNC.
> 
> BTW the Linux man page says specifically that their syslogd tries to be
> compatible with BSD.

Yes, I saw that too, but maybe not in this area.  It is all in one file,
so here is the FreeBSD version:
http://www.freebsd.org/cgi/cvsweb.cgi/src/usr.sbin/syslogd/syslogd.c?rev=1.59.2.28&content-type=text/x-cvsweb-markup

--  Bruce Momjian                        |  http://candle.pha.pa.us pgman@candle.pha.pa.us               |  (610)
359-1001+  If your life is a hard drive,     |  13 Roberts Road +  Christ can be your backup.        |  Newtown Square,
Pennsylvania19073
 


pgsql-hackers by date:

Previous
From: jseymour@LinxNet.com (Jim Seymour)
Date:
Subject: Patch for: 7.4.2 build broken on Solaris 7 and 8 with --enable-thread-safety
Next
From: Andrew Dunstan
Date:
Subject: Re: listening addresses