Re: Fix ALTER DOMAIN VALIDATE CONSTRAINT locking

From: Fujii Masao <masao(dot)fujii(at)gmail(dot)com>
To: Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com>
Cc: Postgres hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Peter Eisentraut <peter(at)eisentraut(dot)org>, jian he <jian(dot)universality(at)gmail(dot)com>
Subject: Re: Fix ALTER DOMAIN VALIDATE CONSTRAINT locking
Date: 2026-06-12 11:47:28
Message-ID: CAHGQGwFPO2DE3y1vL6XOOaKEu=TGVNS5+VbJN+PpRDMLxh8Z-g@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Mon, Jun 8, 2026 at 12:54 PM Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com> wrote:
> See the attached patch for details. I also added an isolation test that follows the repro above.

Thanks for the patch! It looks good to me.

I just have a few minor review comments.

* The lockmode is used for relations using the domain. It should be
* ShareLock when adding a new constraint to domain. It can be
* ShareUpdateExclusiveLock when validating an existing constraint.

This comment in validateDomainCheckConstraint() still references
ShareUpdateExclusiveLock, so it seems to need updating.

Regarding the test, I think it would be safer to also check whether
pg_constraint.convalidated is set correctly. For example:

-----------------------
step s3_validate { ALTER DOMAIN alter_domain_validate_d VALIDATE
CONSTRAINT alter_domain_validate_d_pos; }
+step s3_validated { SELECT convalidated FROM pg_constraint WHERE
conname = 'alter_domain_validate_d_pos'; }
step s3_check { SELECT count(*) FROM alter_domain_validate_t; }

-permutation s1_lock s2_insert s3_add s3_validate s1_unlock s3_check
+permutation s1_lock s2_insert s3_add s3_validate s1_unlock s3_validated s3_chec
-----------------------

After the fix is committed, we should probably also ask Bruce to update
the following v19 release note item?:

Reduce lock level of ALTER DOMAIN ... VALIDATE CONSTRAINT to match
ALTER TABLE ... VALIDATE CONSTRAINT (Jian He) §

Regards,

--
Fujii Masao

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Álvaro Herrera 2026-06-12 12:26:25 Re: Redundant/mis-use of _(x) gettext macro?
Previous Message Alvaro Herrera 2026-06-12 11:40:30 Re: REPACK CONCURRENTLY fails on tables with generated columns