Re: Log rotation

From: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Fernando Nasser <fnasser(at)redhat(dot)com>, Lamar Owen <lowen(at)pari(dot)edu>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Log rotation
Date: 2004-03-14 20:42:31
Message-ID: 200403142042.i2EKgVn24655@candle.pha.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Tom Lane wrote:
> Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)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 */
#define SYNC_FILE 0x002 /* do fsync on file after printing */
#define ADDDATE 0x004 /* add a date to the message */
#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 file after 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(at)candle(dot)pha(dot)pa(dot)us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Andrew Dunstan 2004-03-14 20:42:39 Re: listening addresses
Previous Message Jim Seymour 2004-03-14 20:06:59 Patch for: 7.4.2 build broken on Solaris 7 and 8 with --enable-thread-safety