Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dpdcF-0007vL-TT for pgsql-performance@arkaria.postgresql.org; Wed, 06 Sep 2017 16:55:52 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1dpdcE-0001wR-Uu for pgsql-performance@arkaria.postgresql.org; Wed, 06 Sep 2017 16:55:50 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1dpdcE-0001wH-9X for pgsql-performance@postgresql.org; Wed, 06 Sep 2017 16:55:50 +0000 Received: from resqmta-po-08v.sys.comcast.net ([2001:558:fe16:19:96:114:154:167]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1dpdc8-0005GK-Gt for pgsql-performance@postgresql.org; Wed, 06 Sep 2017 16:55:49 +0000 Received: from resomta-po-16v.sys.comcast.net ([96.114.154.240]) by resqmta-po-08v.sys.comcast.net with ESMTP id pdZhdaNpVbDE6pdbzd5GPH; Wed, 06 Sep 2017 16:55:35 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=comcast.net; s=q20161114; t=1504716935; bh=otdlMOBfsHjlBiAIKb6oigpzgrU92uRxuu4E/kiUHbY=; h=Received:Received:Subject:To:From:Message-ID:Date:MIME-Version: Content-Type; b=bDw0p5LchV6tHc9vOM/6Qx3WcLw4+y4KDCtCaGjGfkwWKD7ifIX0yyPcEdLVDgtLv 1NMQRbFlHptleU7rASgSqdbFySvwAmrIItw+QqI9ZAEEWbu0wjuJd55L+ddv13z62B NhyHjT9lIFI7LLlN1H69hQGpU6BWumUazZLjxmVu0CDcSBTQyAMKECkwHvG2eplWCt I8JDMQ293vDvw8rsl4976vTXfc5W1hdq+1jYK6fDArnuym4PyiZt1qkp1cIslUA3iF +zGwJeWQz0r8aCxd+EajKY+eN1+tusPqRJ88imLLSmNLc9599vwld8TL+7xkH9rt5I VG5TfmXIfHtgg== Received: from [192.168.0.67] ([73.68.146.26]) by resomta-po-16v.sys.comcast.net with SMTP id pdbydHLGSUw7LpdbzdTdBt; Wed, 06 Sep 2017 16:55:35 +0000 Subject: Re: printing results of query to file in different times To: Mariel Cherkassky References: <634f2eb6-daf6-6314-e6f5-1b531b50a9ec@comcast.net> <62fce205-db63-ed25-c726-d8c442f6223f@comcast.net> Cc: pgsql-performance@postgresql.org From: George Neuner Message-ID: Date: Wed, 6 Sep 2017 12:55:32 -0400 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/alternative; boundary="------------7B1DA5CFBDAFB0122E64207D" Content-Language: en-US X-CMAE-Envelope: MS4wfPqs2V/qUV9myIIXYFLceq62NLmkMZnjHbPUWfDjLS/TdHTXFgJHI/TzTzY87jKIq+0TlZOeQMEX6kIy/ftu/Q7hNTPN2AkLYKD6yzKQc3OChJOD9U5L 5wgV0zrrxfGpSWIHM2o9tFHh8IJ1grbUXSZmNonii83nRJjtZcZpJjpPI2L7wMrUu30GtWMa9TnUKqIwcqwxnFK8F4tvb+Bmeco8cdL1dy2X4AW2G+ja3bok 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 This is a multi-part message in MIME format. --------------7B1DA5CFBDAFB0122E64207D Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 8bit Hi Mariel, On 9/6/2017 4:38 AM, Mariel Cherkassky wrote: > I'm sure that those tables arent involved in any other transaction > when the loop is running. Anything else that I can check ? I think > that mybe its connected to some fetching properties but Im not > familiar with what settings.. That's the problem.  There are a lot of things that can affect query performance, but most of them _won't_ affect an open cursor unless isolation is low and the query's source tables are changing due to ongoing operations.  Each time the cursor is accessed, the query's source tables are checked for modifications, and if they have been changed, the cursor's query is re-executed ... potentially changing the result set. Not that it matters here, but you didn't show your actual query. Even if you are only fetching 100 rows, the query may be doing a lot of work (joins, sorts, etc.) to identify those rows.  If a complicated query is being executed over and over due to ongoing table modifications ...    That's why I suggested using a temporary table that you know won't be modified while the cursor is open on it - it's a way of side-stepping isolation issues that are beyond your control. If there really is no contention for the source tables, the only other possibilities are a badly over-loaded (or mis-configured) server, a problem with the storage system (e.g., a bad disk that is causing hiccups rather than outright failures), or some unknown issue with the extension you are using. I'm afraid I'm out of suggestions. George --------------7B1DA5CFBDAFB0122E64207D Content-Type: text/html; charset=windows-1252 Content-Transfer-Encoding: 8bit Hi Mariel,

On 9/6/2017 4:38 AM, Mariel Cherkassky wrote:
I'm sure that those tables arent involved in any other transaction when the loop is running. Anything else that I can check ? I think that mybe its connected to some fetching properties but Im not familiar with what settings..

That's the problem.  There are a lot of things that can affect query performance, but most of them won't affect an open cursor unless isolation is low and the query's source tables are changing due to ongoing operations.  Each time the cursor is accessed, the query's source tables are checked for modifications, and if they have been changed, the cursor's query is re-executed ... potentially changing the result set.

Not that it matters here, but you didn't show your actual query.  Even if you are only fetching 100 rows, the query may be doing a lot of work (joins, sorts, etc.) to identify those rows.  If a complicated query is being executed over and over due to ongoing table modifications ...    That's why I suggested using a temporary table that you know won't be modified while the cursor is open on it - it's a way of side-stepping isolation issues that are beyond your control.

If there really is no contention for the source tables, the only other possibilities are a badly over-loaded (or mis-configured) server, a problem with the storage system (e.g., a bad disk that is causing hiccups rather than outright failures), or some unknown issue with the extension you are using.

I'm afraid I'm out of suggestions.
George
--------------7B1DA5CFBDAFB0122E64207D--