1

https://www.postgresql.org/docs/9.1/sql-cluster.html

Now suppose I have pg_repack installed so that it won't lock the table when clustering.

  1. Should you cluster a table using an index that has a high idx_scan?

  2. It does not make sense to cluster a unique uuid index right? Since reordering the table won't help to retrieve information easily.

  3. Would it make sense to do a cluster on a composite unique index?

  4. If a particular column has been joined (inner/left) with several queries, would it make sense to cluster a table related to the column's index?

  5. What exactly we should look for when selecting a particular index to cluster a table on?

1 Answer 1

2

If the index that you use for clustering is on column col of table public.tab, run

SELECT correlation
FROM pg_stats
WHERE schemaname = 'public' AND tablename = 'tab'
  AND attname = 'col';

If that value is 1.0, the order is perfect, if it is close to 0, the order has rotted. You best use trial and error to find from what value of correlation on performance gets bad.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.