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 1lULdh-0007Qb-6t for pgsql-hackers@arkaria.postgresql.org; Thu, 08 Apr 2021 03:47:29 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lULdd-0004Tt-Ju for pgsql-hackers@arkaria.postgresql.org; Thu, 08 Apr 2021 03:47:25 +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 1lULdc-0004Tm-MQ for pgsql-hackers@lists.postgresql.org; Thu, 08 Apr 2021 03:47:25 +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 1lULdX-0000m9-HT for pgsql-hackers@postgresql.org; Thu, 08 Apr 2021 03:47:24 +0000 Received: from compute7.internal (compute7.nyi.internal [10.202.2.47]) by mailout.west.internal (Postfix) with ESMTP id 02FB4177A; Wed, 7 Apr 2021 23:47:15 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute7.internal (MEProxy); Wed, 07 Apr 2021 23:47:16 -0400 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=fm1; bh=xxuE7z88C0RygCPuIGtaIJIAcZc pptEF/2lQ8O3HdZ4=; b=SWo9ZSc7iF96aZYokDVk+WA/56CQWOTAJUOzcbGfwkW XTxeU/NE7TetgKJt8KTTHNA0z9Yp7rpsrayWgVeLdj1E0vJRYTPsBidaHPA7ZLtR UzfH0mTcHtJOQLnAmX4iraSXgJ72pUYOMZy+19+Tnui9SKfEUGNfxzCZaEVCHrfR J/y+psBzKApOaP9BECf+CV0aWBq8pVbn49Aw3tTPJ783+qtBW9CndqlENYyp8FtP vl+SqzkcPUixh8XL21oSxux5ZlFfBWFfwqZRF+/NcxRTECSbEbzTolZHX/oU6nxG Uom7BA59FCvPxALKQQG1D6UNeqeor7niW6cHqOhWYrg== 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=fm2; bh=xxuE7z 88C0RygCPuIGtaIJIAcZcpptEF/2lQ8O3HdZ4=; b=kPyAgbcMH/xon5TtnE6FBR zoHD54tfqM05XtSz7dw1xP4fSzSS829jRkfdzD4N/usbQMraxgGD5gXMAzIZmzeh SgVc8y5jdkdOovn/egT5ohq1gLKvP195Z0YbbSsWUH6vswe8ds+HZOBDsYojPuc3 5lyPxylsdbLCxIg8TmoHLpNEKkQCQfHp6nEu1AsYbr+1Ef3DfudFHkfLJbBroJw7 FPYLAL2EeWVw6MgtsbHxyecFsDdtJBGno2YmOb4+D/iywYPjBJQpL1fmDvSF8KPr 5X6Xq84Qd0F/x80as8wHgSyZCqogXN3dub+4O0b2B2HiTW5zSdFfrSjMWSAarjsw == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrudejkedgjeehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvffukfhfgggtuggjsehttdertddttddvnecuhfhrohhmpeetnhgurhgv shcuhfhrvghunhguuceorghnughrvghssegrnhgrrhgriigvlhdruggvqeenucggtffrrg htthgvrhhnpeetheehiefgudelhfevvddvtdejheehkeelteekveeggeduieelieduuefg fedtjeenucffohhmrghinhepphhoshhtghhrvghsqhhlrdhorhhgnecukfhppedutdejrd dugedvrdeffedruddtfeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgr ihhlfhhrohhmpegrnhgurhgvshesrghnrghrrgiivghlrdguvg X-ME-Proxy: Received: from intern.anarazel.de (107-142-33-103.lightspeed.sntcca.sbcglobal.net [107.142.33.103]) by mail.messagingengine.com (Postfix) with ESMTPA id 0A6F6108005F; Wed, 7 Apr 2021 23:47:15 -0400 (EDT) Date: Wed, 7 Apr 2021 20:47:13 -0700 From: Andres Freund To: "Drouvot, Bertrand" Cc: fabriziomello@gmail.com, Alvaro Herrera , tushar , "[pgdg] Robert Haas" , Amit Khandekar , Rahila Syed , pgsql-hackers Subject: Re: Minimal logical decoding on standbys Message-ID: <20210408034713.auf7oaxyymu2kc7n@alap3.anarazel.de> References: <96644a03-0b4d-e0a6-2124-0bc37e5b54fb@amazon.com> <842d60ce-99e6-f35e-8c92-0cd49381326e@amazon.com> <6b9168e5-6a29-7fda-8903-cd50563fa84c@amazon.com> <20210406180231.qsnkyrgrm7gtxb73@alap3.anarazel.de> <20210407170954.xbovgh3xdrnogg7w@alap3.anarazel.de> <20210407203218.pestfxu7watrnog4@alap3.anarazel.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210407203218.pestfxu7watrnog4@alap3.anarazel.de> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, On 2021-04-07 13:32:18 -0700, Andres Freund wrote: > While working on this I found a, somewhat substantial, issue: > > When the primary is idle, on the standby logical decoding via walsender > will typically not process the records until further WAL writes come in > from the primary, or until a 10s lapsed. > > The problem is that WalSndWaitForWal() waits for the *replay* LSN to > increase, but gets woken up by walreceiver when new WAL has been > flushed. Which means that typically walsenders will get woken up at the > same time that the startup process will be - which means that by the > time the logical walsender checks GetXLogReplayRecPtr() it's unlikely > that the startup process already replayed the record and updated > XLogCtl->lastReplayedEndRecPtr. > > I think fixing this would require too invasive changes at this point. I > think we might be able to live with 10s delay issue for one release, but > it sure is ugly :(. This is indeed pretty painful. It's a lot more regularly occuring if you either have a slot disk, or you switch around the order of WakeupRecovery() and WalSndWakeup() XLogWalRcvFlush(). - There's about which timeline to use. If you use pg_recvlogical and you restart the server, you'll see errors like: pg_recvlogical: error: unexpected termination of replication stream: ERROR: requested WAL segment 000000000000000000000003 has already been removed the real filename is 000000010000000000000003 - i.e. the timeline is 0. This isn't too hard to fix, but definitely needs fixing. - ResolveRecoveryConflictWithLogicalSlots() is racy - potentially leading us to drop a slot that has been created since we signalled a recovery conflict. See https://www.postgresql.org/message-id/20210408020913.zzprrlvqyvlt5cyy%40alap3.anarazel.de for some very similar issues. - Given the precedent of max_slot_wal_keep_size, I think it's wrong to just drop the logical slots. Instead we should just mark them as invalid, like InvalidateObsoleteReplicationSlots(). - There's no tests covering timeline switches, what happens if there's a promotion if logical decoding is currently ongoing. - The way ResolveRecoveryConflictWithLogicalSlots() builds the error message is not good (and I've complained about it before...). Unfortunately I think the things I have found are too many for me to address within the given time. I'll send a version with a somewhat polished set of the changes I made in the next few days... Greetings, Andres Freund