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 1ullIc-005A7z-If for pgsql-hackers@arkaria.postgresql.org; Tue, 12 Aug 2025 09:28:06 +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 1ullIa-006Vpn-A9 for pgsql-hackers@arkaria.postgresql.org; Tue, 12 Aug 2025 09:28:04 +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 1ullIa-006Vpf-0z for pgsql-hackers@lists.postgresql.org; Tue, 12 Aug 2025 09:28:04 +0000 Received: from mail-lj1-x235.google.com ([2a00:1450:4864:20::235]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1ullIX-000Avl-35 for pgsql-hackers@lists.postgresql.org; Tue, 12 Aug 2025 09:28:03 +0000 Received: by mail-lj1-x235.google.com with SMTP id 38308e7fff4ca-32f1df58f21so51569291fa.3 for ; Tue, 12 Aug 2025 02:28:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1754990881; x=1755595681; 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=xw7mTSo/N2Nd7NpuYm3sBh3lfj29BHE6EjfVixOVt/M=; b=DKQ1ly16iYS667O8ebQEjZFUHnTfZbroZiD10GkHx2vel/K5CMHDxLhRqE2CGObgqV d9zVgKJHxX5O3AIKF6vQHB/gzdjege+lbTS81Y8IKeBdHXxy8/zH1GLGCbTIXTugDv3B FK/cR2CoSfBs0aosA2NheB7+MtZT07RyRI4fpdRh93VXgBkAQgREnOfvHGcG0QmPAltP sb9hG9Sm5G/xnVw/H6mzYqy4wP2e/HmqcWJsPf7qcLqL4ZIK+MIwpG1VrZDbJULXoptP Nbg4fLy/ljPNuC5wEeM1fRJ2GHBfjx8TODRPp5tLpkv69sTRBL4P/CFZWcTulOuEgKBM wkUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1754990881; x=1755595681; 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=xw7mTSo/N2Nd7NpuYm3sBh3lfj29BHE6EjfVixOVt/M=; b=Gk8JxHAEAIhzI77Xctpu+Uhv00SQPAEwlWm6m3fvDCzTLWD95t4De+EXZATnEfN5Sk zs7N/D90CjV728Sy55MHzjwdO5EOAayUrTy756eEYGcVQAZ2HtcGu0qTU/7uWY7oLlLN 0j2/ocbyIrLMauJqgckwikT5T3dNYXpw18zgoCmxYWJkNAGq0QSIWZiNwU8XdRo/3Nsx 6FtOnthJCtus14eFbPpKd/YSrjwpwUfo9DVT4HOW4xoT4FSXXKz+K34SvMapb8kcz1/M pafy+5Yj5p7XYv7f3i4jOGKjbNNNVc1DJ8kJtvJyiiwSPLxhsHG8Go16vyLHq4WejjSj dyxw== X-Gm-Message-State: AOJu0Yygki+n3MuyhFW9wObDL2/qC+ekPVQ+9ZQFCDxwK85gkOZI4Ic3 znNcw6zEhgYl1u8+UvgNHssQ98kkUhrDNRDcs3SBTmCI1FLYaiGWVq6TxJy7QfjOmf9HYrxCheN AMp3PhnokqBIBjASri6Eeh8+k1noLMCgwfCgP X-Gm-Gg: ASbGncuXEOSB7TwLNVr17PQVT7IQCQ1bKY/itBaOm7sWsW6GcpNj1vEspEt/tAQiWOX mu4inWnTYf+vhcEbN3obnwmI5eMKFCELYj01MAPDSvVmzu3UyAP8cHhE74nBQWstAlJDTaG8KqO VNt7Ubi42rmvHK7t85jPRCAWwR6KVwQn5Ii4AcHMNyHFmAgcPwLnx4wM3BamGePX3YUDsWHvCia NygRF+tGA== X-Google-Smtp-Source: AGHT+IEtMkCJNAJSUdt9fRgc8gQ5QArtiqJ/kCFipRlxKBbQUdS0O6RB9jy74TXiEDcs2jvP7qzxKI1kCqEoNfwePV0= X-Received: by 2002:a05:651c:4197:b0:32b:2f4a:35e4 with SMTP id 38308e7fff4ca-333d7bf2424mr7059051fa.34.1754990880996; Tue, 12 Aug 2025 02:28:00 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Amit Kapila Date: Tue, 12 Aug 2025 14:57:49 +0530 X-Gm-Features: Ac12FXwuJYRtXL6Gy94LBHrlXIQ5HTBVeP8wdkkapuEpRDW1pKMYupTkWj_gPkI Message-ID: Subject: Re: [Patch] add new parameter to pg_replication_origin_session_setup To: Doruk Yilmaz 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 Mon, Aug 11, 2025 at 10:41=E2=80=AFPM Doruk Yilmaz w= rote: > > On Mon, Aug 11, 2025 at 9:44=E2=80=AFAM Amit Kapila wrote: > > How do you advance the origin? Did you use > pg_replication_origin_adva= nce()? If so, you should be aware that it > > can be used for initial setup; see comment in that API code... > > No, we don't use pg_replication_origin_advance(). We use > pg_replication_origin_xact_setup() instead as I mentioned before. > > Each worker does the following: > 1. Sets up its own replication-origin session with > pg_replication_origin_session_setup() (using the master process PID). > 2. Applies changes inside transactions. > 3. Right before commit, calls pg_replication_origin_xact_setup(lsn, > commit_timestamp). > 4. Commits only if everything succeeded, so the origin only advances > on a real commit. > > That way, the origin LSN moves forward only when the transaction is > actually committed. If something fails or the process crashes, the > origin stays at the last successful commit, and on restart we replay > from the correct spot. It's safer than advancing the origin without > knowing the transaction made it to disk. > Your use looks good to me. So, maybe we can update the docs with the dangers if the users of API doesn't follow commit order then it may lead to data inconsistency should be sufficient. Additionally, we may want to give an example as to how to use this API for parallel apply. Thoughts? --=20 With Regards, Amit Kapila.