@@ -4283,18 +4283,20 @@ CREATE TABLE measurement_y2008m02 PARTITION OF measurement
4283
4283
TABLESPACE fasttablespace;
4284
4284
</programlisting>
4285
4285
4286
- As an alternative, it is sometimes more convenient to create the
4287
- new table outside the partition structure, and attach it as a
4288
- partition later. This allows new data to be loaded, checked, and
4289
- transformed prior to it appearing in the partitioned table.
4286
+ As an alternative to creating a new partition , it is sometimes more
4287
+ convenient to create a new table separate from the partition structure
4288
+ and attach it as a partition later. This allows new data to be loaded,
4289
+ checked, and transformed prior to it appearing in the partitioned table.
4290
4290
Moreover, the <literal>ATTACH PARTITION</literal> operation requires
4291
- only <literal>SHARE UPDATE EXCLUSIVE</literal> lock on the
4292
- partitioned table, as opposed to the <literal>ACCESS
4293
- EXCLUSIVE</literal> lock that is required by <command>CREATE TABLE
4294
- ... PARTITION OF</command>, so it is more friendly to concurrent
4295
- operations on the partitioned table.
4296
- The <literal>CREATE TABLE ... LIKE</literal> option is helpful
4297
- to avoid tediously repeating the parent table's definition:
4291
+ only a <literal>SHARE UPDATE EXCLUSIVE</literal> lock on the
4292
+ partitioned table rather than the <literal>ACCESS EXCLUSIVE</literal>
4293
+ lock required by <command>CREATE TABLE ... PARTITION OF</command>,
4294
+ so it is more friendly to concurrent operations on the partitioned table;
4295
+ see <link linkend="sql-altertable-attach-partition"><literal>ALTER TABLE ... ATTACH PARTITION</literal></link>
4296
+ for additional details. The
4297
+ <link linkend="sql-createtable-parms-like"><literal>CREATE TABLE ... LIKE</literal></link>
4298
+ option can be helpful to avoid tediously repeating the parent table's
4299
+ definition; for example:
4298
4300
4299
4301
<programlisting>
4300
4302
CREATE TABLE measurement_y2008m02
@@ -4313,17 +4315,15 @@ ALTER TABLE measurement ATTACH PARTITION measurement_y2008m02
4313
4315
</para>
4314
4316
4315
4317
<para>
4316
- Before running the <command>ATTACH PARTITION</command> command, it is
4317
- recommended to create a <literal>CHECK</literal> constraint on the table to
4318
- be attached that matches the expected partition constraint, as
4319
- illustrated above. That way, the system will be able to skip the scan
4320
- which is otherwise needed to validate the implicit
4321
- partition constraint. Without the <literal>CHECK</literal> constraint,
4318
+ Note that when running the <command>ATTACH PARTITION</command> command,
4322
4319
the table will be scanned to validate the partition constraint while
4323
4320
holding an <literal>ACCESS EXCLUSIVE</literal> lock on that partition.
4324
- It is recommended to drop the now-redundant <literal>CHECK</literal>
4325
- constraint after the <command>ATTACH PARTITION</command> is complete. If
4326
- the table being attached is itself a partitioned table, then each of its
4321
+ As shown above, it is recommended to avoid this scan by creating a
4322
+ <literal>CHECK</literal> constraint matching the expected partition
4323
+ constraint on the table prior to attaching it. Once the
4324
+ <command>ATTACH PARTITION</command> is complete, it is recommended to drop
4325
+ the now-redundant <literal>CHECK</literal> constraint.
4326
+ If the table being attached is itself a partitioned table, then each of its
4327
4327
sub-partitions will be recursively locked and scanned until either a
4328
4328
suitable <literal>CHECK</literal> constraint is encountered or the leaf
4329
4329
partitions are reached.
@@ -4333,7 +4333,7 @@ ALTER TABLE measurement ATTACH PARTITION measurement_y2008m02
4333
4333
Similarly, if the partitioned table has a <literal>DEFAULT</literal>
4334
4334
partition, it is recommended to create a <literal>CHECK</literal>
4335
4335
constraint which excludes the to-be-attached partition's constraint. If
4336
- this is not done then the <literal>DEFAULT</literal> partition will be
4336
+ this is not done, the <literal>DEFAULT</literal> partition will be
4337
4337
scanned to verify that it contains no records which should be located in
4338
4338
the partition being attached. This operation will be performed whilst
4339
4339
holding an <literal>ACCESS EXCLUSIVE</literal> lock on the <literal>
@@ -4344,21 +4344,21 @@ ALTER TABLE measurement ATTACH PARTITION measurement_y2008m02
4344
4344
</para>
4345
4345
4346
4346
<para>
4347
- As explained above , it is possible to create indexes on partitioned tables
4348
- so that they are applied automatically to the entire hierarchy.
4349
- This is very
4350
- convenient, as not only will the existing partitions become indexed, but
4351
- also any partitions that are created in the future will. One limitation is
4352
- that it's not possible to use the <literal>CONCURRENTLY</literal>
4353
- qualifier when creating such a partitioned index . To avoid long lock
4354
- times, it is possible to use <command>CREATE INDEX ON ONLY</command>
4355
- the partitioned table; such an index is marked invalid, and the partitions
4356
- do not get the index applied automatically . The indexes on partitions can
4357
- be created individually using <literal>CONCURRENTLY</literal>, and then
4358
- <firstterm>attached</firstterm> to the index on the parent using
4359
- <command>ALTER INDEX .. ATTACH PARTITION</command>. Once indexes for all
4360
- partitions are attached to the parent index, the parent index is marked
4361
- valid automatically. Example:
4347
+ As mentioned earlier , it is possible to create indexes on partitioned
4348
+ tables so that they are applied automatically to the entire hierarchy.
4349
+ This can be very convenient as not only will all existing partitions be
4350
+ indexed, but any future partitions will be as well. However, one
4351
+ limitation when creating new indexes on partitioned tables is that it
4352
+ is not possible to use the <literal>CONCURRENTLY</literal>
4353
+ qualifier, which could lead to long lock times . To avoid this, you can
4354
+ use <command>CREATE INDEX ON ONLY</command> the partitioned table, which
4355
+ creates the new index marked as invalid, preventing automatic application
4356
+ to existing partitions . Instead, indexes can then be created individually
4357
+ on each partition using <literal>CONCURRENTLY</literal> and
4358
+ <firstterm>attached</firstterm> to the partitioned index on the parent
4359
+ using <command>ALTER INDEX ... ATTACH PARTITION</command>. Once indexes for
4360
+ all the partitions are attached to the parent index, the parent index will
4361
+ be marked valid automatically. Example:
4362
4362
<programlisting>
4363
4363
CREATE INDEX measurement_usls_idx ON ONLY measurement (unitsales);
4364
4364
0 commit comments