Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

What ONLY keyword really means in Postgresql CREATE INDEX command

From the docs: "Indicates not to recurse creating indexes on partitions, if the table is partitioned. The default is to recurse.".

Am I understand correctly that index will not be created on existing partitons? What kind of index will be created then (on what)?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

The objective is to build a partitioned index with as little locking as possible.

Normally, you’d use CREATE INDEX CONCURRENTLY to create an index on each partition, then CREATE INDEX on the partitioned table. If the index definitions match, the previously created indexes will become partitions of the partitioned index.

The problem with that is that all partitions will be locked at the same time. Instead, you can do it one partition at a time:

  • create the index ONLY on the partitioned table (the index will be invalid)

  • use ALTER INDEX ... ATTACH PARTITION to attach the indexes on the partitions as partitions of the index

  • once all partitions are attached, the partitioned index will become valid

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading