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 1rex4k-00EU4B-7r for pgsql-hackers@arkaria.postgresql.org; Tue, 27 Feb 2024 13:00:50 +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 1rex4h-002sNP-F9 for pgsql-hackers@arkaria.postgresql.org; Tue, 27 Feb 2024 13:00:47 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rex4g-002sNF-P8 for pgsql-hackers@lists.postgresql.org; Tue, 27 Feb 2024 13:00:47 +0000 Received: from mail-oa1-x2d.google.com ([2001:4860:4864:20::2d]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1rex4a-001V0C-4h for pgsql-hackers@lists.postgresql.org; Tue, 27 Feb 2024 13:00:45 +0000 Received: by mail-oa1-x2d.google.com with SMTP id 586e51a60fabf-2204e9290f9so128908fac.2 for ; Tue, 27 Feb 2024 05:00:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709038840; x=1709643640; darn=lists.postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=RPQ4fNMmKn84AEutioiHW5qwLXQlN4u2G+gLG8PP3IU=; b=RidhKT/JezznkVvxXX0cfkrejkCcddPaW4CzdfXuUf2SvYzZG6mxpVM4DSI7JlVDo0 qxcP0q7LGxxkVLuj+A98CgMhQrU9FEXvLUq+w8JH6vxRF551vArzdxNmUPygWo+ZcxWz ANopr8H+Sf1LCK7S6ouFS+KiwbDrlk9J7ZUWMzjDkm/PczwvDYnBDCuIv06wKXeLENQZ ruE+g/D11fRsx1QcuKDbWozXIiCQB+PjSSSh0CU/ermU/Fi2+rLOt9PbzeeAlqNwRq7w lzfLM5AUqWWtMF5sEynoeRZ1OvnAmQD0N5QJ0roDgaeihneuspF4tMuen1lSqsw1k8cf ElkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709038840; x=1709643640; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=RPQ4fNMmKn84AEutioiHW5qwLXQlN4u2G+gLG8PP3IU=; b=pcL0YGDA7m82OR8wtV/0JDxaw+KHLaZN9JQlmGVy1RgbdhJU8VLZZrSsSmkQTNr+ii LaY/lovqCYnLIiCfgYu9ZymnAuNZm/3ADQ3g72rWyQhtDsoWwcr8hBAgpVU/u+FInSgM HtszOYRI2OVwkR9PjfAI/herwQoI2QrR8+Ma9papXXT/YWf3koaRPtodlOkgA6755oL5 PRslwh4elfY7imprmJ0NCUTJouIKPgfwayTErmxHHGgaiLH+AlVBxwsG7s84XfWiVOTw WTPfLJrXqZcoZmRI93ClRaUjY9bTqFioRzAYhPfoWnjoh5MTF6pr2s9Tz+o6BwaHpJRK oEdg== X-Gm-Message-State: AOJu0YwVgEAS/mxiaPyAPd3u+IptTBE5pLFf75Qk2EDek9NjPTkPUreY qzbtCuG+E0s1VRDHC3T92/dE+0+t5uivbU/2xMH7B/91C3e4em5eB/kg1oiAqJYTlfQ9hzhSL8Z bHrPU/jphmBxCC5OL0oLAgH/PYj/k4981M3hCNw== X-Google-Smtp-Source: AGHT+IGJABIJRI4vT/WjHPX/kNkpHGs1SijjxylkDvCNfhKp6O1gAkwLFsyS3NomyTIUiIYW1XrThj1wHukt9tdb6k0= X-Received: by 2002:a05:6870:1856:b0:21f:d4d0:391f with SMTP id u22-20020a056870185600b0021fd4d0391fmr7950654oaf.15.1709038839549; Tue, 27 Feb 2024 05:00:39 -0800 (PST) MIME-Version: 1.0 References: <8fab8-65d74c80-1-2f28e880@39088166> <99df2-65d8d200-1-63c26880@172687752> In-Reply-To: From: Amit Kapila Date: Tue, 27 Feb 2024 18:30:28 +0530 Message-ID: Subject: Re: Slow catchup of 2PC (twophase) transactions on replica in LR To: =?UTF-8?B?0JTQsNCy0YvQtNC+0LIg0JLQuNGC0LDQu9C40Lk=?= Cc: pgsql-hackers@lists.postgresql.org 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 On Tue, Feb 27, 2024 at 4:49=E2=80=AFPM =D0=94=D0=B0=D0=B2=D1=8B=D0=B4=D0= =BE=D0=B2 =D0=92=D0=B8=D1=82=D0=B0=D0=BB=D0=B8=D0=B9 wrote: > > Thank you for your interest in the discussion! > > On Monday, February 26, 2024 16:24 MSK, Amit Kapila wrote: > > > I think the reason is probably that when the WAL record for prepared is a= lready flushed then what will be the idea of async commit here? > > I think, the idea of async commit should be applied for both transactions= : PREPARE and COMMIT PREPARED, which are actually two separate local transa= ctions. For both these transactions we may call XLogSetAsyncXactLSN on comm= it instead of XLogFlush when async commit is enabled. When I use async comm= it, I mean to apply async commit to local transactions, not to a twophase (= prepared) transaction itself. > > > At commit prepared, it seems we read prepare's WAL record, right? If so, = it is not clear to me do you see a problem with a flush of commit_prepared = or reading WAL for prepared or both of these. > > The problem with reading WAL is due to async commit of PREPARE TRANSACTIO= N which saves 2PC in the WAL. At the moment of COMMIT PREPARED the WAL with= PREPARE TRANSACTION 2PC state may not be XLogFlush-ed yet. > As we do XLogFlush() at the time of prepare then why it is not available? OR are you talking about this state after your idea/patch where you are trying to make both Prepare and Commit_prepared records async? So, PREPARE TRANSACTION should wait until its 2PC state is flushed. > > I did some experiments with saving 2PC state in the local memory of logic= al replication worker and, I think, it worked and demonstrated much better = performance. Logical replication worker utilized up to 100% CPU. I'm just c= oncerned about possible problems with async commit for twophase transaction= s. > > To be more specific, I've attached a patch to support async commit for tw= ophase. It is not the final patch but it is presented only for discussion p= urposes. There were some attempts to save 2PC in memory in past but it was = rejected. > It would be good if you could link those threads. --=20 With Regards, Amit Kapila.