Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id C0F331337B43 for ; Mon, 18 Apr 2011 16:41:29 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 67003-07 for ; Mon, 18 Apr 2011 19:41:21 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by mail.postgresql.org (Postfix) with ESMTP id 5D305133740B for ; Mon, 18 Apr 2011 16:41:20 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.2/8.14.2) with ESMTP id p3IJfJXp015056; Mon, 18 Apr 2011 15:41:19 -0400 (EDT) To: John Rouillard cc: "pgsql-performance@postgresql.org" Subject: Re: Assessing performance of fetches In-reply-to: <20110418181241.GF27218@renesys.com> References: <20110418181241.GF27218@renesys.com> Comments: In-reply-to John Rouillard message dated "Mon, 18 Apr 2011 18:12:41 -0000" Date: Mon, 18 Apr 2011 15:41:19 -0400 Message-ID: <15055.1303155679@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.91 tagged_above=-10 required=5 tests=BAYES_00=-1.9, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201104/255 X-Sequence-Number: 43317 John Rouillard writes: > I am seeing: > 2011-04-16 00:55:33 UTC user@database(3516): LOG: duration: > 371954.811 ms statement: FETCH FORWARD 1 FROM c_2aaaaaaeea50_a08 > While I obviously have a problem here, is there any way to log the > actual select associated with the cursor other than logging all > statements? Can't think of one :-( > Also once I have the select statement, does the fact that is is > associated with a fetch/cursor change the steps I should take in > tuning it compared to somebody just issuing a normal select? The planner does treat cursor queries a bit different from plain queries, putting more emphasis on getting the first rows sooner. If you want to be sure you're getting the truth about what's happening, try EXPLAIN [ANALYZE] DECLARE c CURSOR FOR SELECT ... rather than just EXPLAIN [ANALYZE] SELECT ... Other than that, it's the same as tuning a regular query. regards, tom lane