BUG #1057: psql sometimes does not flush its output - Mailing list pgsql-bugs

From PostgreSQL Bugs List
Subject BUG #1057: psql sometimes does not flush its output
Date
Msg-id 20040120225208.B0D1ECF4BF4@www.postgresql.com
Whole thread Raw
List pgsql-bugs
The following bug has been logged online:

Bug reference:      1057
Logged by:          Jon Sablatnig

Email address:      jhs@cs.tu-berlin.de

PostgreSQL version: 7.4

Operating system:   Linux 2.4

Description:        psql sometimes does not flush its output

Details:

The frontend psql will usually flush its output after
every command.

Since version 7.4, it will NOT flush after its FIRST
command, if the output is NOT a tty.

Testcase:
    $ psql template1 | more
Now type:
    \qecho hello

The text will NOT appear.
Try it again, both lines will appear.

This is rather annoying when trying to parse the output
automatically, so please revert to the old behaviour of
always flushing.



Analysis & fix:
The relevant files are
    postgresql-7.4.1/src/bin/psql/mainloop.c
, and the same file in postgresql-7.3.4.

Specifically, the else{} block from line 161 on (both
files) changed so that the fflush(stdout) moved inside
the if (pset.cur_cmd_interactive).  Undoing this change
will fix the bug.

Another, perhaps slightly cleaner option is to add the
line
    fflush(pset.queryFout);
just before the end of the main while loop (line 499
in 7.4).  This also fixes the bug.

Laters,
jon

pgsql-bugs by date:

Previous
From: "PostgreSQL Bugs List"
Date:
Subject: BUG #1056: ecpg ignores WHENEVER NOT FOUND
Next
From: Michael Meskes
Date:
Subject: Re: BUG #1056: ecpg ignores WHENEVER NOT FOUND