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 1ozP7b-0000cr-C7 for pgsql-admin@arkaria.postgresql.org; Sun, 27 Nov 2022 21:23:31 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1ozP7Y-0006UR-Al for pgsql-admin@arkaria.postgresql.org; Sun, 27 Nov 2022 21:23:28 +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 1ozP7X-0006UI-T4 for pgsql-admin@lists.postgresql.org; Sun, 27 Nov 2022 21:23:27 +0000 Received: from mail-qk1-x734.google.com ([2607:f8b0:4864:20::734]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1ozP7V-0007bz-HD for pgsql-admin@lists.postgresql.org; Sun, 27 Nov 2022 21:23:26 +0000 Received: by mail-qk1-x734.google.com with SMTP id i9so6044815qkl.5 for ; Sun, 27 Nov 2022 13:23:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=in-reply-to:from:references:to:content-language:subject:user-agent :mime-version:date:message-id:from:to:cc:subject:date:message-id :reply-to; bh=uN5JFDo5xPs/45DJjJCVInyhRtqYKY+HaCGjzHt49GI=; b=dxVMPRUUAF1ps2v64dm4JHkTrrZyqcAKxrK9ZNntPTbUhGitqHHPGb70Qh370EDqZm SE1Qr10ffcLNCMFWxH76aSsBtDQw+blsTA3B3OspEZmmjPiXdRVG5lmL3BGcPipwjnkK fdWzvKrk6axUOW1pgRMz41kx4Vzp4wvmAs5AJKL3Ie1YYw4BWYLbRSqBkJP6YlmY7IQw MqqYaeJlaym+ynWdOJMMCTn6pFa8avnu/3gAal7brosTeHNvwAXumxXujKUvjbpskTFW skiPSvYjx6UgQtQ4VbkduhnMU6kUSxzmYH5awfC8iQAjBipKVVqp1mc/gJLs5CgoI8P/ 6t0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:from:references:to:content-language:subject:user-agent :mime-version:date:message-id:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=uN5JFDo5xPs/45DJjJCVInyhRtqYKY+HaCGjzHt49GI=; b=PnwerbHCcVUVcAEEhacXNqJNckUKp2NEmou475yAGhAFHb/4p79/991bMDYNYh5pdb 6skhnBzuNhalh+EQp9BSehpb1Adr5bwbKQ059RTEQYALIn64bDs0H+MEW0UvP1wW+pAe NA5GTVR4jNqbdpYFD6Ckbb4YzqHkJl3Q3OZYQYRBVeqbZcTVVqSCG+3a9E61RW20p/4P 696+2KPpJQjDbjSkVy3TZ7oU5Vsf+dhlGzXMkQnr+I7ULtKAsWQr8QTu5eWIbv8q8Cf7 e5fjq+9DTmuWOODt3LXnd3WzVyDmisFWIWr/XpED2Z0HwUx1HeI3RLdmacMql44ifrpI gl2w== X-Gm-Message-State: ANoB5pmQy66dMtBc9mKpvdgLAwo9vXzIyJaO+Ut0niNV/RISGCVWnHad Bn9+y8AF4A1ONWP6MbiAaSGFZbbxPV4= X-Google-Smtp-Source: AA0mqf5ATSb2HPrLogyFxbPKDbKODViwQz7KXWq50tfqf/em0hMUe8t72sPpFKU1pGNxg454cks4dQ== X-Received: by 2002:a05:620a:16a2:b0:6fa:124e:d8aa with SMTP id s2-20020a05620a16a200b006fa124ed8aamr26131645qkj.604.1669584204209; Sun, 27 Nov 2022 13:23:24 -0800 (PST) Received: from ?IPV6:2600:1700:bd2c:b810::43? ([2600:1700:bd2c:b810::43]) by smtp.googlemail.com with ESMTPSA id d18-20020ac85352000000b0035d432f5ba3sm5823191qto.17.2022.11.27.13.23.23 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 27 Nov 2022 13:23:23 -0800 (PST) Content-Type: multipart/alternative; boundary="------------0ifMxKjhtbCSnhSqxhL22DLk" Message-ID: Date: Sun, 27 Nov 2022 15:23:22 -0600 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.2.2 Subject: Re: Disable unique constraint in Postgres Content-Language: en-US To: pgsql-admin@lists.postgresql.org References: From: Ron In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk This is a multi-part message in MIME format. --------------0ifMxKjhtbCSnhSqxhL22DLk Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 11/27/22 10:58, Scott Ribe wrote: >> On Nov 27, 2022, at 9:51 AM, Samed YILDIRIM 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. --------------0ifMxKjhtbCSnhSqxhL22DLk Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit On 11/27/22 10:58, Scott Ribe wrote:
On Nov 27, 2022, at 9:51 AM, Samed YILDIRIM <samed@reddoc.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.
--------------0ifMxKjhtbCSnhSqxhL22DLk--