Unix Technical Forum

Re: pgbench on mingw needs fflush

This is a discussion on Re: pgbench on mingw needs fflush within the Pgsql Patches forums, part of the PostgreSQL category; --> Can we distinguish mingw case from others so that we could ifdef out the extra fflush()? -- Tatsuo Ishii ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > Pgsql Patches

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-18-2008, 09:41 AM
Tatsuo Ishii
 
Posts: n/a
Default Re: pgbench on mingw needs fflush

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


---------------------------(end of broadcast)---------------------------
TIP 9: In versions below 8.0, the planner will ignore your desire to
choose an index scan if your joining column's datatypes do not
match

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-18-2008, 09:41 AM
Tom Lane
 
Posts: n/a
Default Re: pgbench on mingw needs fflush

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

---------------------------(end of broadcast)---------------------------
TIP 6: explain analyze is your friend

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-18-2008, 09:41 AM
ITAGAKI Takahiro
 
Posts: n/a
Default Re: pgbench on mingw needs fflush


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



---------------------------(end of broadcast)---------------------------
TIP 4: Have you searched our list archives?

http://archives.postgresql.org

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-18-2008, 09:41 AM
Magnus Hagander
 
Posts: n/a
Default Re: pgbench on mingw needs fflush

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

---------------------------(end of broadcast)---------------------------
TIP 4: Have you searched our list archives?

http://archives.postgresql.org

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 04-18-2008, 09:43 AM
Bruce Momjian
 
Posts: n/a
Default Re: pgbench on mingw needs fflush

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. +

---------------------------(end of broadcast)---------------------------
TIP 6: explain analyze is your friend

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 03:32 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com