Re: ALTER TABLE .. DETACH PARTITION CONCURRENTLY
Justin Pryzby <pryzby@telsasoft.com>
From: Justin Pryzby <pryzby@telsasoft.com>
To: Alvaro Herrera <alvherre@alvh.no-ip.org>
Cc: Amit Langote <amitlangote09@gmail.com>, pgsql-hackers@lists.postgresql.org
Date: 2021-03-17T18:45:34Z
Lists: pgsql-hackers
The v8 patch has the "broken constraint" problem.
Also, it "fails to avoid" adding duplicate constraints:
Check constraints:
"c" CHECK (i IS NOT NULL AND i > 1 AND i < 2)
"cc" CHECK (i IS NOT NULL AND i >= 1 AND i < 2)
"p1_check" CHECK (true)
"p1_i_check" CHECK (i IS NOT NULL AND i >= 1 AND i < 2)
> diff --git a/doc/src/sgml/catalogs.sgml b/doc/src/sgml/catalogs.sgml
> index 5c9f4af1d5..0cb846f408 100644
> --- a/doc/src/sgml/catalogs.sgml
> +++ b/doc/src/sgml/catalogs.sgml
> @@ -4485,6 +4485,16 @@ SCRAM-SHA-256$<replaceable><iteration count></replaceable>:<replaceable>&l
> when using declarative partitioning.
> </para></entry>
> </row>
> +
> + <row>
> + <entry role="catalog_table_entry"><para role="column_definition">
> + <structfield>inhdetachpending</structfield> <type>bool</type>
> + </para>
> + <para>
> + Set to true for a partition that is in the process of being detached;
> + false otherwise.
> + </para></entry>
> + </row>
Remove "Set to" ?
And say <literal>true</literal> and <literal>false</literal>
Probably you'll hate the suggestion, but maybe it should be "pendingdetach".
We already have pg_settings.pending_restart.
> + If <literal>CONCURRENTLY</literal> is specified, this process runs in two
> + transactions in order to avoid blocking other sessions that might be accessing
> + the partitioned table. During the first transaction, a
> + <literal>SHARE UPDATE EXCLUSIVE</literal> lock is taken on both parent table and
> + partition, and its partition is marked detached; at that point, the transaction
> + is committed and all transactions using the partitioned table are waited for.
> + Once all those transactions are gone, the second stage acquires
Instead of "gone", say "have completed" ?
> +/*
> + * MarkInheritDetached
> + *
> + * When a partition is detached from its parent concurrently, we don't
> + * remove the pg_inherits row until a second transaction; as a preparatory
> + * step, this function marks the entry as 'detached', so that other
*pending detached
> + * The strategy for concurrency is to first modify the partition catalog
> + * rows to make it visible to everyone that the partition is detached,
the inherits catalog?
> + /*
> + * In concurrent mode, the partition is locked with share-update-exclusive
> + * in the first transaction. This allows concurrent transactions to be
> + * doing DML to the partition.
> + /*
> + * Check inheritance conditions and either delete the pg_inherits row
> + * (in non-concurrent mode) or just set the inhisdetached flag.
detachpending
Commits
-
Make detach-partition-concurrently-4 less timing sensitive
- eb43bdbf5104 14.0 landed
-
Improve documentation on DETACH PARTITION lock levels
- db6e1aeb952e 14.0 landed
-
Track detached partitions more accurately in partdescs
- 3fe773b14975 14.0 landed
-
Allow a partdesc-omitting-partitions to be cached
- d6b8d29419df 14.0 landed
-
Fix relcache inconsistency hazard in partition detach
- 8aba9322511f 14.0 landed
-
Don't add a redundant constraint when detaching a partition
- 7b357cc6ae55 14.0 landed
-
ALTER TABLE ... DETACH PARTITION ... CONCURRENTLY
- 71f4c8c6f74b 14.0 landed
-
Let ALTER TABLE Phase 2 routines manage the relation pointer
- cd03c6e94b09 14.0 landed
-
Check default partitions constraints while descending
- f481d2823297 14.0 landed
- ef1e1250e716 12.5 landed
- d0230a43fcae 13.0 landed