Clustering an index

CLUSTER works by making a whole new copy of the table, sorted by the index you asked to traverse the original in. It's as if you had inserted them in that order in the first place. Once built, the original copy of the data is dropped. CLUSTER requires an exclusive lock on the table and enough disk space to hold the second, reorganized copy-essentially, twice the amount of disk space, temporarily. You should run ANALYZE afterwards in order to update the statistics associated with this table to reflect its new ordering.

Clustering is useful for getting faster results from range-based queries, when selecting a set of values that is between two end points (with the beginning or end being considered an end point in that context). ...

Get PostgreSQL 10 High Performance now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.