index
Clustered
PostgreSQL CLUSTER rewrites a table in index order once; later writes do not maintain that order. Unlike SQL Server clustered indexes, this is a maintenance operation. Requires locking. Target: PostgreSQL 17. Use a disposable database; plan selection is not guaranteed.
Formal Syntax & Structure
sql syntaxsql
CLUSTER items USING ixWorking Example
Example Snippetsql
CREATE TABLE items(id integer primary key, category integer, price integer, name text, active integer); INSERT INTO items VALUES (1,1,10,'Alpha',1),(2,1,20,'Beta',0),(3,2,30,'Gamma',1); CREATE INDEX ix ON items(price);CLUSTER items USING ix;SELECT id FROM items ORDER BY price;