Search code examples
postgresqlmulti-tenant

Best practice for Cluster Index on Postgres for multi-tenant architecture


If I have a multi-tenant architecture using a Postgres DB is it beneficial to create the AccountId as part of the Cluster Index? Any references to some good database design principles for large multi-tenant architecture designs?

As example:

CREATE TABLE orders ( orderid uuid NOT NULL, accountid bigint NOT NULL, . . )


Solution

  • @jjanes corrected me that Postgres does not have a Cluster Index by design. You can use the CLUSTER command to re-order records by an index. https://www.postgresql.org/docs/current/sql-cluster.html

    This post explains it well. About clustered index in postgres

    Using CLUSTER should reduce the seek time where the Account is part of the index. https://www.postgresonline.com/journal/archives/10-How-does-CLUSTER-ON-improve-index-performance.html