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.98.2) (envelope-from ) id 1xA1V3-00000002PQB-1M41 for pgsql-hackers@arkaria.postgresql.org; Fri, 25 Sep 2026 08:41:45 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.98.2) (envelope-from ) id 1xA1V2-0000000HOhv-2W0U for pgsql-hackers@arkaria.postgresql.org; Fri, 25 Sep 2026 08:41:44 +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.98.2) (envelope-from ) id 1xA1V2-0000000HOfN-0zth for pgsql-hackers@lists.postgresql.org; Fri, 25 Sep 2026 08:41:44 +0000 Received: from mail-wm2-x10.google.com ([2a00:1450:4864:31::10]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1xA1Uz-00000001AaE-2GhC for pgsql-hackers@lists.postgresql.org; Fri, 25 Sep 2026 08:41:43 +0000 Received: by mail-wm2-x10.google.com with SMTP id 5b1f17b1804b1-49e620fa473so3938815e9.1 for ; Fri, 25 Sep 2026 01:41:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1790325701; x=1790930501; darn=lists.postgresql.org; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to:content-type; bh=2udk6O79U8xjjGwAN02mqLGFwhSkm7QHvFK8O1NQl04=; b=R73/mbNP0Djr7TXQAiLag8vT5RPtsMsqYweKrVzg2dV/qFQCh3I0402ga3RmkYKauw 9W2/IzJxjz1g+XgRaJyc6YJrMtfTDvYalytKT33Xht3QFeIYrxMZaBe/6Acv4XZQtYep qnz1ybOj1SFAsrR2J13uqBoWSdGWQNOi1nBDTo2UZWKHBpWXss4UdC2eeMHWXEMrUeVs TuQ9aiOHATMJ2aOyahVBxohh9Ffd5tdQpVzZLwhRi+sK9y8XRcRBQfdtQGg81Rqxnswz MRJkc7s5uC5I8d7NFgRFUE6FMfu8NZvkZBE5ogdXI/Y2KT9VJaj9mGdQNnQ5yPnzBGa/ vojw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1790325701; x=1790930501; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=2udk6O79U8xjjGwAN02mqLGFwhSkm7QHvFK8O1NQl04=; b=q2BuBISwdrq5+FpIgGqJ41YVOl4+FGuMzD+DOSkrMsQ2lPjU960/kJQJg10t2iVEaH a8NrO0MWaRQ8NPmFSkII7J0khhk67+SWxKUg3N5W7z2nvUD4Fw2q71qdUr5sXsWaQur3 XzYQrBgvgkYOXMPUgm6Wl7OSymPadicJSvQHZ3yYWOibshlM5s7Pe+ZWwoqunsamyF+h MseaKlBqjmc+fBy8dA9T7B28QQi+rN8cBguQ+y5hVNV2kqv5l5Tyba0NThGDB5aPBL2m CfQs4EF0bP3RL5ybVRH7Mo19nDrg6rzNKK76K+9sTz/V+F9P4lz7lSK+WNtf/k4w4txM gnMQ== X-Forwarded-Encrypted: i=1; AKwUvBzoad+qp1mPXF3NxYjQE4SjxJ3rUX4gD/r5RLKlzXZ0yvYAQEBcPJ1dSJwU5v/xV/lXewGypqZ2FzTJC8Lp@lists.postgresql.org X-Gm-Message-State: AFuF++mNfo0Olt+y4gWH/t9G29vSo8HhNsZ+wDuEWaot2chR26gJT6t2 lfqP0ov7qAVi4Py89r7RoMULU7G5XeG5RcLtg2jqOvO9lpfvBFcsofnZ X-Gm-Gg: AYBFou3XOJg1r3Uvh0TMjsYil5qvGVCsQm1Fm/6Pd40mSnTMAGm3X6F4wCbyX7VkJ2x g9Rnv+e23v9AZmfpyGo+e3SbNKBw58olULESs9zZ8zKhbsIIwoKmPFT7a+LUzkmFkb1H401y5g+ 3aE9yrGSzd1+LE/bjVkJ6UQCJk4mUl4JXaTWBp2u5EisAhn/NQva12cHqktPADWg8TNr5UfIdYj U+eSOouGugaZjXuo6dQEHjXfgBOJJ5O09IFTqyKgHanjXqznw6qyhrjt2yLl0mU1m1h1ybJziZb HMbSN9aIu0Dzk1y5uib7LgOEOldoahD4SDBM5zrvn2qy3OFqsetLABjxBf90xAwJCocf3NOxK+E zQG6qnbOIxMlCTWIzfoMdHSLMPmK0WXTyAam9V7nAbBbNniFvDv6tMOAWSIIX1pMU34nMgjHMgJ uNJOVojiPZdLy76y+XJmPYg+Hydy/ST1qsjUkhbQb5nh+wm9NYOC0dYgTaiSiSWLirliDIKoWQS rZVy5nyzPs2M2sJaz1im3F6j4IrlZ+c7Gv3KU/xH0w5nJeFu/4/P+XBSw== X-Received: by 2002:a05:600c:19c7:b0:49c:fc6c:be09 with SMTP id 5b1f17b1804b1-49ff06f83edmr25819195e9.32.1790325700498; Fri, 25 Sep 2026 01:41:40 -0700 (PDT) Received: from bdtpg (ec2-15-237-197-144.eu-west-3.compute.amazonaws.com. [15.237.197.144]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-49fe5df44f9sm122926955e9.11.2026.09.25.01.41.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Sep 2026 01:41:40 -0700 (PDT) Date: Fri, 25 Sep 2026 08:41:38 +0000 From: Bertrand Drouvot To: Michael Paquier Cc: Matthias van de Meent , PostgreSQL Hackers Subject: Re: BUG: pg_class.relchecks overflow, making table undroppable Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, On Fri, Sep 25, 2026 at 07:59:22AM +0900, Michael Paquier wrote: > On Thu, Sep 24, 2026 at 07:03:45PM +0200, Matthias van de Meent wrote: > > This causes various issues, such as possible WARNING spam to users > > that need to load that relation into relcache, and an inability to > > drop the relation because dropping the table requires the constraints > > to be dropped first, and dropping a constraint decrements the counter > > that has a check is in place to avoid the counter ever dropping below > > zero (with an error if you try to decrement non-positive counter > > values). > > > > I think we should forbid creating such large amounts of CHECK > > constraints (as attached, backpatch-safe), or drop the "relchecks" > > field wholesale/replace it with a 'haschecks' field. > > > > Also attached is an SQL script that shows the issue, and which doesn't > > fail in the unsafe manner once PG is patched with the attached patch. > > Ahah, fun one! That's in the same line as the recent trigger fix in > b99b74144f9f where catalogs could overflow. Even if it's something > that people would not do in practice, this deserves a backpatch. +1 Just a few comments: === 1 It needs a rebase due to 926627bf902 === 2 + ereport(ERROR, + errmsg("too many check constraints on relation \"%s\"", + RelationGetQualifiedRelationName(rel))); I think ERRCODE_PROGRAM_LIMIT_EXCEEDED would be appropriate here? === 3 numchecks++; + + if (numchecks >= PG_INT16_MAX) + ereport(ERROR, + errmsg("too many check constraints on relation \"%s\"", + RelationGetQualifiedRelationName(rel))); I wonder if it wouldn't make more sense to check numchecks >= PG_INT16_MAX before calling StoreRelCheck()? That would avoid inserting the constraint, recording its dependencies and invoking the post create hook for an object that will be rejected. Regards, -- Bertrand Drouvot PostgreSQL Contributors Team RDS Open Source Databases Amazon Web Services: https://aws.amazon.com