Re: BUG: pg_class.relchecks overflow, making table undroppable

From: Matthias van de Meent <boekewurm+postgres(at)gmail(dot)com>
To: Michael Paquier <michael(at)paquier(dot)xyz>
Cc: Bertrand Drouvot <bertranddrouvot(dot)pg(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Sivaprasad <sivaprasad(dot)postgres(at)gmail(dot)com>
Subject: Re: BUG: pg_class.relchecks overflow, making table undroppable
Date: 2026-09-25 12:33:57
Message-ID: CAEze2Why2Y5iBoTP=N6AEzOXuzzQ=HpD0tmhHsf6KDRKPW7cwg@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Fri, 25 Sept 2026 at 11:05, Michael Paquier <michael(at)paquier(dot)xyz> wrote:
>
> On Fri, Sep 25, 2026 at 08:41:38AM +0000, Bertrand Drouvot wrote:
> > Just a few comments:
> >
> > === 1
> >
> > It needs a rebase due to 926627bf902

Done

> > === 2
> >
> > + ereport(ERROR,
> > + errmsg("too many check constraints on relation \"%s\"",
> > + RelationGetQualifiedRelationName(rel)));
> >
> >
> > I think ERRCODE_PROGRAM_LIMIT_EXCEEDED would be appropriate here?

Done.

> > 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.
>
> Yeah, let's do that. That's unlikely but it would just be a waste and
> that's just switching the order of things.

Also done. Thanks for the fast replies.

Attached v3:

* Add errcode(PROGRAM_LIMIT_EXCEEDED) to the ereports.
* Use pg_add_s16_overflow() to detect the overflows.
This includes changing the type of local numchecks variables to
int16. SetRelationNumChecks's signature is unchanged.
* Move the overflow checks to before StoreRelCheck.
This saves one dirty tuple in catalog tables when that overflow happens.

Kind regards,

Matthias van de Meent
Databricks (https://www.databricks.com)

Attachment Content-Type Size
v3-0001-Enforce-the-pg_class.relchecks-limit.patch application/octet-stream 3.6 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message wenhui qiu 2026-09-25 12:34:53 Re: ZSTD TOAST compression, and an extensible compression method encoding
Previous Message Álvaro Herrera 2026-09-25 12:13:45 Re: REPACK (CONCURRENTLY) loses missing values of columns added without a rewrite