Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cf94l-0000iS-PH for pgsql-performance@arkaria.postgresql.org; Sat, 18 Feb 2017 17:45:39 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1cf94k-0001Uw-Hx for pgsql-performance@arkaria.postgresql.org; Sat, 18 Feb 2017 17:45:38 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1cf934-0007v6-0c for pgsql-performance@postgresql.org; Sat, 18 Feb 2017 17:43:54 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1cf931-0003if-F8 for pgsql-performance@postgresql.org; Sat, 18 Feb 2017 17:43:52 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id v1IHhn0a026740; Sat, 18 Feb 2017 12:43:49 -0500 From: Tom Lane To: Mike Beaton cc: pgsql-performance@postgresql.org Subject: Re: Correct use of cursors for very large result sets in Postgres In-reply-to: References: <21063.1487349580@sss.pgh.pa.us> Comments: In-reply-to Mike Beaton message dated "Sat, 18 Feb 2017 07:57:10 +0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <26738.1487439829.1@sss.pgh.pa.us> Date: Sat, 18 Feb 2017 12:43:49 -0500 Message-ID: <26739.1487439829@sss.pgh.pa.us> X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-performance Precedence: bulk Sender: pgsql-performance-owner@postgresql.org Mike Beaton writes: > One outstanding question I have. Based on a lot of helpful responses given > to the SO question I can now test and see what disk buffers are generated > (by setting `log_temp_files` to `0` and then `tail -f log`), as well as how > long it takes for results to start arriving. > With a large (10,000,000 row) test table, if I do `SELECT * FROM table` on > psql it starts to return results immediately with no disk buffer. If I do > `FETCH ALL FROM cursortotable` on psql it takes about 7.5 seconds to start > returning results, and generates a 14MB buffer. If I do `SELECT * FROM > table` on a correctly coded streaming client, it also starts to return > results immediately with no disk buffer. But if I do `FETCH ALL FROM > cursortotable` from my streaming client, it takes about 1.5 seconds for > results to start coming... but again with no disk buffer, as hoped Seems odd. Is your cursor just on "SELECT * FROM table", or is there some processing in there you're not mentioning? Maybe it's a cursor WITH HOLD and you're exiting the source transaction? regards, tom lane -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance