Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kkuzr-0002Ah-HU for pgsql-performance@arkaria.postgresql.org; Thu, 03 Dec 2020 20:14:35 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kkuzo-00007s-B3 for pgsql-performance@arkaria.postgresql.org; Thu, 03 Dec 2020 20:14:32 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kkuzo-00007l-17 for pgsql-performance@lists.postgresql.org; Thu, 03 Dec 2020 20:14:32 +0000 Received: from mail-wm1-x32b.google.com ([2a00:1450:4864:20::32b]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kkuzg-0007yD-OC for pgsql-performance@lists.postgresql.org; Thu, 03 Dec 2020 20:14:31 +0000 Received: by mail-wm1-x32b.google.com with SMTP id 3so5111328wmg.4 for ; Thu, 03 Dec 2020 12:14:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=EkUZiQhUsOa6GdB9xdbqWjhOGO9z5Mv6apCcPtkYVG0=; b=qycs6RZrHH+f8a71yv17a6VWE5NRXD4JhB1OuqjC0/9dym06YjyyynpCP7DQ4UyAGD MXpRvMnSz+xlmZUQCtho1q8VJfi6Xo8CAp+h/FDpxJy5Nqf1CjPHwlJ4i6CmRMbd/Ubq yy81Hr+c//Fe+MzeOcPbZPekcdk0pgH2MzhcmspHRWgVQW+uuUc8kmi3VrfGpJL9KfIV b4Nul3fhWQ1AMYFBOpInc/XdnbbnEUhKRncKFXuIu/LmxKKWjycwn00NoQ00lM/B8c+O ei8moFSe00TbW9HPzypHyJZAwnLul3bFXdQk+6RVod2cXqPXclNwtZKS6HpTpG7Wemqo F3UQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=EkUZiQhUsOa6GdB9xdbqWjhOGO9z5Mv6apCcPtkYVG0=; b=elr14swezf1iJESMMQwG7Bf+t+P7qwu21XeqlsK/8ujCUF1z94Xwx5maMypOz2MzM0 jdhXi1dDZYvfjn5exIdfF+CVja92WqYI3XN+lxPeMc9tvDBCHNKlez3Gku5u9TrFVjaJ JLKi/OKV4iPbLBdj6xZulwvRvQTTYVgemk8ndPfcHHzuNeTl+mFPoX5x+1Tv6P9twxkt 7QYoD71t1TQtjrvoNKtNo2hCj9CIBp75gue1DjlckxzA9/IlMV5lCvCo8HHX7Bk+PQDz q1bXu/vFv4r4OGLiJTFTsdHEckzMsODj/RbIIffrfUkuHXdehbw1ng3JDjPGTDVKT0Xk Tn0w== X-Gm-Message-State: AOAM53222TPtOD0Neqf13fvxEllzXwrPJUm77W2H2XMGbvxWTCSSQ8jU plVBYtNSGv35x5lNJIi/yC4Cf/nEyp229lM7M0g= X-Google-Smtp-Source: ABdhPJwQz3S/OG1S2QW8TdUu0GkeAuFJbGLK+z/7fbwSey17px2HPi7O5iFy4lZknpmg3AMJc3LAEhNr+U5F8rWm6K8= X-Received: by 2002:a1c:b657:: with SMTP id g84mr501703wmf.181.1607026462078; Thu, 03 Dec 2020 12:14:22 -0800 (PST) MIME-Version: 1.0 References: <815507272.4135293.1607025495638.ref@mail.yahoo.com> <815507272.4135293.1607025495638@mail.yahoo.com> In-Reply-To: <815507272.4135293.1607025495638@mail.yahoo.com> From: Milos Babic Date: Thu, 3 Dec 2020 21:13:46 +0100 Message-ID: Subject: Re: Temporarily disable not null constraints To: Nagaraj Raj Cc: Pgsql Performance Content-Type: multipart/alternative; boundary="0000000000006abdd305b5950182" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --0000000000006abdd305b5950182 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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 wrote: > Hi, > > Can we disable not null constraints temporarily in the session-based > transaction, like we disable FK constraints? > > SET session_replication_role =3D =E2=80=98replica=E2=80=99; > alter table table_name disable trigger user;=E2=80=9D > > above two options are working for unique constraints violation exception. > > Thanks, > Rj > --0000000000006abdd305b5950182 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
generally, you shouldn't be disa= bling your constraints, especially if you are having multiple parallel proc= esses 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 defe= rred (please check this page: https://www.postgresql.org/docs/13/sql-set-const= raints.html)
you may alter your column, remove it, and then g= et it back, but still all rows will have to be checked, which I doubt you w= ould like to see on a large table.

regards, milos<= /div>



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

Can we disable not null constraints tempora= rily in the session-based transaction, like we disable FK constraints?=C2= =A0

SET session_replication_role =3D =E2=80=98replica=E2=80=99;=C2=A0=
alter table table_name disable trigger user;=E2=80=9D

above = two options are working for unique constraints violation exception.=C2=A0

= Thanks,
Rj


--0000000000006abdd305b5950182--