Re: Disable unique constraint in Postgres

From: Ron <ronljohnsonjr(at)gmail(dot)com>
To: pgsql-admin(at)lists(dot)postgresql(dot)org
Subject: Re: Disable unique constraint in Postgres
Date: 2022-11-27 21:23:22
Message-ID: ed261f0d-2d2c-3d40-7963-8d44defd8a40@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

On 11/27/22 10:58, Scott Ribe wrote:
>> On Nov 27, 2022, at 9:51 AM, Samed YILDIRIM<samed(at)reddoc(dot)net> wrote:
>>
>> Important point is why you want to disable a unique constraint.
>> • If you want to add some duplicate rows into a table, you try to do something fundamentally wrong.
> Even more so: why is disabling superior to dropping???
>
> It is at most an extremely minor convenience to be able to re-enable it without having to re-create it, in that you can, presumably, just re-enable by name without specifying the constraint details. In other words, in my opinion, it is a virtually worthless feature. (Typical "enterprise software" feature creep.)

Being an "enterprise dba", IMNSHO "disable constraint" (and more
specifically "*disable index*") is a /great/ feature for maintaining
tables.  For example, if you need to purge a *lot* of records into a table,
disable all indices except the index supporting your WHERE CLAUSE, delete
the data, and then re-enable the indices.  Bonus points if the REENABLE
commands can be done in parallel.

Sure, you /can/ dig around for all of the CREATE INDEX statements, but that
leads to possible errors: "oops, forgot to recreate one of them", or "typo
caused one to fail".  OTOH, DISABLE INDEX and REENABLE INDEX are
idiot-proof, and can be automated.

--
Angular momentum makes the world go 'round.

In response to

Responses

Browse pgsql-admin by date

  From Date Subject
Next Message Mladen Gogala 2022-11-27 21:56:03 Re: Disable unique constraint in Postgres
Previous Message Jeff Janes 2022-11-27 18:15:43 Re: Question about cert authentication method.