pgsql: Enforce pg_class.relchecks limit (32,767 or INT16_MAX)

From: Michael Paquier <michael(at)paquier(dot)xyz>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Enforce pg_class.relchecks limit (32,767 or INT16_MAX)
Date: 2026-09-27 21:55:38
Message-ID: E1xAwqQ-00000001WCB-3Yby@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Enforce pg_class.relchecks limit (32,767 or INT16_MAX)

pg_class.relchecks reports the number of CHECK constraints in a table,
and is stored within a smallint. It was possible to define a table that
could overflow the counter when specifying more than 32k constraints
(new table or adding a constraint). This would cause the table to
become undroppable, as this counter should never be negative when
dropping these constraints.

Author: Matthias van de Meent <boekewurm+postgres(at)gmail(dot)com>
Reviewed-by: Bertrand Drouvot <bertranddrouvot(dot)pg(at)gmail(dot)com>
Reviewed-by: Jian He <jian(dot)universality(at)gmail(dot)com>
Reviewed-by: Sivaprasad <sivaprasad(dot)postgres(at)gmail(dot)com>
Discussion: https://postgr.es/m/CAEze2WjSW4qaHYnvkTtbknp85eGEirGJTLMZatotdJJKiA+_hA@mail.gmail.com
Backpatch-through: 14

Branch
------
REL_19_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/b80d5b17ea3cff60370e08983546bd7b1e4298bd

Modified Files
--------------
doc/src/sgml/limits.sgml | 7 +++++++
src/backend/catalog/heap.c | 28 +++++++++++++++++++++++-----
2 files changed, 30 insertions(+), 5 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Previous Message Tom Lane 2026-09-26 16:56:41 pgsql: Don't emit garbage "\[un]restrict (null)" commands in pg_dump.