Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1n9w5u-00076X-CR for pgsql-hackers@arkaria.postgresql.org; Tue, 18 Jan 2022 21:32:46 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1n9w5t-0003gk-0R for pgsql-hackers@arkaria.postgresql.org; Tue, 18 Jan 2022 21:32:45 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1n9w5s-0003gW-NS for pgsql-hackers@lists.postgresql.org; Tue, 18 Jan 2022 21:32:44 +0000 Received: from wout5-smtp.messagingengine.com ([64.147.123.21]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1n9w5m-00025U-Bu for pgsql-hackers@postgresql.org; Tue, 18 Jan 2022 21:32:44 +0000 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.west.internal (Postfix) with ESMTP id 6E58A32008FA; Tue, 18 Jan 2022 16:32:35 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Tue, 18 Jan 2022 16:32:36 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=anarazel.de; h= date:from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; s=fm3; bh=J81w7oqga9SGNQOo2wbkbDDqP5g WPSiVYl7TsJzt6tk=; b=DhQlPJKZwifqp24usuGTuOnGBf68j4Gf1PWi0xAoz0U LxJNGfWXrP3QIrkioJbBFI2bIBgjiybMIiog9lf2dTGqYpDlyUzGmNM1fE1wt48W 4uNDf71qeQoo+PUGmNFyDKt1hClxC85Kh8kqrUU7B0r2JH8aq5alqHWUFIg7tWc2 INIEMxOtEYxcW00J0edMS2tFZwwHwLxn2LdNZdxC+uKXqZDOKT49HowA67qLhgXj 7gPm29t+gOt0qHxCl/ZIiyrkkwnNGaoAyAHvLve44bopYDXmevraHfqBO0IBtlwY wwPW9xdrkToJZqYCiu4kIPCgGNAacOfhfNKEq6yOVgw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; bh=J81w7o qga9SGNQOo2wbkbDDqP5gWPSiVYl7TsJzt6tk=; b=j1X+tLTOHVywppnwJ1OWWa YWlrE6lBTnGDlc3b+D6z94Yu4P6S22yJ2PZnMXn90oKw18i4ILHviQTKVSRO5nGe zLSKIYwXsvbtrAIva8mN5hWfHfSktW6YGWbPSyYFQ/5OS4eOQ04frQzZW2lJr/1X au2p0lnHBH45D3SX0aaPL3glwudZZTZNkr+7sGoocbuTyXTWFd46TQHH/x1sdDtu V97WH22RqSN8Ljis1odS/OfaS7S4tR/mtEDDJkTrzXwiCoRAOkmTZ5bF09C4P/IJ E9kfX31ch82DYk745/cUpfqWpK6qA4Rr0KlFnvqYyR8OHvS9K2iUDB3ZCwsQb0Ww == X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvvddrudefgdduhedtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvffukfhfgggtuggjsehttdertddttddvnecuhfhrohhmpeetnhgurhgv shcuhfhrvghunhguuceorghnughrvghssegrnhgrrhgriigvlhdruggvqeenucggtffrrg htthgvrhhnpedukefhkeelueegveetheelffffjeegleeuudelfeefuedtleffueejfffh ueffudenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpe grnhgurhgvshesrghnrghrrgiivghlrdguvg X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 18 Jan 2022 16:32:34 -0500 (EST) Date: Tue, 18 Jan 2022 13:32:33 -0800 From: Andres Freund To: Alvaro Herrera Cc: James Coleman , pgsql-hackers Subject: Re: Add last commit LSN to pg_last_committed_xact() Message-ID: <20220118213233.43evzhdhz24b6l33@alap3.anarazel.de> References: <202201172134.ftvqmoyewxkg@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <202201172134.ftvqmoyewxkg@alvherre.pgsql> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, On 2022-01-17 18:34:16 -0300, Alvaro Herrera wrote: > Maybe it would work to have a single LSN in shared memory, as an atomic > variable, which uses monotonic advance[1] to be updated. That could be a reasonable approach. > Whether this is updated or not would depend on a new GUC, maybe > track_latest_commit_lsn. Causing performance pain during transaction commit > is not great, but at least this way it shouldn't be *too* a large hit. What kind of consistency are we expecting from this new bit of information? Does it have to be perfectly aligned with visibility? If so, it'd need to happen in ProcArrayEndTransaction(), with ProcArrayLock held - which I'd consider a complete no-go, that's way too contended. If it's "just" another piece of work happening "sometime around" transaction commit, it'd be a bit less concerning. I wonder if a very different approach could make sense here. Presumably this wouldn't need to be queried at a very high frequency, right? If so, what about storing the latest commit LSN for each backend in PGPROC? That could be maintained without a lock/atomics, and should be just about free. pg_last_committed_xact() then would have to iterate over all PGPROCs to complete the LSN, but that's not too bad for an operation like that. We'd also need to maintain a value for all disconnected backends, but that's also not a hot path. Greetings, Andres Freund