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 1u9W2a-002jfL-Tq for pgsql-hackers@arkaria.postgresql.org; Mon, 28 Apr 2025 21:29:29 +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 1u9W2Y-003K8J-KW for pgsql-hackers@arkaria.postgresql.org; Mon, 28 Apr 2025 21:29:27 +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 1u9W2Y-003K8B-76 for pgsql-hackers@lists.postgresql.org; Mon, 28 Apr 2025 21:29:27 +0000 Received: from mail-io1-xd31.google.com ([2607:f8b0:4864:20::d31]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1u9W2W-0004HZ-32 for pgsql-hackers@lists.postgresql.org; Mon, 28 Apr 2025 21:29:26 +0000 Received: by mail-io1-xd31.google.com with SMTP id ca18e2360f4ac-85dac9729c3so489502839f.2 for ; Mon, 28 Apr 2025 14:29:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1745875764; x=1746480564; 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=Q5bJn1XGJ4xFcXrnlA1RM1oSJfxSWbpDn7JKh3J5c6k=; b=GooI5ttzktLbYgB0T0ejQ62Wd7X6V/fpr8qlwEkBX1PybqKaagB3xq3cZRJf5FSlNB Lmhoe8mjQskQfDKjA2NZZJjDYdEqlNasyz87nptq40n4bKVTiLvI9zAohOLgG0g8WHy2 vPMnIC0jVLfFNwfYgJhmhUuvnzTUH5XtgVbJs9pScKRvs/djhj5h2gqnojJf4n5cd8ir 4rwfjLqzIfB23aI5U7yWPopDg0U6b5LaxSrqCqI9hGFSxvYBoCB4K0egEro7NDQnZ1yW Tsl0NNh4fa1dL5vEv9WG3XGWpgav9A39lBCDZzYHTySbHOI8oZvKoI+t5YT/bbpqWmAh 2gGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745875764; x=1746480564; 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=Q5bJn1XGJ4xFcXrnlA1RM1oSJfxSWbpDn7JKh3J5c6k=; b=GMv8QGlo+6JzYwyaWrvrHJLay8PG+ki9biSGtGD/JEp4EsljzroSMin2DTldCc39zw xXhfFKN/klGEDlclVcNoJZoKkLQuYDliO1p8DdEmdekcGa3JMs236N1ygBwqA0EfvTsW JB+FY2Y/sN1nM043fLUSxAtQhwdRSOgRMGNca+f1c8+M+HSOReptB515AlC+vXTh1Qll +StmX5D5vLdEMUwUDShIrDWSV3vsNQlq3P8R7tBczspk+axuOIZ+6GKO3K0oTT4j5Xr8 i/JXAGHiVp/NEh60qVS7A9EL9a2UeuRg7+rdolEsh3qDAydmqG4dGYp2R/mgxbM3UFuD d1tg== X-Forwarded-Encrypted: i=1; AJvYcCVTAkmGEoZ4IKytbuTMUI5chWxmDPvZTlp+DovsfSNoPXwEU4I+uDAVqoBvarnXAFt36xDEDrGWcr//IO0D@lists.postgresql.org X-Gm-Message-State: AOJu0YywZGd5tI46yxk63FwYwehPWOriwKRJzg/r8C/fDH6mMGcosbmh 5PLZezEmAjrIVrzTcXp0xHqO5wbgPsweucZz/yPO/hApL7LzGNA8 X-Gm-Gg: ASbGncto/56SFfA2ezIvZvdXsLCXPwmVs2+/PPMvuhtALIiW0qDY98KZgZTjBE/+8U3 mwyIgMtk7U/QSc+Ct0RDCjhVosQyCldLZSCqvr2zocktU57doSfuostUm+T0/y32gGMp7E+kdWd EgXJaq5Gp76bvcq2jixjjvlkHGwSpf2zM28p+VGopnyVFucfrGdEqjgSmIoBJiI1ASI4fHD5IMX vTjRb0rCAsQc9EQ9Scq//mQyFpANEjRniR7NAP1NeObt2A6kvi08ijZRIvhQlbn2hkSj31GtFDc 8/daQUo6zQePAjoIMkY4ZmhuC75jYIPYwjKBueH2wJdIwSrA0WrI/Gwud5WIZ5WNZJJZYn03GGF 0RxyVT70s8Jd6KqIlQ76axr0IEgUyY3I= X-Google-Smtp-Source: AGHT+IHEHF5KcNuvkG82tHEHa6ZLJ/ClhQSFOHBncrMFUS+DXUrb7xs06MlJi2mSSK87eO0xgweOZg== X-Received: by 2002:a05:6602:2748:b0:861:6f48:4a68 with SMTP id ca18e2360f4ac-8648ae28bddmr51869139f.3.1745875763930; Mon, 28 Apr 2025 14:29:23 -0700 (PDT) Received: from nathan (162-195-168-172.lightspeed.stlsmo.sbcglobal.net. [162.195.168.172]) by smtp.gmail.com with ESMTPSA id ca18e2360f4ac-864519d2370sm190503739f.30.2025.04.28.14.29.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Apr 2025 14:29:23 -0700 (PDT) Date: Mon, 28 Apr 2025 16:29:21 -0500 From: Nathan Bossart To: Tom Lane Cc: Nisha Moond , Euler Taveira , Michael Paquier , Amit Kapila , Alexander Lakhin , "Jonathan S. Katz" , PostgreSQL Hackers Subject: Re: Large expressions in indexes can't be stored (non-TOASTable) Message-ID: References: <18a111db-9f31-449c-a14b-61779a69f344@app.fastmail.com> <1503201.1745444021@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="A0mE2VZksvkn1UEq" Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --A0mE2VZksvkn1UEq Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Wed, Apr 23, 2025 at 04:44:51PM -0500, Nathan Bossart wrote: > On Wed, Apr 23, 2025 at 05:33:41PM -0400, Tom Lane wrote: >> I don't see any comments in this patch that capture the real >> reason for removing pg_replication_origin's TOAST table, >> namely (IIUC) that we'd like to be able to access that catalog >> without a snapshot. I think it's important to record that >> knowledge, because otherwise somebody is likely to think they >> can undo this change for $whatever-reason. > > D'oh, yes, I'd better add that. I updated the comment atop the check in the misc_sanity test for system tables with varlena columns but no toast table. If you were to reintroduce pg_replication_origin's toast table, you'd have to at least fix the expected output for this test, so the comment theoretically has a higher chance of being seen. -- nathan --A0mE2VZksvkn1UEq Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v5-0001-Remove-pg_replication_origin-s-TOAST-table.patch" From 2d7e89e4ec49b1156b33b11219dbf403aefc5466 Mon Sep 17 00:00:00 2001 From: Nathan Bossart Date: Mon, 28 Apr 2025 16:27:33 -0500 Subject: [PATCH v5 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 Reviewed-by: Tom Lane 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 | 7 ++++++- src/test/regress/sql/misc_functions.sql | 3 +++ src/test/regress/sql/misc_sanity.sql | 4 ++++ 9 files changed, 37 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..b0b76fe3d9a 100644 --- a/src/test/regress/expected/misc_sanity.out +++ b/src/test/regress/expected/misc_sanity.out @@ -42,6 +42,10 @@ 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 we want to be able to access that catalog +-- without setting up a snapshot. As of this writing, 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 +65,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..86c193a0c42 100644 --- a/src/test/regress/sql/misc_sanity.sql +++ b/src/test/regress/sql/misc_sanity.sql @@ -45,6 +45,10 @@ 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 we want to be able to access that catalog +-- without setting up a snapshot. As of this writing, 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) --A0mE2VZksvkn1UEq--