pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Milos Babic <milos.babic@gmail.com>
To: Nagaraj Raj <nagaraj.sf@yahoo.com>
Cc: Pgsql Performance <pgsql-performance@lists.postgresql.org>
Subject: Re: Temporarily disable not null constraints
Date: Thu, 3 Dec 2020 21:13:46 +0100
Message-ID: <CAPVD16t0UPFiSPJrpefObeU5c60BEhxP7SuA-dPHGAcHSChZwg@mail.gmail.com> (raw)
In-Reply-To: <815507272.4135293.1607025495638@mail.yahoo.com>
References: <815507272.4135293.1607025495638.ref@mail.yahoo.com>
	<815507272.4135293.1607025495638@mail.yahoo.com>

generally, you shouldn't be disabling your constraints, especially if you
are having multiple parallel processes accessing your db.
instead, you should create them DEFERRABLE and have them checked at the end
of your transaction.

regarding your question about NOT NULL: it is not possible to have it
deferred (please check this page:
https://www.postgresql.org/docs/13/sql-set-constraints.html)
you may alter your column, remove it, and then get it back, but still all
rows will have to be checked, which I doubt you would like to see on a
large table.

regards, milos



On Thu, Dec 3, 2020 at 9:00 PM Nagaraj Raj <nagaraj.sf@yahoo.com> wrote:

> Hi,
>
> Can we disable not null constraints temporarily in the session-based
> transaction, like we disable FK constraints?
>
> SET session_replication_role = ‘replica’;
> alter table table_name disable trigger user;”
>
> above two options are working for unique constraints violation exception.
>
> Thanks,
> Rj
>

view thread (4+ messages)  latest in thread

Message-ID: <CAPVD16t0UPFiSPJrpefObeU5c60BEhxP7SuA-dPHGAcHSChZwg@mail.gmail.com>
Permalink:  ../CAPVD16t0UPFiSPJrpefObeU5c60BEhxP7SuA-dPHGAcHSChZwg@mail.gmail.com/
Also on:    postgresql.org/message-id/CAPVD16t0UPFiSPJrpefObeU5c60BEhxP7SuA-dPHGAcHSChZwg@mail.gmail.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-performance@postgresql.org
  Cc: milos.babic@gmail.com, nagaraj.sf@yahoo.com, pgsql-performance@lists.postgresql.org
  Subject: Re: Temporarily disable not null constraints
  In-Reply-To: <CAPVD16t0UPFiSPJrpefObeU5c60BEhxP7SuA-dPHGAcHSChZwg@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox