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.96) (envelope-from ) id 1wXZ3g-003KsH-32 for pgsql-hackers@arkaria.postgresql.org; Thu, 11 Jun 2026 06:38:33 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wXZ3f-00EZqv-2h for pgsql-hackers@arkaria.postgresql.org; Thu, 11 Jun 2026 06:38:31 +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.96) (envelope-from ) id 1wXZ3f-00EZqn-1f for pgsql-hackers@lists.postgresql.org; Thu, 11 Jun 2026 06:38:31 +0000 Received: from mail-pg1-x52c.google.com ([2607:f8b0:4864:20::52c]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wXZ3d-00000002TVE-1Das for pgsql-hackers@lists.postgresql.org; Thu, 11 Jun 2026 06:38:31 +0000 Received: by mail-pg1-x52c.google.com with SMTP id 41be03b00d2f7-c859a374903so2682685a12.3 for ; Wed, 10 Jun 2026 23:38:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1781159906; cv=none; d=google.com; s=arc-20240605; b=Pdx9FmdUqljA+5hDEZzzSq5QipIi9iPTBphymbcKuJYbanEj43SL8+8FnMiIHODiJu SMEf6w121YSU/ZQBWdp7E2/+jF0V52kq4HWCJG6lpuPkLpL5o/aFImu8lffOYbW3ZJrH EiGQxBk46Zc/6vLz/lQTTP2j6FsFe4UQ55/LKsscPFcCQCq38Ru6elVizchASl1Tw/Va NuByWcDJN3y7dXHf7xa6+0RMIsCdLm+Hk2PJCZZ+fO0sQMzCKjb4fL5TfEXJf6fnLvYR Nizm6KsM8g1XUv7kMciScFGMeutntxIsY/6/CRODknbHjZqtyPqRQoJ79Yx7V61hQLaD njUQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=Ok1ORz3twG0OtDL2qyjJrf2Dxf7hL5sCuPFwYbZ4T7s=; fh=RwU/s4CCFlxZMPuO8EIGsl0VfTaT8WbiCHgGeYkwA/g=; b=dpO5niXmIObF+saXC4LQeZAO6NjSQA+RSPyp+LQ6B8JLxdC8oNS34xLP1K6QsfiLl8 ft0Gu8jGqwQrED5tc0CzF1/pkrFFTprgL7H/ZaD4BZpIhBYdYvhXYEAtu45hnRpr7zQM Q4NUGr6DPXAQsADzCGYKlcRwK6/yIPBxBCmgqdEG1A0mXW5NOVTifZTTk0Cj2FPSeajC +Wa6GKO8ULXXEbXpoRrbOmCEAh7hUAjv8kFJfmtfXDEfkhkwUSvAYGXFZpn4Ir2SLrgA Cb6Uoe52TGR1brR41k0NWxgswkS0f6hFk+P51B9Nx91JPWLQWYVkLsYLl+rfZvUUpGyz mHMg==; darn=lists.postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1781159906; x=1781764706; 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=Ok1ORz3twG0OtDL2qyjJrf2Dxf7hL5sCuPFwYbZ4T7s=; b=pxj3uhIVcAlNuVdg/HBdGu6F05Xz0VtivsILCDpgDP5l/oqj/kSzK88ehqu8zn23H4 L9t0XVKsiMqEA8+9gUarTvUIeA90N7TABuhR7W4cujFn7CogfPYT8TE8nm0KRhd5Oq0A VfDS3mHpwH3b37PBtfa0LejR2jBmekbF0z8zjQTVjh5wgv7KHfDe7lgTDHes7vNgLl3g GiPUqA/JQ6JqjE6UnA8+8IUQwe1+KSgowEANIRoWkYm80tfLjw/rmrpwZn32kngVEOEP xgySAtoYD+uXJlNJpu3exwTnQ19YEW3spCfyr0TXSYZE8CUYruBYFKrZLwR/uDmcuLG+ 7HtA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781159906; x=1781764706; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=Ok1ORz3twG0OtDL2qyjJrf2Dxf7hL5sCuPFwYbZ4T7s=; b=kAKTFBP8TBCuP9wYWeMbmtgEkWodSxARgBBjojVxFtkL8CQqBhF4yfxW0fQ4J2N+IJ 4zPLAtKfbBo4DMOlSyDywKDyt4gJCicd1fN4SnyZopTvOe6dV/UVWy8Gbg6h0uofHkqv 5/gdZzOKTA8Qpg/yby4B+dBSnEh5Zawa0piXb5eHZDRfGYmkt9KKoEKqCCCFOxc7lHnc 5n9qDlR/W3LPuxTuwgV3LXAtIhWdtxSbHvldtJUD4C1mzwGdATGF28KbFpiOZMuIKz8q ZgxN+/wba4JqeRHtSYI6vbFtZt0jCX6wYcDSEw21hCTce4uLIySr/6qzigfzRGKj6v15 7CWg== X-Forwarded-Encrypted: i=1; AFNElJ/y/YhfVZTxu49c24PiDW+mjmJJEfHg9R0ncpdMI/YxvBk48adFtdiqQMofHrldC2daAjWh6zEIJxNppLLm@lists.postgresql.org X-Gm-Message-State: AOJu0YyZsCYa6o3ZhlT1CJqMfw+0n2wntY90k5iUINpEqsKtU85YOyeA gMELlQkzT5ywLmVvHODI7CnWOJ2UBNGM38nWngtPm4dWCKe+izH01yUEI3yqTn9NcIf0Da6vnSi gNwcahqKwzV91zzatPGnSFIO/boIdvb4= X-Gm-Gg: Acq92OGsGJodT2+3/wO9U/SH0hrefR4QL5nAb6Wft3UawaXm/Ek3M+qREsP6P6OfoW9 50D2WjMnWzNjkiBPva22pwTQlBFCbBiBJBSuH+7FpT8hMJPl85HRZNyRZcRyVHcDSAXwz2eG1sY tyHXRMZxhSbNt80vO6OhZiG9O3+Amsh+032wPgLRnWGaewEDq0nwvrT72e3OY+9zYQCXCZMCwKC zzfKYmaYYWgtC1YpNTBJWpGephk2i7xtKp+9KZDsbBC9BHfMQlMTcl3R2dxuc+GyQuNMgrPPDYt QyOnIxr2HptpeMbadBWB3JpO5T0iblbNuhWnUFWTdmymldBtRqE3EX9x14bo4VBpgs3ZORmj1Ic Vl1PSb2VX0aYQCyC9YmMi X-Received: by 2002:a05:6300:67c2:b0:3b4:8ba9:4d8e with SMTP id adf61e73a8af0-3b5e331c836mr1632842637.23.1781159906119; Wed, 10 Jun 2026 23:38:26 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: shveta malik Date: Thu, 11 Jun 2026 12:08:13 +0530 X-Gm-Features: AVVi8Cf8abZ4565OIEXlQbFvvKYrCNIHScIBh1t7SmkxIKMtdEdEQ4Nb3c-E9Y4 Message-ID: Subject: Re: [PATCH] Preserve replication origin OIDs in pg_upgrade To: Shlok Kyal , Amit Kapila , Dilip Kumar Cc: Ajin Cherian , Zsolt Parragi , vignesh C , "Hayato Kuroda (Fujitsu)" , PostgreSQL Hackers , shveta malik 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, Jun 8, 2026 at 10:36=E2=80=AFPM Shlok Kyal wrote: > > > 1. I want to clarify, what is the expected behaviour when we upgrade > the postgres instance from version <=3D 16 to "HEAD + patch"? > - ReplicationOriginNameForLogicalRep(subid, InvalidOid, originname, > sizeof(originname)); > - replorigin_create(originname); > + if (!IsBinaryUpgrade) > + { > + ReplicationOriginNameForLogicalRep(subid, InvalidOid, > originname, sizeof(originname)); > + replorigin_create(originname); > + } > and > + /* Dump replication origins */ > + if (server_version >=3D 170000 && binary_upgrade && > archDumpFormat =3D=3D archNull) > + dumpReplicationOrigins(conn); > > When the postgres instance with subscription is updated from PG 16 (or > less) to HEAD, the replication origin is created as we do not have "if > (!IsBinaryUpgrade)" check in HEAD, > whereas when the similar instance is upgraded to "HEAD + patch", no > replication origin is present after the upgrade. > Is this difference in the behaviour between HEAD and "HEAD + patch" expec= ted? > No, this difference is not expected. The issue is that in patch 002 we intentionally avoid replication-origin creation during CreateSubscription() by adding the '!IsBinaryUpgrade' check. The idea is that origin creation should instead happen through 'binary_upgrade_create_conflict_detection_slot()', where we can also preserve the original origin ID. Origin-ID preservation is currently implemented only for upgrades from PG17 and later. (see the check in pg_dumpall.c in 002). As a result, when upgrading from PG16, origin creation is skipped in CreateSubscription(), but the origin is also not created through binary_upgrade_create_conflict_detection_slot() because of the PG17 version check. Therefore, no replication origin exists after the upgrade in this particular case. We do not have access to the source-node version during the restore stage (i.e., when CreateSubscription() is executed), so we cannot perform the version check directly there. Therefore, any information needed to make this decision must be preserved during the dump stage. Ajin, Kuroda-san, and I discussed several possible approaches to address th= is: 1) Add a new subscription option, for example 'skip_origin_creation'. When set to true, CREATE SUBSCRIPTION would skip replication-origin creation. During binary upgrade, pg_dump would emit skip_origin_creation =3D true for source clusters running PG17 or later, and false otherwise. However, this approach requires introducing a new user-visible CREATE SUBSCRIPTION option. 2) Another idea could be to have a 'binary_upgrade_skip_subs_origin_creation' variable. We populate it during dumpSubscription if 'source_version >=3D PG17' and 'IsBinaryUpgrade' is true. So this will be dumped SELECT pg_catalog.binary_upgrade_set_skip_subs_origin_creation(true); CREATE SUBSCRIPTION ... SELECT pg_catalog.binary_upgrade_set_skip_subs_origin_creation(false); First call will set 'binary_upgrade_skip_subs_origin_creation' which will be used by Create Subscription to decide to skip origin. This is similar to how dumpACl decides whether to record priveleges into 'pg_init_privs' for objectes created by extensions. See binary_upgrade_set_record_init_privs() which sets binary_upgrade_record_init_privs which is then used by recordExtensionInitPriv(). 3) Create origins and preserve origin IDs regardless of source version The current patch preserves origin IDs for upgrades from PG17 and later. One reason for choosing PG17 as the starting point for preserving origin-ids is that complete logical-replication setup migration was introduced in PG17. Prior to PG17, subscription state (pg_subscription_rel) and replication slots were not preserved during upgrade, so limiting origin-ID preservation to PG17 and later aligns with the broader logical-replication migration support. OTOH, replication-origin migration itself is supported for PG16 upgrades. For PG16- upgrades (without this patch), subscriptions itself can be migrated, and corresponding origins can be created at that time. Therefore, even on versions prior to Pg17, it may also be reasonable to consider preserving origin IDs independently of the rest of the logical-replication configuration migration, and not tie it to the PG17 boundary. If we choose that approach, check_new_cluster_replication_origins() would likely need to run for upgrades from PG16 (and prior) as well. Subscription-ids also need to be preserved for the same versions. For reference, check_new_cluster_replication_slots() and check_new_cluster_subscription_configuration() currently run only for PG17 and later. ~~ Given the need for a new user-visible parameter, I would rule out option 1. Between options 2 and 3, I prefer option 2, but I would be interested in hearing others' opinions. Any other ideas are also welcome. thanks Shveta