Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iOsdv-0007rb-M1 for pgsql-hackers@arkaria.postgresql.org; Mon, 28 Oct 2019 00:12:20 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iOsdu-0005bY-AW for pgsql-hackers@arkaria.postgresql.org; Mon, 28 Oct 2019 00:12:18 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iOsdt-0005bR-PU for pgsql-hackers@lists.postgresql.org; Mon, 28 Oct 2019 00:12:18 +0000 Received: from mail-yb1-xb2d.google.com ([2607:f8b0:4864:20::b2d]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1iOsdm-0002G1-9S for pgsql-hackers@postgresql.org; Mon, 28 Oct 2019 00:12:16 +0000 Received: by mail-yb1-xb2d.google.com with SMTP id z125so3476543ybc.4 for ; Sun, 27 Oct 2019 17:12:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telsasoft-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :user-agent; bh=Sys9lh6cNkWgI3eFDbMga/aL115GD1T/J6cv4LmXdCA=; b=e5xY/J4dHzZ1TzPkWn8+fU+LaMdGBtbGHvAvnqzTiAgTJ/Jy8BdMoyvAbtmE6J1KwQ IVs/F/WlpPmVZvGxssLOsq0DiapKnTFBaPmvrv27UKxtHHZ/x6DOI7hcQSj+n184N0/X bgZoRwpsHBxUF5c55J7gzMeAl93CuPLHU/R8imvk/H2tqLzFn9htc0gE3q6PVgwwpqQg zhqALG6/vlvcoH09g3HGv32wDk6ey2To1ps8IOC44vnO/QbYp0E9qsFTItpEYvgy1JVU wI+OTlB0ktHMzRYwAeJf+QEt4AOK+O8NCzomk7JbRG18cbi0fC1eZ5K/1b/fa0KP1G1v jy1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:user-agent; bh=Sys9lh6cNkWgI3eFDbMga/aL115GD1T/J6cv4LmXdCA=; b=bkDva6visokUjh9zUuUG3av8IJTdfEQVV8dl8LTTq9iv4q+qgki5ThETHOJvNvb+v4 tBMYAGBESAc9VClpziRNHd3V6MBvdp9zFFop90UBVAU7agi7dCmvMcVH2yM/hC67S9xj nW5u7BRyvvAwW3oDSjcoEkLC+6tWmJbSNbSjV+PO3yOScBEz5crzQATBmyoPYsczOXw/ qXmaP6nUdyYUG/2EFXnmybkuKKAgfXVjSMawQk/4sKI2mxMHWtdPE6EVKycR7TRjbNtT 4gbhuzBqYJ4zTyS9BeXM888ED+DrB82l/W81E0tsBjr3zcfFoz5p5DmNzhplVItPyBNu Bong== X-Gm-Message-State: APjAAAUvjFS9ZPYy7F34ljkWibdUL8AgRE5sOcccRpo5u+RgOTrgNqQ2 gdjBh/MP0bsbenfFt9tDINbzEw== X-Google-Smtp-Source: APXvYqzyG7hKQRrZwnCS8as2j4xh8p0ushJ0xSLaDq4GmwMDrfZngFQtb/TtsHTGWladO6ychj9GoA== X-Received: by 2002:a25:778c:: with SMTP id s134mr3036707ybc.143.1572221529390; Sun, 27 Oct 2019 17:12:09 -0700 (PDT) Received: from pryzbyj (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id k188sm5326842ywe.41.2019.10.27.17.12.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 27 Oct 2019 17:12:08 -0700 (PDT) Received: by pryzbyj (Postfix, from userid 1000) id 444428011CB; Sun, 27 Oct 2019 19:12:07 -0500 (CDT) Date: Sun, 27 Oct 2019 19:12:07 -0500 From: Justin Pryzby To: Robert Haas Cc: pgsql-hackers Subject: update ALTER TABLE with ATTACH PARTITION lock mode Message-ID: <20191028001207.GB23808@telsasoft.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="xHFwDpU9dbj6ez1V" Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --xHFwDpU9dbj6ez1V Content-Type: text/plain; charset=us-ascii Content-Disposition: inline commit #898e5e32 (Allow ATTACH PARTITION with only ShareUpdateExclusiveLock) updates ddl.sgml but not alter_table.sgml, which only says: https://www.postgresql.org/docs/12/release-12.html |An ACCESS EXCLUSIVE lock is held unless explicitly noted. Find attached patch, which also improve language in several related places. "Without such a constraint": SUCH could refer to either of the constraints.. "because it is no longer necessary.": In our use case, we prefer to keep the redundant constraint, to avoid having to add it back if we detach/reattach again in the future.. --xHFwDpU9dbj6ez1V Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v1-0001-Mention-reduced-locking-strength-of-ATTACH-PARTIT.patch" From c820a81fba0a6c2388ec58fc0204ca833523e81e Mon Sep 17 00:00:00 2001 From: Justin Pryzby Date: Sun, 27 Oct 2019 18:54:24 -0500 Subject: [PATCH v1 1/2] Mention reduced locking strength of ATTACH PARTITION.. See commit 898e5e32 --- doc/src/sgml/ref/alter_table.sgml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/doc/src/sgml/ref/alter_table.sgml b/doc/src/sgml/ref/alter_table.sgml index c8dfa19..a184bed 100644 --- a/doc/src/sgml/ref/alter_table.sgml +++ b/doc/src/sgml/ref/alter_table.sgml @@ -900,6 +900,13 @@ WITH ( MODULUS numeric_literal, REM the scan of the new partition, it is always skipped when the default partition is a foreign table. + + + Attaching a partition acquires a SHARE UPDATE EXCLUSIVE + lock on the partitioned table, in addition to an + ACCESS EXCLUSIVE lock on the partition. + + -- 2.7.4 --xHFwDpU9dbj6ez1V Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v1-0002-Tweak-language-for-ATTACH-PARTITION-docs.patch" From b1c9c50228ebd3d2d511382ebd6cbae08788e376 Mon Sep 17 00:00:00 2001 From: Justin Pryzby Date: Sun, 27 Oct 2019 18:38:23 -0500 Subject: [PATCH v1 2/2] Tweak language for ATTACH PARTITION docs --- doc/src/sgml/ddl.sgml | 8 ++++---- doc/src/sgml/ref/alter_table.sgml | 12 ++++++------ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/doc/src/sgml/ddl.sgml b/doc/src/sgml/ddl.sgml index b097b80..8b60d8b 100644 --- a/doc/src/sgml/ddl.sgml +++ b/doc/src/sgml/ddl.sgml @@ -3972,14 +3972,14 @@ ALTER TABLE measurement ATTACH PARTITION measurement_y2008m02 Before running the ATTACH PARTITION command, it is recommended to create a CHECK constraint on the table to - be attached describing the desired partition constraint. That way, + be attached matching the desired partition constraint. That way, the system will be able to skip the scan which is otherwise needed to validate the implicit - partition constraint. Without such a constraint, the table will be + partition constraint. Without the CHECK constraint, the table will be scanned to validate the partition constraint while holding an ACCESS EXCLUSIVE lock on that partition and a SHARE UPDATE EXCLUSIVE lock on the parent table. - One may then drop the constraint after ATTACH PARTITION - is finished, because it is no longer necessary. + It may be desired to drop the redundant CHECK constraint + after ATTACH PARTITION is finished. diff --git a/doc/src/sgml/ref/alter_table.sgml b/doc/src/sgml/ref/alter_table.sgml index a184bed..91ec626 100644 --- a/doc/src/sgml/ref/alter_table.sgml +++ b/doc/src/sgml/ref/alter_table.sgml @@ -841,7 +841,7 @@ WITH ( MODULUS numeric_literal, REM or as a default partition by using DEFAULT. For each index in the target table, a corresponding one will be created in the attached table; or, if an equivalent - index already exists, will be attached to the target table's index, + index already exists, it will be attached to the target table's index, as if ALTER INDEX ATTACH PARTITION had been executed. Note that if the existing table is a foreign table, it is currently not allowed to attach the table as a partition of the target table if there @@ -864,17 +864,17 @@ WITH ( MODULUS numeric_literal, REM already exist. If any of the CHECK constraints of the table being attached are marked NO INHERIT, the command will fail; - such a constraint must be recreated without the NO INHERIT + such constraints must be recreated without the NO INHERIT clause. If the new partition is a regular table, a full table scan is performed - to check that no existing row in the table violates the partition + to check that existing rows in the table do not violate the partition constraint. It is possible to avoid this scan by adding a valid - CHECK constraint to the table that would allow only - the rows satisfying the desired partition constraint before running this - command. It will be determined using such a constraint that the table + CHECK constraint to the table that allows only + rows satisfying the desired partition constraint before running this + command. The CHECK constraint will be used to determine that the table need not be scanned to validate the partition constraint. This does not work, however, if any of the partition keys is an expression and the partition does not accept NULL values. If attaching -- 2.7.4 --xHFwDpU9dbj6ez1V--