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 1wa8s1-001YjS-2s for pgsql-hackers@arkaria.postgresql.org; Thu, 18 Jun 2026 09:17:10 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wa8s0-00Aaf5-2d for pgsql-hackers@arkaria.postgresql.org; Thu, 18 Jun 2026 09:17:08 +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 1wa8s0-00Aaex-1a for pgsql-hackers@lists.postgresql.org; Thu, 18 Jun 2026 09:17:08 +0000 Received: from mail-pg1-x52d.google.com ([2607:f8b0:4864:20::52d]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wa8ry-000000014Cb-2AMj for pgsql-hackers@lists.postgresql.org; Thu, 18 Jun 2026 09:17:08 +0000 Received: by mail-pg1-x52d.google.com with SMTP id 41be03b00d2f7-c88973b6965so597394a12.1 for ; Thu, 18 Jun 2026 02:17:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1781774225; cv=none; d=google.com; s=arc-20240605; b=asKiUE64xDkEpqUDCblsnalAusMVAj0u6jZizrjFKnuKcypYTdHrzaJzKMhRadxDyx k194AIcYdXfhTW+d8aocMrocNQruJ4LS2xowvq/lj6NCDJ8xkyeSFgyklAskBQkuXa5c uQxmteACmGov0fnOGiVqxOM/q6/FESgGQt4IFuQIlJ2t0gM6I44hwhruCQgI90FfTiM2 ov6ax8qq/R7nLtEqIm8btuK6NbGjsw3bVjYvrcn9nd0vltYTebHG+z6KuPTs7jvdJTB7 Rspye3wr9DDPFz9L0M4CmwdnV6PJIsVLH24cILfW3CAkAed7h2RiWY1ysdgC6kJZa7Ec NHKA== 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=9x9DfV9Rcr0WN31MOs2GBhlPAXya6egTJaFuuvWxii0=; fh=Zlbx99mdvV1il7NpIuodHbyhVYmHl3eqZjQmMEATC+c=; b=XXaXqEP4M41ltPKgVoUvbd+bTYFHx0UAUIcS9oiLV7M/9Ors8xd6IY27WpGWLOPUTV EqFRycA778+QcQ4gQ/BVxdXCbmIJXObPL1yEOsaR+dh9ZL+S2hlwT9RPHL/eC9nSsRXa UJZsKs39g59Dy5maKxAVFLI9JryRRgTjBTC1qjdlk0p8xDfGIcEZsAf0cM88QmRGOz/L E22NZ/7xId4jvSM3BDi/maQj/IIMrM+NqkmY//dLKhc+kz20RKVRZxMjh7TEgnVbZhAG YmQk9C1v5DfsaFqcbbQF6qLD4dV6H5nsNjzKeoe3rx8zvLRE68maLcxrcA+yCnTB7qvm lWTA==; 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=1781774224; x=1782379024; 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=9x9DfV9Rcr0WN31MOs2GBhlPAXya6egTJaFuuvWxii0=; b=EYUTep+2l3VoRauR6XXuifuM6+tit87eGCQv1b81jhe1zOxNku9AYTUSwC9WRVxI4o jy/PdfBBTCgX809w+1j0SExir1CL4db8EL7iNsuq8QHYCNkD7dnn2CEZ4EnKMWCZkCzO qRLaagOnTldswp4tB4TCkDqyGbfNP+p6BUpnn285cW59/XL9fXNEDD8lGuhtPpdx5KPM 1NEBtojHG0aZ+BiXsh9kq+Bz9P0BnfgjUY+RX0VINIjkJXGV87dOv/5ibrOmeQpX8AUe NDHU7y/Fqnq4C3Mj2DawcFBkse7wLWxVPQ+dxnF/O1uLqQ+pNDdNbDwG3l5FWzeFz8Sr 3OUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781774225; x=1782379025; 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=9x9DfV9Rcr0WN31MOs2GBhlPAXya6egTJaFuuvWxii0=; b=NihqUADbBLsluGGE+qXhD1ovzQafhXmCDio7M+hLwtaGhKOuULSRsL8v7JorOG9EPj U+X5jn060GMQ/CAMC2hdxK9RT6hZ4ol0j6S3/ySb/QOi5/mT44coGQjG92ywI5JwuM3c kZoTDQAwP8C1Fr/2POjGfJshLTnlPLbRDpIcm+nQY+rk7pMHVUc3294kbXMg1w/+hoyP 1VcAzms62sEI1GvN8L3a3vllVHkuNlILTdDQhF51Agjr2xt6xlAiGsPVJeztn+rT0QzG 2Atj+BkH6bMUbeQ93mb8+iad3uiuWQoj+Fin60Su/ARRnzhEPvJAMHAuULS9dqP4FurU tQWA== X-Forwarded-Encrypted: i=1; AFNElJ8hKV1Npc5DWB6nQw1KOFUkGsPxV62fzfpAZRuSbXfVS6LHpPvN0y5ZOWLXc8f20wN0B78aqmMINkW5c5FJ@lists.postgresql.org X-Gm-Message-State: AOJu0YzrKYvmZhSaXaV7AqKJDtgPN/j6lX+kfiQuxu7OOtT8dPm5euuI S1dwWzc6aGicXTtT2WpuvgI12fyg0YPz//+BVPRghso8UbJK6bDEQMqe/lpGTemr8z/+gl1shHP 7eJbJvkVDWmATt35dTuzQTSpM6xJiBRY= X-Gm-Gg: Acq92OGJe4Pgj42Ox4XS4vz2gMGcJxnIJK0q5R2Urk4jXypalXFDvO+wG1FrsJl5ZgB iNrliLRGNYbU3iwURiWmjOrCHL5zP+qS79h5uP2KgySqykWtDOQkhjFnPKf7qV1mQeW7eBsSDnJ xqI79tILeYvI/TVyY2aJy3ysUYFeTttodLsFuW85C0QXN4MqkxPTw8UKiWmUeVv00sZhqYy/v0X pYHtD1hQTMZG/W25iYzWzrg2KCKbfUey4WYWmzxHRx4BMw8B/qPV9fbzAcZgZZVGjMNKp2zDrOK dDOAGB2PFoJmSx4uyDXoN9sEZ5c9BE7svZjvXo17 X-Received: by 2002:a05:6a21:1f8e:b0:38e:92f6:9ab1 with SMTP id adf61e73a8af0-3b9e28c787bmr2684996637.22.1781774224515; Thu, 18 Jun 2026 02:17:04 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: shveta malik Date: Thu, 18 Jun 2026 14:46:51 +0530 X-Gm-Features: AVVi8CdvYD7QZWusskEY4z-lCiz0y2uSAo4sNZI6_qmpTIYBnWf1V4zTMcLTd78 Message-ID: Subject: Re: [PATCH] Preserve replication origin OIDs in pg_upgrade To: Nisha Moond Cc: Ajin Cherian , Shlok Kyal , 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 Wed, Jun 17, 2026 at 5:12=E2=80=AFPM Nisha Moond wrote: > > On Wed, Jun 17, 2026 at 4:29=E2=80=AFPM Nisha Moond wrote: > > > > On Wed, Jun 17, 2026 at 2:49=E2=80=AFPM Ajin Cherian wrote: > > > > > > I have addressed the comments in v8 (attached). I've also now taken > > > out the check for PG17 on old cluster and now all clusters which have > > > replication origins are migrated. > > > > Hi Ajin, Thanks for the patches. > > I have started reviewing the patches. Please find a few initial > > comments below (from v7 review, still applicable to v8): > > Please find a couple more comments for the v8-002 patch: > > 4) I was able to build successfully without all three new header > inclusions below, so we may not need them. > --- a/src/backend/utils/adt/pg_upgrade_support.c > +++ b/src/backend/utils/adt/pg_upgrade_support.c > @@ -11,6 +11,7 @@ > +#include "access/genam.h" > ... > +#include "utils/fmgroids.h" > ... > +#include "utils/snapmgr.h" > ~~~ > > 5) Race condition in origin.c: replorigin_create() > - heap_freetuple(tuple); > + table_close(rel, ExclusiveLock); > + > + replorigin_create_with_id(roident, roname, InvalidXLogRecPtr); > + > > Due to the above refactoring, CREATE SUBSCRIPTION can now fail because > of a race between two concurrent CREATE SUBSCRIPTION commands: > > postgres=3D# create subscription sub2 connection 'dbname=3Dpostgres > host=3Dlocalhost port=3D7733' publication pub1; > ERROR: replication origin with ID 2 already exists > > I think this happens because the table lock is released, allowing > another session to create a pg_origin with the next available roident, > which replorigin_create_with_id() later attempts to use. > > Would it make sense to call replorigin_create_with_id() before > table_close() so the lock is still held? I tested this and it works, > though I'm not fully sure whether self-locking could be a concern > here, since replorigin_create_with_id() again acquires a > RowExclusiveLock on the same table. We can handle this race-condition by moving the table-open to callers rather than internal call replorigin_create_with_id(). But we also need the following changes first: 1) replorigin_create_with_id has: + /* + * To avoid needing a TOAST table for pg_replication_origin, we limit + * replication origin names to 512 bytes. This should be more than enough + * for all practical use. + */ + if (strlen(roname) > MAX_RONAME_LEN) + ereport(ERROR, + errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED), + errmsg("replication origin name is too long"), + errdetail("Replication origin names must be no longer than %d bytes.", + MAX_RONAME_LEN)); replorigin_create_with_id() is called by replorigin_create() and binary_upgrade_create_replication_origin(). replorigin_create() already has this check. We should move above check to binary_upgrade_create_replication_origin() and get rid of it from internal function replorigin_create_with_id(). 2) Also the checks: + if (SearchSysCacheExists1(REPLORIGIDENT, ObjectIdGetDatum(roident))) + ereport(ERROR, + errcode(ERRCODE_DUPLICATE_OBJECT), + errmsg("replication origin with ID %u already exists", + (Oid) roident)); + + if (SearchSysCacheExists1(REPLORIGNAME, roname_d)) + ereport(ERROR, + errcode(ERRCODE_DUPLICATE_OBJECT), + errmsg("replication origin \"%s\" already exists", roname)); should be moved to caller binary_upgrade_create_replication_origin(). IMO, these checks are not needed for replorigin_create(), it alread has this, which should suffice. ereport(ERROR, (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED), errmsg("could not find free replication origin ID"))); ~~ Once we correctly place these checks, we can move the 'table_open with lock' to caller (before name and id collision checks) instead of replorigin_create_with_id(), which will take care of race-conditions reported by Nisha. thanks Shveta