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 1mpv5p-0002c2-7O for pgsql-hackers@arkaria.postgresql.org; Wed, 24 Nov 2021 16:25:57 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mpv5o-0001sb-5H for pgsql-hackers@arkaria.postgresql.org; Wed, 24 Nov 2021 16:25:56 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mpv5n-0001sS-9x for pgsql-hackers@lists.postgresql.org; Wed, 24 Nov 2021 16:25:55 +0000 Received: from out5-smtp.messagingengine.com ([66.111.4.29]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mpv5k-00084m-5o for pgsql-hackers@postgresql.org; Wed, 24 Nov 2021 16:25:54 +0000 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.nyi.internal (Postfix) with ESMTP id AD3785C01EC; Wed, 24 Nov 2021 11:25:50 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute3.internal (MEProxy); Wed, 24 Nov 2021 11:25:50 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tapoueh.org; h= from:to:cc:subject:references:date:in-reply-to:message-id :mime-version:content-type:content-transfer-encoding; s=mesmtp; bh=2sZgZIal7mM4Y61BeuGes89sJByQAbWXHGuQy/hEd2E=; b=U46/VjSAJzF6 Ll7LKD+IvdaIEDLuVgeSj2VpAOyVtUDWKSjguVAeB6s74ao9CmhF+ReBcbPw2neo dRAApdtmtrZa7mjvJbqJ8AsO7e2dRfYgU0bmS6mrWUlw+dNrRh+5yFD2bxa3qMmF Z5KmvcGPkS5+u5hpbxcqGKfznmSD58w= 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-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm1; bh=2sZgZIal7mM4Y61BeuGes89sJByQAbWXHGuQy/hEd 2E=; b=hmEq7L4pJOldJSNYWi1lB0lfP0IntISUbb0CZ3R0eMb0Oui52KRNHWoV/ 0pYeZNa4dSylMWcj9hQL1MWUGlRMa9jJgqSldY1GxMjziCESOg21hPxbivTxBhP4 ddBQ5azAqK9OiQnVw2GRAPzUafvb0JfC6wPn7ctV/N+riv9vh0w+AjuktkfVI2jm JPHlAxw875MPcJ38w1roapYZguwYYklIROuKMd0AmTn/hyNnuk+WsxuxweVYxYYL fkpt1SPIUIdqMELxAQXO3Fvbf0HGw7Lghan1hPfv5VBOI5mL+iED7EgCiGGrcS4J B7xiQ7lKTriALfIYcqzHxLGm2F7FQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvuddrgeekgdeltdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefhvffufhffjgfkfgggtgfgsehtqhertddtreejnecuhfhrohhmpeffihhmihht rhhiucfhohhnthgrihhnvgcuoeguihhmsehtrghpohhuvghhrdhorhhgqeenucggtffrrg htthgvrhhnpeduheeugedtieduhfdtffffleelheefffdvieehheeulefhffevfeeileet fedufeenucffohhmrghinhepthhhvggrrhhtohhfphhoshhtghhrvghsqhhlrdgtohhmpd hgihhthhhusgdrtghomhenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgr ihhlfhhrohhmpeguihhmsehtrghpohhuvghhrdhorhhg X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 24 Nov 2021 11:25:49 -0500 (EST) From: Dimitri Fontaine To: Peter Eisentraut Cc: pgsql-hackers Subject: Re: Synchronizing slots from primary to standby References: <514f6f2f-6833-4539-39f1-96cd1e011f23@enterprisedb.com> User-Mail-Address: dim@tapoueh.org Date: Wed, 24 Nov 2021 17:25:47 +0100 In-Reply-To: <514f6f2f-6833-4539-39f1-96cd1e011f23@enterprisedb.com> (Peter Eisentraut's message of "Sun, 31 Oct 2021 11:08:18 +0100") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (darwin) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi all, Peter Eisentraut writes: > I want to reactivate $subject. I took Petr Jelinek's patch from [0], > rebased it, added a bit of testing. It basically works, but as=20 > mentioned in [0], there are various issues to work out. Thanks for working on that topic, I believe it's an important part of Postgres' HA story. > The idea is that the standby runs a background worker to periodically fet= ch > replication slot information from the primary. On failover, a logical > subscriber would then ideally find up-to-date replication slots on the new > publisher and can just continue normally. Is there a case to be made about doing the same thing for physical replication slots too? That's what pg_auto_failover [1] does by default: it creates replication slots on every node for every other node, in a way that a standby Postgres instance now maintains a replication slot for the primary. This ensures that after a promotion, the standby knows to retain any and all WAL segments that the primary might need when rejoining, at pg_rewind time. > The previous thread didn't have a lot of discussion, but I have gathered > from off-line conversations that there is a wider agreement on this=20 > approach. So the next steps would be to make it more robust and > configurable and documented. I suppose part of the configuration would then include taking care of physical slots. Some people might want to turn that off and use the Postgres 13+ ability to use the remote primary restore_command to fetch missing WAL files, instead. Well, people who have setup an archiving system, anyway. > As I said, I added a small test case to=20 > show that it works at all, but I think a lot more tests should be added. = I > have also found that this breaks some seemingly unrelated tests in the > recovery test suite. I have disabled these here. I'm not sure if the pa= tch > actually breaks anything or if these are just differences in timing or > implementation dependencies. This patch adds a LIST_SLOTS replication > command, but I think this could be replaced with just a SELECT FROM > pg_replication_slots query now. (This patch is originally older than when > you could run SELECT queries over the replication protocol.) Given the admitted state of the patch, I didn't focus on tests. I could successfully apply the patch on-top of current master's branch, and cleanly compile and `make check`. Then I also updated pg_auto_failover to support Postgres 15devel [2] so that I could then `make NODES=3D3 cluster` there and play with the new replication command: $ psql -d "port=3D5501 replication=3D1" -c "LIST_SLOTS;" psql:/Users/dim/.psqlrc:24: ERROR: XX000: cannot execute SQL commands in= WAL sender for physical replication LOCATION: exec_replication_command, walsender.c:1830 ... I'm not too sure about this idea of running SQL in a replication protocol connection that you're mentioning, but I suppose that's just me needing to brush up on the topic. > So, again, this isn't anywhere near ready, but there is already a lot here > to gather feedback about how it works, how it should work, how to configu= re > it, and how it fits into an overall replication and HA architecture. Maybe the first question about configuration would be about selecting which slots a standby should maintain from the primary. Is it all of the slots that exists on both the nodes, or a sublist of that? Is it possible to have a slot with the same name on a primary and a standby node, in a way that the standby's slot would be a completely separate entity from the primary's slot? If yes (I just don't know at the moment), well then, should we continue to allow that? Other aspects of the configuration might include a list of databases in which to make the new background worker active, and the polling delay, etc. Also, do we want to even consider having the slot management on a primary node depend on the ability to sync the advancing on one or more standby nodes? I'm not sure to see that one as a good idea, but maybe we want to kill it publically very early then ;-) Regards, --=20 dim Author of =E2=80=9CThe Art of PostgreSQL=E2=80=9D, see https://theartofpost= gresql.com [1]: https://github.com/citusdata/pg_auto_failover [2]: https://github.com/citusdata/pg_auto_failover/pull/838