Unix Technical Forum

psql: flush output in cursor-fetch mode

This is a discussion on psql: flush output in cursor-fetch mode within the Pgsql Patches forums, part of the PostgreSQL category; --> psql's "FETCH_COUNT" feature is useful for incrementally displaying the results of a long-running query. However, psql fails to flush ...


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

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-18-2008, 11:15 AM
Neil Conway
 
Posts: n/a
Default psql: flush output in cursor-fetch mode

psql's "FETCH_COUNT" feature is useful for incrementally displaying the
results of a long-running query. However, psql fails to flush its output
stream as new rows from the partial result set are produced, which means
that partial query results may not be visible to the client until the
stdio buffer is eventually flushed or the query produces its complete
result set.

Example:

$ cat ~/test.sql
-- a contrived function to get a query that slowly produces
-- more rows
create function slow_func() returns boolean as
$$
begin
perform pg_sleep(2);
return true;
end;
$$ language plpgsql;

neilc=# \i ~/test.sql
CREATE FUNCTION
neilc=# create table t1 (a int, b int);
CREATE TABLE
neilc=# insert into t1 values (5, 10), (10, 15), (20, 25), (30, 35);
INSERT 0 4
neilc=# \set FETCH_COUNT 1
neilc=# select * from t1 where slow_func() is true;

With CVS HEAD, no output is visible until the complete result set has
been produced, at which point all 4 rows are printed. This is
undesirable: since the client has gone to the trouble of FETCH'ing the
rows one-at-a-time, it should display the partial result set before
issuing another FETCH.

Attached is a patch that fixes this, by calling fflush() on the psql
output stream after each call to printQuery() in ExecQueryUsingCursor().

-Neil



---------------------------(end of broadcast)---------------------------
TIP 3: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faq

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-18-2008, 11:15 AM
Neil Conway
 
Posts: n/a
Default Re: psql: flush output in cursor-fetch mode

On Wed, 2007-06-20 at 15:51 -0700, Neil Conway wrote:
> Attached is a patch that fixes this, by calling fflush() on the psql
> output stream after each call to printQuery() in ExecQueryUsingCursor().


Applied to HEAD.

-Neil



---------------------------(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
  #3 (permalink)  
Old 04-18-2008, 11:15 AM
Tom Lane
 
Posts: n/a
Default Re: psql: flush output in cursor-fetch mode

Neil Conway <neilc@samurai.com> writes:
> On Wed, 2007-06-20 at 15:51 -0700, Neil Conway wrote:
>> Attached is a patch that fixes this, by calling fflush() on the psql
>> output stream after each call to printQuery() in ExecQueryUsingCursor().


> Applied to HEAD.


Seems reasonable to back-patch into 8.2 too...

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-18-2008, 11:16 AM
Neil Conway
 
Posts: n/a
Default Re: psql: flush output in cursor-fetch mode

On Thu, 2007-21-06 at 22:09 -0400, Tom Lane wrote:
> Seems reasonable to back-patch into 8.2 too...


Okay, done.

-Neil



---------------------------(end of broadcast)---------------------------
TIP 2: Don't 'kill -9' the postmaster

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 05:26 PM.


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