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 1wVRV7-001xqj-2w for pgsql-hackers@arkaria.postgresql.org; Fri, 05 Jun 2026 10:10:06 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wVRV6-00BkhE-2s for pgsql-hackers@arkaria.postgresql.org; Fri, 05 Jun 2026 10:10:04 +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.96) (envelope-from ) id 1wVRV6-00Bkh5-1V for pgsql-hackers@lists.postgresql.org; Fri, 05 Jun 2026 10:10:04 +0000 Received: from mail-yw1-x1135.google.com ([2607:f8b0:4864:20::1135]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wVRV4-00000001DfD-2Oay for pgsql-hackers@lists.postgresql.org; Fri, 05 Jun 2026 10:10:03 +0000 Received: by mail-yw1-x1135.google.com with SMTP id 00721157ae682-7e2cb01a974so19565517b3.1 for ; Fri, 05 Jun 2026 03:10:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1780654202; cv=none; d=google.com; s=arc-20240605; b=VZzmHlUwlrhRbjPXb9wG5xEbcGyB3pXIdzYUKvz46c6SWkGzQPI10iOCB6Szk7mciz jl6sU76v6DK5b1zrokrQ9sR7X4OzFi9K6bXj9bsDyozhAurCs34Lzwau9viU/nbi999p F+q7YBarGVsVVpVvULxHQ94x2LLr1xf/2oiOpvv5ttSa7fvymMrhFcerkFiAHqw7U0aD a16lnsy8Kb0iInf3Qa2VBkzgGK1GFYlgxI0JzNyNo+FEFnTxCBG1u2a4xg+4wv6Uz74n PYobTXhOrXF0EAB6NVf2+sFJeg9eImxR1PnMrYBeTxcgsPyvtxGQwrWYJECNMhblAeks ESLQ== 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=k+g/AR9ml+jDRJTjKSelVyYLnVno6hU1jtW0ADrT9pw=; fh=PwcrYXVUc4NfnRBaQllhid/qr8U6M0lUcfAqFX7e3vM=; b=C7tfgLb8+efBJIiNoXLN10uEtojraXm8GuFSVTUtB8Q2zuc5bSxmV6CZgXgYAqbakZ 64paWyJDAxUnPakqPQ684HbG91ZVRZgZZ08vHAgN2zEUz31vbVm6xG+q5m5+7Km3Y8rD dJqGKbEAqamh9sN3cEZRfEUlNwHta9CbivoJXhTLd/P5vZ650nyrUHYXsgj6jLp2XkIX zn34YbNEsIhfcga4xFYjYPc/O7JlqAVZw9bn5O69SvyvcsiOM5e+NMoQJ2Gn9oWPf+pK EGa1m2XsjxXlJkroQD1xo4qJmv9b5sG7NmY0/hi+BPxAk4KkuPq923na+FnytrUagMiP KoZw==; 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=1780654202; x=1781259002; 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=k+g/AR9ml+jDRJTjKSelVyYLnVno6hU1jtW0ADrT9pw=; b=onnlg98amiltj0RcN9rX2rA2ZAwGlNr1Jlm/QjBBfJSJ2ruV7nARVBw+Rcp5dcTl7c 8n7urOV47EL1+47HPiZ5Rkn417GuEdmiJg7D4TuVasG4+3ic/zXStjEF9lOHadiQdR6a GI5Zk5MVtG8nnlrOVOawViS+wVrOQBEZSwzM+Z/LnEu6hANHMpaMK05R5gPufNtwZUMM PDvlQlwXeRy+Wk2Twfro6/kgqMNlqposYQuw2H28Z4e+U71RzvCKpxZcCC0e9oYgunL+ fGozB+3Z/+3u4B4cpZMRqPJ9+gv9pBHbkpEWsboK85FBvEIaFGr/lgSQKQ/Eak1M/Qlc nPNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780654202; x=1781259002; 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=k+g/AR9ml+jDRJTjKSelVyYLnVno6hU1jtW0ADrT9pw=; b=X/NoyKRsdlAV3cBZCVcqY1UhR8nGulLu9g0n5yEEXFvpNQhzeVd/FDSFekGSJKGNZR P11D71ztD47IrZrudByEeVCYIrtsEckxvTlZ0BOuvs0/Hi3BtGVTtSV3WHH20BF3j6IX h8Tzp3nUodziDv7byl6UgXuLILIHq+mqqErRGpo10lknHJk1+TGl/0Zy5NdgiAcTrnWU ZTxeJlFWutfI5kGVk+FA3rSC/tAdxLbnzddOJI3JVuc/rm/cRorQu2ConCxY+rb9U2AL XEe8lCMLY4GyUjicwyANztQN1l+etnbys072tULJX3DyTngg7ozkJzY4S+rjPWHRAi7n BcEw== X-Forwarded-Encrypted: i=1; AFNElJ8ahdi40PVozRt/ZN9RXSaHI1W9SSN04dAuk9aS8evqONN+ZNGOqX+OUO8ds7UhfJ0vSx3iL7dO4wzTXS9T@lists.postgresql.org X-Gm-Message-State: AOJu0YxDgBWsKz4xSOI3Chnz6vGdq3Z/U106UELWPtxFWO/bvpoZk7sY t8LUslsiWrJyy+UDf3CdmRPjcJuES1mYfdyJdUlwNk8xLzCl4AoS4TjdQCr3IFzx7SB3LageZJk HovZA5rwiCEtli83fCifqsEiPPwwzFQc= X-Gm-Gg: Acq92OFq9tx+FAartPzUoIRgewdAF8iTvt4zlpP0MsYUJsHkPUA6XtEtostA7tZK3xH ukQC5QsxZieq2Enp2okd0I5m2NSEePQQmn6tmUG1nbkp3zeX2NaFihowKEeefUp7URRRR7ua+8S Afubz55g+7jcWMIvW1h8kNN/AffCR27ago5vNDN5RFnp+FjDTpNwd8vWAZE/ad9IcKPdNWwjN62 QI+4HQnUoFfYuvhy0gQtjDKNyAhGGZDNXfBVQkMI1N33zzEgvl/U70vpZIUsXq6JLdWSi3sgarF pPzgTZmxFsmzXcbw5TxL X-Received: by 2002:a05:690c:e1c:b0:7e2:2c41:4f74 with SMTP id 00721157ae682-7ed0b87496dmr27691277b3.5.1780654201558; Fri, 05 Jun 2026 03:10:01 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: vignesh C Date: Fri, 5 Jun 2026 15:39:49 +0530 X-Gm-Features: AVHnY4IRyT8-YEQzvjRTPOvFvZz9hYScQQY-E6fL283Ns6bVnOCmYzw2IPB2B_g Message-ID: Subject: Re: [PATCH] Preserve replication origin OIDs in pg_upgrade To: Ajin Cherian Cc: shveta malik , Shlok Kyal , Zsolt Parragi , "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 Thu, 28 May 2026 at 08:18, Ajin Cherian wrote: > > Fixed this. Added a new check for replication origins and if the new clus= ter has any existing replication origins, then the check will fail. >> >> >> Few trivial comments: >> >> 1) >> >> +#include "access/skey.h" >> +#include "catalog/indexing.h" >> >> pg_upgrade_support.c compiles without above. >> > > Removed. > >> >> 2) >> + Assert(!OidIsValid(rel->rd_rel->reltoastrelid)); >> >> Is there a reason for this sanity check? I generally do not see a >> Null-Toast table sanity check after every table_open. >> > > Removed. > >> >> 3) >> >> + >> + /* Dump replication origins */ >> + if (server_version >=3D 170000 && binary_upgrade && archDumpFormat =3D= =3D archNull) >> + dumpReplicationOrigins(conn); >> >> why the check is for PG17 specifically? >> > > In PG17, we started migrating pg_subscription_rel and the remote LSN duri= ng upgrades; prior to that, these were not migrated. Given that change, it = also makes sense to migrate replication origins from them. Otherwise, when = upgrading from PG17 to a later version, you could end up with a subscriptio= n where pg_subscription_rel and the remote LSN are migrated, but the corres= ponding replication origin is not created. > > > > On Mon, May 25, 2026 at 5:13=E2=80=AFPM shveta malik wrote: >> >> >> One issue in 002: >> >> binary_upgrade_create_replication_origin() has this: >> >> + originname =3D PG_GETARG_NAME(1); >> + >> + roname_d =3D CStringGetTextDatum(NameStr(*originname)); >> + >> >> We are getting origin-name (text) into Name-type which can not be more >> than 64 bytes. So if an origin has name more than 64, it will end up >> trimming the name post-upgrade. >> >> I tried this: >> >> Old-setup: >> postgres=3D# SELECT >> pg_replication_origin_create('this_is_a_very_long_replication_origin_nam= e_that_exceeds_the_limit_of_64'); >> pg_replication_origin_create >> ------------------------------ >> 1 >> postgres=3D# select * from pg_replication_origin; >> roident | roname >> ---------+--------------------------------------------------------------= -------- >> 1 | this_is_a_very_long_replication_origin_name_that_exceeds_the_= limit_of_64 >> >> >> Post-upgrade: name got trimmed to 64 length. >> ------------------------- >> postgres=3D# select * from pg_replication_origin; >> roident | roname >> ---------+--------------------------------------------------------------= --- >> 1 | this_is_a_very_long_replication_origin_name_that_exceeds_the_= li >> >> thanks >> Shveta > > > Fixed this. Now binary_upgrade_create_replication_origin handles it simi= larly to the way pg_replication_origin_create handles the name of the origi= n. Few comments: 1) pg_dumpall dumps all replication origins, not just subscription origins and recreates every origin: SELECT o.*, os.remote_lsn FROM pg_replication_origin o LEFT JOIN pg_replication_origin_status os ON o.roident =3D os.local_id Is pg_upgrade expected to preserve user-created origins? If so, you can mention this in the commit message 2) Should the table lock be released here, if so should we mention comments similar to how it is mentioned in binary_upgarde_add_sub_rel_state: + /* Restore the remote_lsn if provided, while still holding the lock */ + if (!PG_ARGISNULL(2)) + { + XLogRecPtr remote_commit =3D PG_GETARG_LSN(2); - ReplicationSlotRelease(); + replorigin_advance(node, remote_commit, InvalidXLogRecPtr, + false /* backward */, + false /* WAL log */); + } + + table_close(rel, RowExclusiveLock); 3) We can use new style of ereport to exclude '(' before errcode: 3.a) + 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))); 3.b) Similarly here: + ereport(ERROR, + (errcode(ERRCODE_DUPLICATE_OBJECT), + errmsg("replication origin with ID %u already exists", node_oid))); 3.c) There are many others, you can search other ereport in the patch and change it too. 4) Since only one column will be returned here, can we use "PQgetvalue(res, 0, 0) and remove PQfnumber: + res =3D executeQueryOrDie(conn, + "SELECT count(*) AS nrepl_origins " + "FROM pg_catalog.pg_replication_origin"); + i_nrepl_origins =3D PQfnumber(res, "nrepl_origins"); + cluster->nrepl_origins =3D atoi(PQgetvalue(res, 0, i_nrepl_origins)); + PQclear(res); 5) replorigin_create also has some duplicate code like below, will it be possible to have a common function so that both of them can use? /* Check for name collision */ + ScanKeyInit(&key, + Anum_pg_replication_origin_roname, + BTEqualStrategyNumber, F_TEXTEQ, + roname_d); + scan =3D systable_beginscan(rel, ReplicationOriginNameIndex, + true /* indexOK */, + SnapshotSelf, + 1, &key); + collides =3D HeapTupleIsValid(systable_getnext(scan)); + systable_endscan(scan); + + if (collides) + ereport(ERROR, + (errcode(ERRCODE_DUPLICATE_OBJECT), + errmsg("replication origin \"%s\" already exists", + originname))); + + memset(&nulls, 0, sizeof(nulls)); + memset(&values, 0, sizeof(values)); + + values[Anum_pg_replication_origin_roident - 1] =3D ObjectIdGetDatum(node)= ; + values[Anum_pg_replication_origin_roname - 1] =3D roname_d; + + tuple =3D heap_form_tuple(RelationGetDescr(rel), values, nulls); + CatalogTupleInsert(rel, tuple); + heap_freetuple(tuple); + CommandCounterIncrement(); Regards, Vignesh