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 1ozPoB-0002Yp-VQ for pgsql-admin@arkaria.postgresql.org; Sun, 27 Nov 2022 22:07: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 1ozPoA-0006vs-EB for pgsql-admin@arkaria.postgresql.org; Sun, 27 Nov 2022 22:07:30 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ozPoA-0006vj-3A for pgsql-admin@lists.postgresql.org; Sun, 27 Nov 2022 22:07:30 +0000 Received: from mail-qk1-x72e.google.com ([2607:f8b0:4864:20::72e]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1ozPo5-0005Sm-A3 for pgsql-admin@lists.postgresql.org; Sun, 27 Nov 2022 22:07:29 +0000 Received: by mail-qk1-x72e.google.com with SMTP id z17so6066854qki.11 for ; Sun, 27 Nov 2022 14:07: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=Xo2wCP7a4FQv+nMgRJANK6IyJl2d7pxr4tjdVa8kBO4=; b=PR91GP7TR2LDc287fk/49GPIAx3v6V5EB8OiN5jqEMgM7kUDhB6h1n4SPUHT7JkguT JTFvxbcBAQdIi8bGimoT0xxwC8ePqpXNDEKahxiyr3xAxYDgHJunamDNHrJSDLvxgfub 5GCDEMGip0qOlSVhd0AtYHxDPMe5E4FQH4eKbEKqcF1fbXXVGPpwr83NlL3Ncj7vYtn0 S3n1GzZp98EX5l21OwcD1B6V9rDVlkJdAgfb2lzxcid9YJn3vF/BNVjlcEYR6dP2Uct/ YQfKoyNS4Jfrda62ZPTeXO9vqmNl2e0a2mWCG6czslyudEQB+NOx6YfUCTFOD0E3tsyz 93cA== 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=Xo2wCP7a4FQv+nMgRJANK6IyJl2d7pxr4tjdVa8kBO4=; b=CT3TzrwFjVpsf/6OwkeyUDCKtvsHkHiZOIzOVq9R+xtlVf2WGvxjRmWpwpQlXPS9vm hZJuuMUtEza8fJEX/a7aGURZuD1cXhSXjhUzLTaHmGlj8WHJMEwZAYx+l5vb8/QQRO2m BHM12iET9lrtfxCcscguvFzLkHsEg/TIhAI2i63W1Fmi2D+FoazaWnNOrG3QVAMDFc63 4Kf34qz6eQ0gwmEbOm/xZ1Crj7DjwBtlsGZGCv41dqAxt6FNAP91CmYwyeFoVvJj4Lb2 itQ7aFP93TwDGt09D4Ww8vbw7/sP9qJgKls7vVHzxb10qX4zunWvD1Sqiwwq6tdoiEUT 5SUA== X-Gm-Message-State: ANoB5pnGgdNdWcmNykpZNR9jvzL00FHJvEChvs2ShR2tohNhvb9tlJ/1 bNRrss62QStTZyqre0P8fNlbTD1jXNQ= X-Google-Smtp-Source: AA0mqf4VXBXTypS+KGY/yW+zNcl0iw7WNVl4Ynu4RU/ZQTBqdN+SYBquaFiQuFIYIAf9Z+gwXKd6tA== X-Received: by 2002:a05:620a:899:b0:6fa:39fa:eeb7 with SMTP id b25-20020a05620a089900b006fa39faeeb7mr42846028qka.666.1669586843381; Sun, 27 Nov 2022 14:07:23 -0800 (PST) Received: from ?IPV6:2600:1700:bd2c:b810::43? ([2600:1700:bd2c:b810::43]) by smtp.googlemail.com with ESMTPSA id fb18-20020a05622a481200b0039a08c0a594sm5925049qtb.82.2022.11.27.14.07.22 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 27 Nov 2022 14:07:23 -0800 (PST) Content-Type: multipart/alternative; boundary="------------nd7iUZiQWxu5pVXVpcdsa84v" Message-ID: Date: Sun, 27 Nov 2022 16:07: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: <88df5cb3-913f-182e-22ed-cbdc62fdd7d6@gmail.com> From: Ron In-Reply-To: <88df5cb3-913f-182e-22ed-cbdc62fdd7d6@gmail.com> 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. --------------nd7iUZiQWxu5pVXVpcdsa84v Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 11/27/22 15:56, Mladen Gogala wrote: > On 11/27/22 16:23, Ron wrote: >> >> 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. > > > You are aware that in Oracle "ALTER TABLE ENABLE CONSTRAINT" rebuilds the > index used to enforce the constraint? You will not save any time by > disabling and re-enabling constraints. > Eliminating mistakes and reducing DBA work are the point of DISABLE and ENABLE INDEX, not saving clock time during the maintenance window. -- Angular momentum makes the world go 'round. --------------nd7iUZiQWxu5pVXVpcdsa84v Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit On 11/27/22 15:56, Mladen Gogala wrote:
On 11/27/22 16:23, Ron wrote:

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.


You are aware that in Oracle "ALTER TABLE ENABLE CONSTRAINT" rebuilds the index used to enforce the constraint? You will not save any time by disabling and re-enabling constraints.


Eliminating mistakes and reducing DBA work are the point of DISABLE and ENABLE INDEX, not saving clock time during the maintenance window.

--
Angular momentum makes the world go 'round.
--------------nd7iUZiQWxu5pVXVpcdsa84v--