Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dpHOx-0002nI-82 for pgsql-performance@arkaria.postgresql.org; Tue, 05 Sep 2017 17:12: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 1dpHOw-0007cw-B5 for pgsql-performance@arkaria.postgresql.org; Tue, 05 Sep 2017 17:12: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 1dpHOv-0007bv-3v for pgsql-performance@postgresql.org; Tue, 05 Sep 2017 17:12:37 +0000 Received: from resqmta-ch2-10v.sys.comcast.net ([2001:558:fe21:29:69:252:207:42]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1dpHOj-0003rS-IU for pgsql-performance@postgresql.org; Tue, 05 Sep 2017 17:12:35 +0000 Received: from resomta-ch2-01v.sys.comcast.net ([69.252.207.97]) by resqmta-ch2-10v.sys.comcast.net with ESMTP id pHKhd1LXEYw7OpHOgdbx8d; Tue, 05 Sep 2017 17:12:22 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=comcast.net; s=q20161114; t=1504631542; bh=awHM4TMmWuZIuQnQG719TDDmiqvYcyy0xFMxcdpSxaQ=; h=Received:Received:Subject:To:From:Message-ID:Date:MIME-Version: Content-Type; b=PwJka3uAU03Zes0u+B6w+l74kKURu3HuShz0gh1wN19YkXfMuYQCXb8e3Zu4M44Y1 i0SNGmUdKRwMJ0d0NcjwhXcSFJuckjpzBwvsfBZn3aWfx0ca/Pvg0qqneD97DMfChs 3uLaSrbdgK5nR0qpCxNhhMWjAnMd8qR24xSYPUi53GYRpogHer8wwRnXX7GT7ddnVo d0c48qoNXF7APUw7Qyu5nrM1SjeYcdehu9ywQ9Eq9Zy3PvXHxS4EV+rc6b/DOReiE5 8m7rkDJ4OJxgNofC+bMRPqXg9pzAg8Hj3weA5+cIlm5Pj4hZ6uUjw20L2ihshMePp7 rOFJsBAGQlvDQ== Received: from [192.168.0.3] ([73.68.146.26]) by resomta-ch2-01v.sys.comcast.net with SMTP id pHOfd2VL0J7dKpHOfd3dmV; Tue, 05 Sep 2017 17:12:22 +0000 Subject: Re: printing results of query to file in different times To: Mariel Cherkassky References: <634f2eb6-daf6-6314-e6f5-1b531b50a9ec@comcast.net> Cc: pgsql-performance@postgresql.org From: George Neuner Message-ID: <2d6aac29-0b20-1cd7-859e-4fc3a47f5477@comcast.net> Date: Tue, 5 Sep 2017 13:12:24 -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: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US X-CMAE-Envelope: MS4wfL7e1hmY2TM0k/U05488x+jo8tdX+0uw9q0q78J/ga8oGjT76SS+alEV1MFbFKtgmFTfd6q1JhVc9pzwhnBDKjY6DfuYmG6XtamXYExDZIbawUSqAq9A I1/UfOCrFyyyeIEEuZmzG6ErmRv05hk/lx48cHPaV0unyLnN71y8xf2w1/7+O7naxns1+Ibkb5IUmyC1GlajMS10sKltlfYo37tLq3KMBMHlpxqwSyItxC2W 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 Geez ... I just saw how my last message got mangled. Trying again. On 9/5/2017 7:28 AM, Mariel Cherkassky wrote: > I didn't understand what do you mean by REPEATABLE_READ. I was referring to transaction isolation levels.  When multiple transactions are running concurrently, the DBMS can (or not) prevent them from seeing changes made by one another.  Consider 2 transactions A and B running concurrently:   T1:   A reads table X   T2:   B writes to table X   T3:   B commits   T4:   A reads table X again. Depending on the isolation levels [and the specific query, obviously], A may or may not be able to see what changes B made to X. The default isolation level in Postgresql is READ COMMITTED, which does allow transactions to see committed writes made by concurrently running transactions.  REPEATABLE READ is a higher level of isolation which effectively takes a snapshot of the table(s) when they are 1st read, and guarantees that any further reads (e.g., by cursors) of the tables made by the transaction continue to see the same results. My thought was that your loop may be running slowly because the table is being changed underneath your cursor.  It may be better to pull the results into a temporary table and run your cursor loop over that. For more information, see: https://www.postgresql.org/docs/current/static/transaction-iso.html https://www.postgresql.org/docs/9.6/static/sql-begin.html https://stackoverflow.com/questions/6274457/set-isolation-level-for-postgresql-stored-procedures George -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance