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 1ulMGY-00E1r6-Nk for pgsql-hackers@arkaria.postgresql.org; Mon, 11 Aug 2025 06:44:18 +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 1ulMGX-00AQQV-7p for pgsql-hackers@arkaria.postgresql.org; Mon, 11 Aug 2025 06:44:17 +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 1ulMGW-00AQQG-UV for pgsql-hackers@lists.postgresql.org; Mon, 11 Aug 2025 06:44:16 +0000 Received: from mail-lf1-x12c.google.com ([2a00:1450:4864:20::12c]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1ulMGU-001pln-0H for pgsql-hackers@lists.postgresql.org; Mon, 11 Aug 2025 06:44:16 +0000 Received: by mail-lf1-x12c.google.com with SMTP id 2adb3069b0e04-55b9855f671so3457759e87.0 for ; Sun, 10 Aug 2025 23:44:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1754894653; x=1755499453; 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=mmoUQEMZ/dEekl29lCTeSWc06VMReGw0Qe/Aj9Iw2ME=; b=LYA+JUuVm6o5rxaZj7+95ydUlMHU84TrZvhZGn62xW5SM1y71INeJi5543MI03wIai vY3e+sWtaijx59GdA0/apW29wfAMft5aklor8qh0NNuj6Lf7hAOm7nPwWa3qtztPvmXJ NwQKuasrla9Bh+qjJ7uXGeWORDqzjo7tJIAsq6Jednb7G7MB//9qfTvpFsLJjnYjTwCH QqWsszno7S3RuZviLExKcrpRFAAhPt2fwR7YeIclK2VxC2E7LfwW+oPhBhQ6c4s36SGF uTi3/X+LoeiT471HtohY6bpfKdp1Mi0tkKtpMGMv+rndyWeTp/JJ3OWoTzd7nu0+HU8k pFCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1754894653; x=1755499453; 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=mmoUQEMZ/dEekl29lCTeSWc06VMReGw0Qe/Aj9Iw2ME=; b=Rd0tME+V28vl1/cCV3HaT8oZJlczZH5Q4O73fCeXPnD94DMhaMNtuUGa7G/a9hOw6G zVCAO08XJF9XpXV3Fc2vmhgb3yhhI8teR1Jg6ytgwtMzNGhQCt8WTJBDmZmvsmV5eh2y ygsoBYjUp67j/WZwYQl6xXLcNo9S0A2IlkKFzB5ujcMIdYlawavpggCgEL3nISz7Sdt4 ZUgrsmAMazIFmy3zaJvOt8CMfdKnjTKFPAeuMrvCWUpFD+N+0c72cDZtB4KRDygNgVvV alEhQsYjLEeub45TgKOcIxzgHEKpNLR84cl+85hdJpqPDWhi63rd7XSYlHhkz5503qgV MHAQ== X-Forwarded-Encrypted: i=1; AJvYcCV6QIcVzPfm9/t8tlOmofb+vGRg93I9YpeatNQNwl1oj7hkso/jRosBKlxId7bBf4VOSus1ec+VtgwS5cw0@lists.postgresql.org X-Gm-Message-State: AOJu0YznCgtgNTJ6rIkzuHEUp2lf6+A/ao4St5BC9EBCpeTIHKlRUnOj ZfriyZVbW4B8cMMGxEQC04tBB56Zt/df/+u+I+QgJThGzFNKokW7rGD99IAiKD9qwOEgsLDkzmr 3btjAW2JFG7ZMLNMWTPaVeq71W4iWeINl+EBjgQo= X-Gm-Gg: ASbGncsidqkp5yUugLP/mFNTAaes1ZU8x78Rb8Qy/wDOrZxzaoP6ruVBqiz5hAQgusP DsJBAtJKg583vZwbqBk3JqGSVxHKQ8dJPXyRjGXnLswndbltEui1jkXDKaQNN5IHb4PJKTtSo/m zg4/7tb5W+JMDdxqayfwxp/j9Fb7QbNtwSvdJATb04eLb+4is8C2MDCl0nuX3hMRPUEJE3Y1Zmz tkDiR6wPzeN/gZ3IpAt X-Google-Smtp-Source: AGHT+IHn0dkOUMnAGstbNQI4vs5clefykXFoDZ0nuF/WlNXWNWoNdmU5J3HVfqujLhCoxxBXR52IYU8bOW+KVhsWpFk= X-Received: by 2002:a05:6512:23a9:b0:55b:814a:a7fa with SMTP id 2adb3069b0e04-55cb5d91a56mr4603138e87.8.1754894652956; Sun, 10 Aug 2025 23:44:12 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Amit Kapila Date: Mon, 11 Aug 2025 12:14:01 +0530 X-Gm-Features: Ac12FXxZzbtipWdPASOgE4MkzgS_vJylC8DF_sDwGyAV4uHenPonCMlNIyvXJOA Message-ID: Subject: Re: [Patch] add new parameter to pg_replication_origin_session_setup To: Doruk Yilmaz Cc: Euler Taveira , pgsql-hackers@lists.postgresql.org, Sawada Masahiko , =?UTF-8?B?SG91LCBaaGlqaWUv5L6vIOW/l+adsA==?= 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 Wed, Jul 30, 2025 at 12:00=E2=80=AFAM Doruk Yilmaz w= rote: > > On Mon, Jul 29, 2025 at 8:13 AM Amit Kapila wro= te: > > That is true but I still feel there has to be some mechanism where we > > can catch and give an ERROR to the user, if it doesn't follow the > > same. For example, pg_replication_origin_advance() always allows going > > backwards in terms of LSN which means if one doesn't follow commit > > order, it can lead to breaking the replication as after restart the > > client can ask to start replication from some prior point. > If you have any ideas for safeguards or API changes, I'd be happy to > help implement them or discuss them. > > Can you tell us the use case? Did you also intend to use it for paralle= l apply, if so, can you also tell at a high > > level, how you are planning to manage origin? > Yes, we use it for parallel apply. We have a custom logical > replication system that applies changes using multiple worker > processes, each with their own database connection. > Our use case requires multiple connections to be able to advance the > same replication origin. > How do you advance the origin? Did you use pg_replication_origin_advance()? If so, you should be aware that it can be used for initial setup; see comment in that API code: "Can't sensibly pass a local commit to be flushed at checkpoint - this xact hasn't committed yet. This is why this function should be used to set up the initial replication state, but not for replay." I wonder if you are using pg_replication_origin_advance(), won't its current implementation has the potential to cause a problem for your usecase? I think the problem it can cause is it may miss a transaction to apply after restart because we can use remote_lsn without a corresponding transaction (local_lsn) flushed on the subscriber. This can happen because ideally we want the transaction that is not successfully flushed to be replayed after restart. In general, I was thinking of adding a restriction pg_replication_origin_advance() such that it gives an ERROR when a user tries to move remote_lsn backward unless requested explicitly. It would be good to know the opinion of others involved in the original change of maintaining commit order for parallel apply of large transactions. --=20 With Regards, Amit Kapila.