Skip to content

Understand schema optimization

Schema optimization options available in TimescaleDB and Tiger Cloud, including indexes, constraints, triggers, tablespaces, JSON, and FDW

TimescaleDB inherits the full schema toolbox from PostgreSQL — indexes, constraints, triggers, tablespaces, foreign data wrappers, and JSON/JSONB types — and applies them to hypertables and chunks. A well-designed schema keeps hot paths fast; a poor fit shows up as wasted I/O, bloated indexes, or painful migrations later.

Indexes are the primary tool for accelerating queries. TimescaleDB automatically creates a time-based index on every hypertable. You can add secondary indexes (B-tree, hash, GiST, GIN) to speed up filters on non-time columns such as device IDs, tags, or status codes.

For hypertables with hypercore enabled, secondary indexes also support chunk skipping, which lets the query planner skip entire chunks that don’t match a filter.

Use PostgreSQL constraintsNOT NULL, CHECK, UNIQUE, and foreign keys — to enforce data integrity at the database level. Hypertables support all standard constraint types, with the requirement that UNIQUE and PRIMARY KEY constraints must include the partitioning column.

Triggers let you run custom logic automatically when rows are inserted, updated, or deleted. Common use cases include auditing changes, enforcing business rules, and transforming data on write.

Tablespaces let you control where PostgreSQL stores data on disk. You can place hot chunks on fast SSDs and move older chunks to slower, cheaper storage. This is primarily useful for self-hosted deployments — Tiger Cloud manages storage tiers automatically.

When your data has varying or unpredictable fields — for example, IoT sensors that report different measurements — use PostgreSQL JSONB columns for the flexible parts and regular columns for the fields you always filter or aggregate on. This gives you schema flexibility without sacrificing query performance on known fields.

Foreign data wrappers let you query external PostgreSQL data sources as if they were local tables. This is useful for joining time-series data with reference data stored elsewhere.

You can alter hypertable schemas after creation: add or drop columns, change data types, rename columns, and modify constraints. Schema changes propagate automatically across all chunks.

  • Set the time column datatype to timestamptz, not timestamp. See PostgreSQL timestamp best practices.
  • Add secondary indexes only on columns you actively filter or join on — unused indexes slow down writes.
  • Use JSONB over JSON for semi-structured data — JSONB supports indexing and is more efficient to query.
  • Include the partitioning column in any UNIQUE or PRIMARY KEY constraint.