Physical Storage Optimization
Optimize database performance by rearranging data on storage and using faster storage devices.
Rearranging Data on the Storage Device
The single most efficient way to improve query speed is to reinsert data into database tables in a sorted order. This optimizes the distribution of data across database pages. Since like data is located near each other when rearranged, the database engine can grab more rows that share the same page, reducing overhead.
-- PostgreSQL: Recluster table in index order
REINDEX TABLE tablename;
-- Or insert ordered data:
INSERT INTO sorted_orders (id, customer_id, created_at, total)
SELECT * FROM orders ORDER BY created_at, id;
Move the Database Files to a Faster Device
The database is limited to the speed at which the storage device can read data. Moving database files to a faster storage device (SSD vs HDD, NVMe vs SATA, or even in-memory) can provide significant performance gains.
| Storage Type | Relative Speed |
|---|---|
| In-memory | Fastest |
| NVMe SSD | Very Fast |
| SATA SSD | Fast |
| HDD | Slow |