Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rSQf7-00DiAg-5J for pgsql-hackers@arkaria.postgresql.org; Tue, 23 Jan 2024 23:58:37 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1rSQf6-000JBY-1Z for pgsql-hackers@arkaria.postgresql.org; Tue, 23 Jan 2024 23:58:36 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rSQf5-000JBQ-Mi for pgsql-hackers@lists.postgresql.org; Tue, 23 Jan 2024 23:58:35 +0000 Received: from out5-smtp.messagingengine.com ([66.111.4.29]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rSQf2-003NYg-Sh for pgsql-hackers@lists.postgresql.org; Tue, 23 Jan 2024 23:58:35 +0000 Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id D5A585C0167; Tue, 23 Jan 2024 18:58:31 -0500 (EST) Received: from imap49 ([10.202.2.99]) by compute2.internal (MEProxy); Tue, 23 Jan 2024 18:58:31 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=eulerto.com; h= cc:cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm1; t=1706054311; x=1706140711; bh=McjfIa27Us N95EBfwFHTSkbHC+Dd/dWCAZeVkrX7oYQ=; b=b33ZxPwP6QLjEE7Pvqlb3NyPF8 kvMLeMpvnMrzPVpLYbExI/k0ZyLZtO+oCnyMKovVJn4g3SQb8+yZ2OwromRxhJXJ zs4BVWnV4mfIH3G26vw2Pqq3CiLcMaDOcxzuojKFJo2aZlSGHdqRYfvoERgvZIra LEFRDL2D72nnLr6sG8aB2rT/pwLxjBUD0SCvqbb6ysC8HdKt1mFFMGV9lHcDBrD3 BuYjdXRoOcYS0N4rDUZGTbY9UWRQcRwLIkWF9kBl40gw+5okV9Y2f1xdCtuhvI8s YxrI2SbK/Rl/A+V/fZd9l4SymAeZyxQnRzuLELHOShJq6G+k9a1jIAwm+c7w== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1706054311; x=1706140711; bh=McjfIa27UsN95EBfwFHTSkbHC+Dd /dWCAZeVkrX7oYQ=; b=nQf4PZiFIuKuD0OljJaguPbjZ0oQg43/KtHYdc3SceoR fRO/PHtV0Y+iYj+SB38ej7liTEgzb4KcxZKd+hvgk+1OBHTt5saaeIbEghi8Gi1j O7MaSHy+LFPUWpEwv2eir6PqSrWb+eiLKeA+Q94WMpmsvmHbMfmVz7FGLWJGcsn1 6HMBFLBdQuxeAlVY/Ds5wghfI4R59THi2eSaGMILER3qs2u+GzSJZWx/HqBJwT1R KFiwbF7EYJ9/v3JfOP0cQZ7eQ/iJ82n7Xj0LI2k7La+3hCQsHR78w+RAFH5+3UEA jlOGRMCyWIV6lJMjchLwEl0G5KIJY/obeRLhKoa4EQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvkedrvdekledgudeiucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepofgfggfkjghffffhvfevufgtsegrtderreerredtnecuhfhrohhmpedfgfhu lhgvrhcuvfgrvhgvihhrrgdfuceovghulhgvrhesvghulhgvrhhtohdrtghomheqnecugg ftrfgrthhtvghrnhepgfffjedviedvkedviedvteduieekudeivedthffhuddvteegleet ieffkeeghfdvnecuffhomhgrihhnpegvnhhtvghrphhrihhsvggusgdrtghomhenucevlh hushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegvuhhlvghrsegv uhhlvghrthhordgtohhm X-ME-Proxy: Feedback-ID: i0c21471d:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id 546C515A0092; Tue, 23 Jan 2024 18:58:31 -0500 (EST) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.11.0-alpha0-119-ga8b98d1bd8-fm-20240108.001-ga8b98d1b MIME-Version: 1.0 Message-Id: <73ab86ca-3fd5-49b3-9c80-73d1525202f1@app.fastmail.com> In-Reply-To: References: <5ac50071-f2ed-4ace-a8fd-b892cffd33eb@www.fastmail.com> <4710d895-689a-4ae6-b8e3-344286dbf970@app.fastmail.com> <96e3b739-d63d-4d35-90a3-7869465b7167@eisentraut.org> <2736443c-58e3-42df-8cc4-8c66106e3da5@app.fastmail.com> Date: Tue, 23 Jan 2024 20:58:11 -0300 From: "Euler Taveira" To: "kuroda.hayato@fujitsu.com" , "'pgsql-hackers@lists.postgresql.org'" Cc: "Shlok Kyal" , "vignesh C" , "Michael Paquier" , "Peter Eisentraut" , "Andres Freund" , "Ashutosh Bapat" , "Amit Kapila" Subject: Re: speed up a logical replica setup Content-Type: multipart/alternative; boundary=c9fe0cd53eb642539bb3099448c25018 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --c9fe0cd53eb642539bb3099448c25018 Content-Type: text/plain On Mon, Jan 22, 2024, at 4:06 AM, Hayato Kuroda (Fujitsu) wrote: > I analyzed and found a reason. This is because publications are invisible for some transactions. > > As the first place, below operations were executed in this case. > Tuples were inserted after getting consistent_lsn, but before starting the standby. > After doing the workload, I confirmed again that the publication was created. > > 1. on primary, logical replication slots were created. > 2. on primary, another replication slot was created. > 3. ===on primary, some tuples were inserted. === > 4. on standby, a server process was started > 5. on standby, the process waited until all changes have come. > 6. on primary, publications were created. > 7. on standby, subscriptions were created. > 8. on standby, a replication progress for each subscriptions was set to given LSN (got at step2). > =====pg_subscriber finished here===== > 9. on standby, a server process was started again > 10. on standby, subscriptions were enabled. They referred slots created at step1. > 11. on primary, decoding was started but ERROR was raised. Good catch! It is a design flaw. > In this case, tuples were inserted *before creating publication*. > So I thought that the decoded transaction could not see the publication because > it was committed after insertions. > > One solution is to create a publication before creating a consistent slot. > Changes which came before creating the slot were surely replicated to the standby, > so upcoming transactions can see the object. We are planning to patch set to fix > the issue in this approach. I'll include a similar code in the next patch and also explain why we should create the publication earlier. (I'm renaming create_all_logical_replication_slots to setup_publisher and calling create_publication from there and also adding the proposed GUC checks in it.) -- Euler Taveira EDB https://www.enterprisedb.com/ --c9fe0cd53eb642539bb3099448c25018 Content-Type: text/html Content-Transfer-Encoding: quoted-printable
On Mon, Jan 22,= 2024, at 4:06 AM, Hayato Kuroda (Fujitsu) wrote:
I analyzed and found a reason. Th= is is because publications are invisible for some transactions.

As the first place, below operations were executed = in this case.
Tuples were inserted after getting consisten= t_lsn, but before starting the standby.
After doing the wo= rkload, I confirmed again that the publication was created.

1. on primary, logical replication slots were created.<= br>
2. on primary, another replication slot was created.
3. =3D=3D=3Don primary, some tuples were inserted. =3D=3D=3D
4. on standby, a server process was started
5.= on standby, the process waited until all changes have come.
6. on primary, publications were created.
7. on standby= , subscriptions were created.
8. on standby, a replication= progress for each subscriptions was set to given LSN (got at step2).
=3D=3D=3D=3D=3Dpg_subscriber finished here=3D=3D=3D=3D=3D
9. on standby, a server process was started again
<= div>10. on standby, subscriptions were enabled. They referred slots crea= ted at step1.
11. on primary, decoding was started but ERR= OR was raised.

Good catch! It = is a design flaw.

In this case, tuples were inserted *before creating pu= blication*.
So I thought that the decoded transaction coul= d not see the publication because
it was committed after i= nsertions.

One solution is to create a publ= ication before creating a consistent slot.
Changes which c= ame before creating the slot were surely replicated to the standby,
<= /div>
so upcoming transactions can see the object. We are planning t= o patch set to fix
the issue in this approach.

I'll include a similar code in the next p= atch and also explain why we should
create the publication= earlier. (I'm renaming
create_all_logical_replication_slo= ts to setup_publisher and calling
create_publication from = there and also adding the proposed GUC checks in it.)

=

-= -
Euler Taveira

--c9fe0cd53eb642539bb3099448c25018--