Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1j1wfs-0003BF-02 for pgsql-hackers@arkaria.postgresql.org; Wed, 12 Feb 2020 18:23:48 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1j1wfp-00005X-PC for pgsql-hackers@arkaria.postgresql.org; Wed, 12 Feb 2020 18:23:45 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1j1wfp-00005L-Bn for pgsql-hackers@lists.postgresql.org; Wed, 12 Feb 2020 18:23:45 +0000 Received: from mail-yb1-xb44.google.com ([2607:f8b0:4864:20::b44]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1j1wfl-0003sd-EU for pgsql-hackers@postgresql.org; Wed, 12 Feb 2020 18:23:44 +0000 Received: by mail-yb1-xb44.google.com with SMTP id f21so1540805ybg.11 for ; Wed, 12 Feb 2020 10:23:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telsasoft-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :user-agent; bh=lnM9fYD/I2a5kZEZSLJAmxYpwuYtzKzKQnTxQnHGF4o=; b=bVSP+j2xbinS4kybmrIz+GDuzQGh79rUugNfWQRS0aqbf75ILOfHrj75bDbhdQEGVg F1J8ijqysTW9mJkNgqCNkTf+0yFgmvcB3er9sMyE/EcmF5GDarBP8q02zRE2TR9EQuoF b6uoCblFMM0oc5M7ak5TjouF/rUa+UXPW0JPdolVTOKG9mtH++563maBELdjDgxo0rSR ps/J9oLxDBErOWKJnO1nFXgtxeWrkW0b8/y8hVsnLuXK3KArbCO/azL1P3Bp09J/SRpF poKVJUes+/ECQXaXcAn7vjjwkv73lttImqkRsFQImziakDf9xsX921cjxNqP8Qt5d55x A0ZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:user-agent; bh=lnM9fYD/I2a5kZEZSLJAmxYpwuYtzKzKQnTxQnHGF4o=; b=HjORiZ0ZAyl/elJPnz15+cfxodRL9ECdVeWB1JdGCedPWZZVuVz5BYUEGho+kuf7sZ j5zfI/3aFw3MQhoWoZZh660sEeW1CJJaG08nTlXh+VAAgk9E3IvZEsizyZEKEXfVYYPy nDXqFJd3hhqwoh0LPyIBEiQxqDhYGVWwADHVU/vLtOGF2JyOwkLNLQiijFl4HuZyGALV Zz3RwOPuTa+m+PX/SJme7yOOHh9SK3ourjRwBiqF03RKcNTEYJfcH9Xs11kQGmR2WuaQ jXS5um7QYjtU9K4ADCCddJs3Qfaj3gOxFLIZ/i6JeQLR5R/f6AYdVplKAZQBdK7rUzMB GycA== X-Gm-Message-State: APjAAAV6H0u2Yo8hU/K4Cw++dvnGuf3a8IH/qxQ7hMsx2Q+Vh++wt/Tp Jn0bmALDl1ZxLpPWgBLnGJucFQ== X-Google-Smtp-Source: APXvYqw6oT/8DyCfpJ7cLt9+p027OWzQiXw8nweGVkwwUbAbIy/XIkaEI+yivoTHbt3LjNRCmaYixw== X-Received: by 2002:a25:cbc9:: with SMTP id b192mr8455660ybg.480.1581531819334; Wed, 12 Feb 2020 10:23:39 -0800 (PST) Received: from pryzbyj (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id q16sm482954ywa.110.2020.02.12.10.23.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 12 Feb 2020 10:23:38 -0800 (PST) Received: by pryzbyj (Postfix, from userid 1000) id 4433E800926; Wed, 12 Feb 2020 12:23:37 -0600 (CST) Date: Wed, 12 Feb 2020 12:23:37 -0600 From: Justin Pryzby To: Alvaro Herrera Cc: Amit Langote , pgsql-hackers@postgresql.org Subject: assert pg_class.relnatts is consistent Message-ID: <20200212182337.GZ1412@telsasoft.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="TB36FDmn/VVEgNH/" Content-Disposition: inline User-Agent: Mutt/1.5.24 (2015-08-30) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --TB36FDmn/VVEgNH/ Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Forking this thread for two tangential patches which I think are more worthwhile than the original topic's patch. https://www.postgresql.org/message-id/20200207143935.GP403%40telsasoft.com Is there a better place to implement assertion from 0002 ? On Fri, Feb 07, 2020 at 08:39:35AM -0600, Justin Pryzby wrote: > From 7eea0a17e495fe13379ffd589b551f2f145f5672 Mon Sep 17 00:00:00 2001 > From: Justin Pryzby > Date: Thu, 6 Feb 2020 21:48:13 -0600 > Subject: [PATCH v1 1/3] Update comment obsolete since b9b8831a > > --- > src/backend/commands/cluster.c | 6 +++--- > 1 file changed, 3 insertions(+), 3 deletions(-) > > diff --git a/src/backend/commands/cluster.c b/src/backend/commands/cluster.c > index e9d7a7f..3adcbeb 100644 > --- a/src/backend/commands/cluster.c > +++ b/src/backend/commands/cluster.c > @@ -1539,9 +1539,9 @@ get_tables_to_cluster(MemoryContext cluster_context) > > /* > * Get all indexes that have indisclustered set and are owned by > - * appropriate user. System relations or nailed-in relations cannot ever > - * have indisclustered set, because CLUSTER will refuse to set it when > - * called with one of them as argument. > + * appropriate user. Shared relations cannot ever have indisclustered > + * set, because CLUSTER will refuse to set it when called with one as > + * an argument. > */ > indRelation = table_open(IndexRelationId, AccessShareLock); > ScanKeyInit(&entry, > -- > 2.7.4 > > From 4777be522a7aa8b8c77b13f765cbd02043438f2a Mon Sep 17 00:00:00 2001 > From: Justin Pryzby > Date: Fri, 7 Feb 2020 08:12:50 -0600 > Subject: [PATCH v1 2/3] Give developer a helpful kick in the pants if they > change natts in one place but not another > > --- > src/backend/bootstrap/bootstrap.c | 23 +++++++++++++++++++++++ > 1 file changed, 23 insertions(+) > > diff --git a/src/backend/bootstrap/bootstrap.c b/src/backend/bootstrap/bootstrap.c > index bfc629c..d5e1888 100644 > --- a/src/backend/bootstrap/bootstrap.c > +++ b/src/backend/bootstrap/bootstrap.c > @@ -25,7 +25,9 @@ > #include "access/xlog_internal.h" > #include "bootstrap/bootstrap.h" > #include "catalog/index.h" > +#include "catalog/pg_class.h" > #include "catalog/pg_collation.h" > +#include "catalog/pg_proc.h" > #include "catalog/pg_type.h" > #include "common/link-canary.h" > #include "libpq/pqsignal.h" > @@ -49,6 +51,7 @@ > #include "utils/ps_status.h" > #include "utils/rel.h" > #include "utils/relmapper.h" > +#include "utils/syscache.h" > > uint32 bootstrap_data_checksum_version = 0; /* No checksum */ > > @@ -602,6 +605,26 @@ boot_openrel(char *relname) > TableScanDesc scan; > HeapTuple tup; > > + /* Check that pg_class data is consistent now, rather than failing obscurely later */ > + struct { Oid oid; int natts; } > + checknatts[] = { > + {RelationRelationId, Natts_pg_class,}, > + {TypeRelationId, Natts_pg_type,}, > + {AttributeRelationId, Natts_pg_attribute,}, > + {ProcedureRelationId, Natts_pg_proc,}, > + }; > + > + for (int i=0; i + Form_pg_class classForm; > + HeapTuple tuple; > + tuple = SearchSysCache1(RELOID, ObjectIdGetDatum(checknatts[i].oid)); > + if (!HeapTupleIsValid(tuple)) > + elog(ERROR, "cache lookup failed for relation %u", checknatts[i].oid); > + classForm = (Form_pg_class) GETSTRUCT(tuple); > + Assert(checknatts[i].natts == classForm->relnatts); > + ReleaseSysCache(tuple); > + } > + > if (strlen(relname) >= NAMEDATALEN) > relname[NAMEDATALEN - 1] = '\0'; > > -- > 2.7.4 > --TB36FDmn/VVEgNH/ Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v1-0002-Give-developer-a-helpful-kick-in-the-pants-if-the.patch" From 4777be522a7aa8b8c77b13f765cbd02043438f2a Mon Sep 17 00:00:00 2001 From: Justin Pryzby Date: Fri, 7 Feb 2020 08:12:50 -0600 Subject: [PATCH v1 2/3] Give developer a helpful kick in the pants if they change natts in one place but not another --- src/backend/bootstrap/bootstrap.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/backend/bootstrap/bootstrap.c b/src/backend/bootstrap/bootstrap.c index bfc629c..d5e1888 100644 --- a/src/backend/bootstrap/bootstrap.c +++ b/src/backend/bootstrap/bootstrap.c @@ -25,7 +25,9 @@ #include "access/xlog_internal.h" #include "bootstrap/bootstrap.h" #include "catalog/index.h" +#include "catalog/pg_class.h" #include "catalog/pg_collation.h" +#include "catalog/pg_proc.h" #include "catalog/pg_type.h" #include "common/link-canary.h" #include "libpq/pqsignal.h" @@ -49,6 +51,7 @@ #include "utils/ps_status.h" #include "utils/rel.h" #include "utils/relmapper.h" +#include "utils/syscache.h" uint32 bootstrap_data_checksum_version = 0; /* No checksum */ @@ -602,6 +605,26 @@ boot_openrel(char *relname) TableScanDesc scan; HeapTuple tup; + /* Check that pg_class data is consistent now, rather than failing obscurely later */ + struct { Oid oid; int natts; } + checknatts[] = { + {RelationRelationId, Natts_pg_class,}, + {TypeRelationId, Natts_pg_type,}, + {AttributeRelationId, Natts_pg_attribute,}, + {ProcedureRelationId, Natts_pg_proc,}, + }; + + for (int i=0; irelnatts); + ReleaseSysCache(tuple); + } + if (strlen(relname) >= NAMEDATALEN) relname[NAMEDATALEN - 1] = '\0'; -- 2.7.4 --TB36FDmn/VVEgNH/--