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 1u7hbK-004PKg-6n for pgsql-hackers@arkaria.postgresql.org; Wed, 23 Apr 2025 21:25:50 +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 1u7hbI-00AUoF-4D for pgsql-hackers@arkaria.postgresql.org; Wed, 23 Apr 2025 21:25:48 +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 1u7hbH-00AUo6-Kj for pgsql-hackers@lists.postgresql.org; Wed, 23 Apr 2025 21:25:48 +0000 Received: from mail-il1-x12e.google.com ([2607:f8b0:4864:20::12e]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1u7hbE-001bFD-2U for pgsql-hackers@lists.postgresql.org; Wed, 23 Apr 2025 21:25:47 +0000 Received: by mail-il1-x12e.google.com with SMTP id e9e14a558f8ab-3d90208e922so1953245ab.3 for ; Wed, 23 Apr 2025 14:25:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1745443544; x=1746048344; darn=lists.postgresql.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=34p4+3b+wFlumsJ54cUGUH7oCamjDSk+VJziD85VOtk=; b=ew+BBOSZoGm6qUFW/Jsd6tn/j5OLw1Lw7dpUB+g1qsj8/trfOQyLJrv2AnHhfwqS1E Fwz7Jn5acyzxTDaa1G4GWtWoEIdabYZi9QaqTth3Qy40gkd4g70wyf2KwwNsEpN0LrD8 bZCYYDGIjOM4wmAvshMNWyIv1HBlybnzTx9ULvixUve22/NeIzNKHYM081LWxjNj4a8R ifK2Tdc5U5RD5JdVMzZre57wfcqDWk4glvOH6hhkV65ZPrJLWJR7GZVR3QZvGt9H/wcV He7Si31K5+Ak0e75tvd45mjWKeNmLMz80iriC24OWG8iWe7U3QOaVGIQLO8SyrRBuQzU w1cQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745443544; x=1746048344; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=34p4+3b+wFlumsJ54cUGUH7oCamjDSk+VJziD85VOtk=; b=SyBHh2gwTZDEWR3ZES7GmlCf4m7sf9NPG/86axJBGm+FtS7ZDMdpe2jVYgvT0fpaqs nVxRKw2aTAzvCpY5AsEQ1oVmgITNX1libAiIrGx+sB61+PmDtATBAaaOOLLtNuTxnv1U KCMxJT9R3rs+XxcKBM2fBAjaOcZUGwgx/4Ph+p4pjSRVTPY18zfNWYLrCC/YhqiDVrWo ECoWZsKeofUTKSukYIvFGY3q8J6pKvgU0ry/ea1UQRvgHxBnk1/a6JuLjK5u3mlZ1SBn M5kzyes7j7mXE/4RaKJr40j51eW95qLCdEd08a7bzUwim4yMhl916jpTMeVeQokRwIvh keZg== X-Forwarded-Encrypted: i=1; AJvYcCU0lcYFduEGe02MpqD6GxJ/GsU3zajp95KMvQLO6o6Mu7B/UmPk9WAFuCk+mE7Y3UHNUWocPkfMijdVEYYg@lists.postgresql.org X-Gm-Message-State: AOJu0YyPUn52Ge64ynKYVpc9YbFL81iaWw8V7FDbGJkC5faEACN1M1qp xYdB3yagHpqTB/IX9ZFYrIQX3KVkS1NaQSRB/J3pxW2+pG+UB/6T X-Gm-Gg: ASbGncvQeAtrAd6n5kQNauVVAf18sPBQm2Jw1qeOZNlkgbCHhxO6lOezOuHBPEK+n7v QffsoZDr+cmL+h3MJhswYuRklGIVxVBDFIULyLp1eDVHaEg450j16tKGvoLd6fS0KmK6fmddfzk ii2dAViBs+EIOani1YCcqF5cx3oylxfWVNExyeQF2W10eI2jhjUR+mW6mOObnPcR+wVKNYrqKuN Hurhm6TTUx0WmPuwx62h8XIQYQFu96XFokjnKrCw1NDb0rx/B+mfIYFNFrMld+DghU3vyiyxVT9 ozBxiTmE5095qCym3Gaz4ZSty6aeDoctpEC348nt/SRiexuOotsLeHXxrT5bIdXEiUPQP505NBT P38Y0zfax2a5lSXFxrYwt73Psom8Scnk= X-Google-Smtp-Source: AGHT+IGrLpi5Kcs+rXl/T39W+ecuxRY5j5ti+RN/D7i4FHFpAEGOPCDN9QW5GxO2zBOlp4FBAx/OOQ== X-Received: by 2002:a05:6e02:160e:b0:3d4:4134:521a with SMTP id e9e14a558f8ab-3d9303cb2f6mr2284865ab.12.1745443544418; Wed, 23 Apr 2025 14:25:44 -0700 (PDT) Received: from nathan (162-195-168-172.lightspeed.stlsmo.sbcglobal.net. [162.195.168.172]) by smtp.gmail.com with ESMTPSA id 8926c6da1cb9f-4f6a3933e2asm3027374173.98.2025.04.23.14.25.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Apr 2025 14:25:43 -0700 (PDT) Date: Wed, 23 Apr 2025 16:25:41 -0500 From: Nathan Bossart To: Nisha Moond Cc: Euler Taveira , Michael Paquier , Amit Kapila , Alexander Lakhin , Tom Lane , "Jonathan S. Katz" , PostgreSQL Hackers Subject: Re: Large expressions in indexes can't be stored (non-TOASTable) Message-ID: References: <4c2a6100-738e-48cc-8a11-2d85f95ae0ed@app.fastmail.com> <18a111db-9f31-449c-a14b-61779a69f344@app.fastmail.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="JsS/Y9YpAk9vOtU8" Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --JsS/Y9YpAk9vOtU8 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Tue, Apr 22, 2025 at 12:21:01PM -0500, Nathan Bossart wrote: > On Tue, Apr 22, 2025 at 05:17:17PM +0530, Nisha Moond wrote: >> 5) As Euler pointed out, logical replication already has a built-in >> restriction for internally assigned origin names, limiting them to >> NAMEDATALEN. Given that, only the SQL function >> pg_replication_origin_create() is capable of creating longer origin >> names. Would it make sense to consider moving the check into >> pg_replication_origin_create() itself, since it seems redundant for >> all other callers? >> That said, if there's a possibility of future callers needing this >> restriction at a lower level, it may be reasonable to leave it as is. > > pg_replication_origin_create() might be a better place. After all, that's > where we're enforcing the name doesn't start with "pg_" and, for testing, > _does_ start with "regress_". Plus, it seems highly unlikely that any > other callers of replorigin_create() will ever provide names longer than > 512 bytes. Here is a new version of the patch with this change. -- nathan --JsS/Y9YpAk9vOtU8 Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v4-0001-Remove-pg_replication_origin-s-TOAST-table.patch" From 1ca6f9c2a4a3c9917bb4846a77d0b7eaf936b8b8 Mon Sep 17 00:00:00 2001 From: Nathan Bossart Date: Wed, 23 Apr 2025 16:21:22 -0500 Subject: [PATCH v4 1/1] Remove pg_replication_origin's TOAST table. Reviewed-by: Michael Paquier Reviewed-by: Amit Kapila Reviewed-by: Euler Taveira Reviewed-by: Nisha Moond Discussion: https://postgr.es/m/ZvMSUPOqUU-VNADN%40nathan --- doc/src/sgml/func.sgml | 1 + src/backend/catalog/catalog.c | 2 -- src/backend/replication/logical/origin.c | 12 ++++++++++++ src/include/catalog/pg_replication_origin.h | 2 -- src/include/replication/origin.h | 7 +++++++ src/test/regress/expected/misc_functions.out | 4 ++++ src/test/regress/expected/misc_sanity.out | 6 +++++- src/test/regress/sql/misc_functions.sql | 3 +++ src/test/regress/sql/misc_sanity.sql | 3 +++ 9 files changed, 35 insertions(+), 5 deletions(-) diff --git a/doc/src/sgml/func.sgml b/doc/src/sgml/func.sgml index 574a544d9fa..593e45495be 100644 --- a/doc/src/sgml/func.sgml +++ b/doc/src/sgml/func.sgml @@ -29941,6 +29941,7 @@ postgres=# SELECT '0/0'::pg_lsn + pd.segment_number * ps.setting::int + :offset Creates a replication origin with the given external name, and returns the internal ID assigned to it. + The name must be no longer than 512 bytes. diff --git a/src/backend/catalog/catalog.c b/src/backend/catalog/catalog.c index 60000bd0bc7..59caae8f1bc 100644 --- a/src/backend/catalog/catalog.c +++ b/src/backend/catalog/catalog.c @@ -346,8 +346,6 @@ IsSharedRelation(Oid relationId) relationId == PgDbRoleSettingToastIndex || relationId == PgParameterAclToastTable || relationId == PgParameterAclToastIndex || - relationId == PgReplicationOriginToastTable || - relationId == PgReplicationOriginToastIndex || relationId == PgShdescriptionToastTable || relationId == PgShdescriptionToastIndex || relationId == PgShseclabelToastTable || diff --git a/src/backend/replication/logical/origin.c b/src/backend/replication/logical/origin.c index 6583dd497da..e9629350cb0 100644 --- a/src/backend/replication/logical/origin.c +++ b/src/backend/replication/logical/origin.c @@ -1296,6 +1296,18 @@ pg_replication_origin_create(PG_FUNCTION_ARGS) elog(WARNING, "replication origins created by regression test cases should have names starting with \"regress_\""); #endif + /* + * To avoid needing a TOAST table for pg_replication_origin, we restrict + * replication origin names to 512 bytes. This should be more than enough + * for all practical use. + */ + if (strlen(name) > 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))); + roident = replorigin_create(name); pfree(name); diff --git a/src/include/catalog/pg_replication_origin.h b/src/include/catalog/pg_replication_origin.h index deb43065fe9..7ade8bbda39 100644 --- a/src/include/catalog/pg_replication_origin.h +++ b/src/include/catalog/pg_replication_origin.h @@ -54,8 +54,6 @@ CATALOG(pg_replication_origin,6000,ReplicationOriginRelationId) BKI_SHARED_RELAT typedef FormData_pg_replication_origin *Form_pg_replication_origin; -DECLARE_TOAST_WITH_MACRO(pg_replication_origin, 4181, 4182, PgReplicationOriginToastTable, PgReplicationOriginToastIndex); - DECLARE_UNIQUE_INDEX_PKEY(pg_replication_origin_roiident_index, 6001, ReplicationOriginIdentIndex, pg_replication_origin, btree(roident oid_ops)); DECLARE_UNIQUE_INDEX(pg_replication_origin_roname_index, 6002, ReplicationOriginNameIndex, pg_replication_origin, btree(roname text_ops)); diff --git a/src/include/replication/origin.h b/src/include/replication/origin.h index 9cb2248fa9f..29724c0dcae 100644 --- a/src/include/replication/origin.h +++ b/src/include/replication/origin.h @@ -33,6 +33,13 @@ typedef struct xl_replorigin_drop #define InvalidRepOriginId 0 #define DoNotReplicateId PG_UINT16_MAX +/* + * To avoid needing a TOAST table for pg_replication_origin, we restrict + * replication origin names to 512 bytes. This should be more than enough for + * all practical use. + */ +#define MAX_RONAME_LEN 512 + extern PGDLLIMPORT RepOriginId replorigin_session_origin; extern PGDLLIMPORT XLogRecPtr replorigin_session_origin_lsn; extern PGDLLIMPORT TimestampTz replorigin_session_origin_timestamp; diff --git a/src/test/regress/expected/misc_functions.out b/src/test/regress/expected/misc_functions.out index d3f5d16a672..3de32c3c7ef 100644 --- a/src/test/regress/expected/misc_functions.out +++ b/src/test/regress/expected/misc_functions.out @@ -914,3 +914,7 @@ SELECT test_relpath(); (1 row) +-- pg_replication_origin.roname length restriction +SELECT pg_replication_origin_create('regress_' || repeat('a', 505)); +ERROR: replication origin name is too long +DETAIL: Replication origin names must be no longer than 512 bytes. diff --git a/src/test/regress/expected/misc_sanity.out b/src/test/regress/expected/misc_sanity.out index b032a3f4761..0cb58311329 100644 --- a/src/test/regress/expected/misc_sanity.out +++ b/src/test/regress/expected/misc_sanity.out @@ -42,6 +42,9 @@ WHERE refclassid = 0 OR refobjid = 0 OR -- as user data by pg_upgrade, which would cause failures. -- 3. pg_authid, since its toast table cannot be accessed when it would be -- needed, i.e., during authentication before we've selected a database. +-- 4. pg_replication_origin, since its toast table would only be used for +-- replication origin names, which we can avoid with a reasonable length +-- restriction. SELECT relname, attname, atttypid::regtype FROM pg_class c JOIN pg_attribute a ON c.oid = attrelid WHERE c.oid < 16384 AND @@ -61,7 +64,8 @@ ORDER BY 1, 2; pg_class | relpartbound | pg_node_tree pg_largeobject | data | bytea pg_largeobject_metadata | lomacl | aclitem[] -(10 rows) + pg_replication_origin | roname | text +(11 rows) -- system catalogs without primary keys -- diff --git a/src/test/regress/sql/misc_functions.sql b/src/test/regress/sql/misc_functions.sql index aaebb298330..ea72a62dab7 100644 --- a/src/test/regress/sql/misc_functions.sql +++ b/src/test/regress/sql/misc_functions.sql @@ -411,3 +411,6 @@ CREATE FUNCTION test_relpath() AS :'regresslib' LANGUAGE C; SELECT test_relpath(); + +-- pg_replication_origin.roname length restriction +SELECT pg_replication_origin_create('regress_' || repeat('a', 505)); diff --git a/src/test/regress/sql/misc_sanity.sql b/src/test/regress/sql/misc_sanity.sql index 135793871b4..545b2b48989 100644 --- a/src/test/regress/sql/misc_sanity.sql +++ b/src/test/regress/sql/misc_sanity.sql @@ -45,6 +45,9 @@ WHERE refclassid = 0 OR refobjid = 0 OR -- as user data by pg_upgrade, which would cause failures. -- 3. pg_authid, since its toast table cannot be accessed when it would be -- needed, i.e., during authentication before we've selected a database. +-- 4. pg_replication_origin, since its toast table would only be used for +-- replication origin names, which we can avoid with a reasonable length +-- restriction. SELECT relname, attname, atttypid::regtype FROM pg_class c JOIN pg_attribute a ON c.oid = attrelid -- 2.39.5 (Apple Git-154) --JsS/Y9YpAk9vOtU8--