Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ea2J1-00059G-R0 for pgsql-hackers@arkaria.postgresql.org; Fri, 12 Jan 2018 16:35:47 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ea2J1-0008HL-31 for pgsql-hackers@arkaria.postgresql.org; Fri, 12 Jan 2018 16:35:47 +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 1ea2J0-0008H2-Ow for pgsql-hackers@lists.postgresql.org; Fri, 12 Jan 2018 16:35:46 +0000 Received: from out3-smtp.messagingengine.com ([66.111.4.27]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1ea2Ix-0007mm-Mp for pgsql-hackers@postgresql.org; Fri, 12 Jan 2018 16:35:45 +0000 Received: from compute7.internal (compute7.nyi.internal [10.202.2.47]) by mailout.nyi.internal (Postfix) with ESMTP id 54D1020C3D; Fri, 12 Jan 2018 11:35:42 -0500 (EST) Received: from frontend1 ([10.202.2.160]) by compute7.internal (MEProxy); Fri, 12 Jan 2018 11:35:42 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; bh=LRivPx VZfDIlm8w+znKclC8VenfWf6NGOp9PN1s6cgA=; b=Mh+wmBLvOpONI+fdpVq8T3 2W8UhslO+2wiTB/fJozvqphd9Rq9UuO0Zs1d6aunv6j7kYD2Qcu0SEM5ZoY8/kT/ MaIW8V1/hhe3+cQalGu5dKbHVFSVLqQPT9RgHKyxUDDIIENSvou5sjtYvziN7KZR OQMknL6fJKT/GwXoxTDrf6FtitjfY2blhYk0nWcBUg2ZCmJvMM0wd+I/meWPu64L /WntU8Am1bIP7oZAGrHJ23tNci7qQ293ZyjayodJt7bLi1KmQbQqg1+mIVrPvFJH lBPKBC4WnsXj4xhsYczZ7LOXRcXsLhPSEQB9hrh00hSrcuk6kViBj9QOiQvPD0Kw == X-ME-Sender: Received: from april.local (c-73-13-66-39.hsd1.pa.comcast.net [73.13.66.39]) by mail.messagingengine.com (Postfix) with ESMTPA id 0F7337E16A; Fri, 12 Jan 2018 11:35:42 -0500 (EST) Subject: Re: PATCH: logical_work_mem and logical streaming of large in-progress transactions To: Greg Stark References: <688b0b7f-2f6c-d827-c27b-216a8e3ea700@2ndquadrant.com> Cc: Tomas Vondra , PostgreSQL Hackers From: Peter Eisentraut Organization: 2ndQuadrant Message-ID: <5d00346a-b565-7fde-c6da-35f39c72936a@2ndquadrant.com> Date: Fri, 12 Jan 2018 11:35:41 -0500 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:52.0) Gecko/20100101 Thunderbird/52.5.2 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 1/11/18 18:23, Greg Stark wrote: > AIUI spilling to disk doesn't affect absorbing future updates, we > would just keep accumulating them in memory right? We won't need to > unspill until it comes time to commit. Once a transaction has been serialized, future updates keep accumulating in memory, until perhaps it gets serialized again. But then at commit time, if a transaction has been partially serialized at all, all the remaining changes are also serialized before the whole thing is read back in (see reorderbuffer.c line 855). So one optimization would be to specially keep track of all transactions that have been serialized already and pick those first for further serialization, because it will be done eventually anyway. But this is only a secondary optimization, because it doesn't help in the extreme cases that either no (or few) transactions have been serialized or all (or most) transactions have been serialized. > The real aim should be to try to pick the transaction that will be > committed furthest in the future. That gives you the most memory to > use for live transactions for the longest time and could let you > process the maximum amount of transactions without spilling them. So > either the oldest transaction (in the expectation that it's been open > a while and appears to be a long-lived batch job that will stay open > for a long time) or the youngest transaction (in the expectation that > all transactions are more or less equally long-lived) might make > sense. Yes, that makes sense. We'd still need to keep a separate ordered list of transactions somewhere, but that might be easier if we just order them in the order we see them. -- Peter Eisentraut http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services