Thread: pgbench on mingw needs fflush

pgbench on mingw needs fflush

From
ITAGAKI Takahiro
Date:
pgbench reports its progress of loading ("N tuples done.") or vacuuming
("vacuum...end"), but the messages are not printed on the moment on mingw.
The reason seems to be the buffering of stderr. This patch adds fflush()
just after each fprintf(stderr).

The buffered stderr might be a bug of mingw, but redundant fflush()
does not make mischief for platforms that have correct stderr.

Regards,
---
ITAGAKI Takahiro
NTT Open Source Software Center

Attachment

Re: pgbench on mingw needs fflush

From
Tatsuo Ishii
Date:
Can we distinguish mingw case from others so that we could ifdef out
the extra fflush()?
--
Tatsuo Ishii
SRA OSS, Inc. Japan

> pgbench reports its progress of loading ("N tuples done.") or vacuuming
> ("vacuum...end"), but the messages are not printed on the moment on mingw.
> The reason seems to be the buffering of stderr. This patch adds fflush()
> just after each fprintf(stderr).
>
> The buffered stderr might be a bug of mingw, but redundant fflush()
> does not make mischief for platforms that have correct stderr.
>
> Regards,
> ---
> ITAGAKI Takahiro
> NTT Open Source Software Center

Re: pgbench on mingw needs fflush

From
Tatsuo Ishii
Date:
Can we distinguish mingw case from others so that we could ifdef out
the extra fflush()?
--
Tatsuo Ishii
SRA OSS, Inc. Japan

> pgbench reports its progress of loading ("N tuples done.") or vacuuming
> ("vacuum...end"), but the messages are not printed on the moment on mingw.
> The reason seems to be the buffering of stderr. This patch adds fflush()
> just after each fprintf(stderr).
>
> The buffered stderr might be a bug of mingw, but redundant fflush()
> does not make mischief for platforms that have correct stderr.
>
> Regards,
> ---
> ITAGAKI Takahiro
> NTT Open Source Software Center

Re: pgbench on mingw needs fflush

From
Tom Lane
Date:
Tatsuo Ishii <ishii@sraoss.co.jp> writes:
> Can we distinguish mingw case from others so that we could ifdef out
> the extra fflush()?

Isn't the right fix a single-spot patch to force stderr into unbuffered
mode?  It's supposed to be that way already per spec.  I could see a
one-or-two-line patch to remind mingw of the buffer mode it's supposed
to be using ... I'm not excited about making an ongoing commitment to
remember to fflush() after every write call, especially not when no
standard-compliant platform needs it.

            regards, tom lane

Re: pgbench on mingw needs fflush

From
ITAGAKI Takahiro
Date:
Tatsuo Ishii <ishii@sraoss.co.jp> wrote:

> Can we distinguish mingw case from others so that we could ifdef out
> the extra fflush()?
> > The buffered stderr might be a bug of mingw

After a little research, I found that MSDN says the buffered stderr is
a specifications on Windows somehow, not a bug.

setvbuf() is better solution for the problem.
This is more simple and no need to use ifdef.



*** pgbench.c.orig    Mon Jan 22 11:17:30 2007
--- pgbench.c    Tue Mar 13 17:01:12 2007
*************** main(int argc, char **argv)
*** 1184,1189 ****
--- 1184,1192 ----

      char        val[64];

+     /* stderr is buffered on Win32. */
+     setvbuf(stderr, NULL, _IONBF, 0);
+
      if ((env = getenv("PGHOST")) != NULL && *env != '\0')
          pghost = env;
      if ((env = getenv("PGPORT")) != NULL && *env != '\0')

Regards,
---
ITAGAKI Takahiro
NTT Open Source Software Center



Re: pgbench on mingw needs fflush

From
Magnus Hagander
Date:
On Tue, Mar 13, 2007 at 05:09:15PM +0900, ITAGAKI Takahiro wrote:
>
> Tatsuo Ishii <ishii@sraoss.co.jp> wrote:
>
> > Can we distinguish mingw case from others so that we could ifdef out
> > the extra fflush()?
> > > The buffered stderr might be a bug of mingw
>
> After a little research, I found that MSDN says the buffered stderr is
> a specifications on Windows somehow, not a bug.
>
> setvbuf() is better solution for the problem.
> This is more simple and no need to use ifdef.

I was just going to suggest this, because this is what we already use in
the backend (src/backend/main/main.c).

Applied, but with the #ifdefs, because that's cleaner and that's also
how we do it in the backend.

//Magnus

Re: pgbench on mingw needs fflush

From
Bruce Momjian
Date:
Magnus Hagander wrote:
> On Tue, Mar 13, 2007 at 05:09:15PM +0900, ITAGAKI Takahiro wrote:
> >
> > Tatsuo Ishii <ishii@sraoss.co.jp> wrote:
> >
> > > Can we distinguish mingw case from others so that we could ifdef out
> > > the extra fflush()?
> > > > The buffered stderr might be a bug of mingw
> >
> > After a little research, I found that MSDN says the buffered stderr is
> > a specifications on Windows somehow, not a bug.
> >
> > setvbuf() is better solution for the problem.
> > This is more simple and no need to use ifdef.
>
> I was just going to suggest this, because this is what we already use in
> the backend (src/backend/main/main.c).
>
> Applied, but with the #ifdefs, because that's cleaner and that's also
> how we do it in the backend.

And the #ifdef documents we need it only on Win32.  Without it, someone
might remove it thinking Unix doesn't need it.

--
  Bruce Momjian  <bruce@momjian.us>          http://momjian.us
  EnterpriseDB                               http://www.enterprisedb.com

  + If your life is a hard drive, Christ can be your backup. +