liveBook · Manning

Create_hypertable function

As explained in Just Use Postgres!

The create_hypertable function converts a regular PostgreSQL table into a TimescaleDB hypertable and defines its partitioning configuration.

Converts a regular PostgreSQL table into a TimescaleDB hypertable that automatically creates and manages time-series partitions, called chunks or child tables. section 9.4

SELECT create_hypertable(
  relation => 'watch.heart_rate_measurements',
  dimension => by_range('recorded_at', interval '1 month'),
  create_default_indexes => false
);

Run this statement to partition heart-rate measurements by one-month ranges on recorded_at while disabling default index creation. section 9.4

Configure the function through three parameters:

  • Set relation to the table being converted, such as watch.heart_rate_measurements. section 9.4
  • Set dimension to a range partition over recorded_at, using a one-month interval. section 9.4
  • Set create_default_indexes to false when planning indexes separately for time-series workloads. section 9.4
  • Choose partition granularity carefully: monthly chunks suit a small dataset but may be too large for millions of devices. section 9.4

Verify automatic chunk creation

Inspect the converted table to list child tables, then insert a row beyond the current range. TimescaleDB creates a new chunk covering the next one-month interval. section 9.4

How Just Use Postgres! covers it

How deep it goes
Explains parameters, chunk inspection, automatic creation, and sizing caveats without detailing comprehensive indexing strategy.
Examples
Uses heart-rate measurements, recorded_at ranges, psql inspection commands, inserts, and show_chunks output.
What it assumes
Assumes a PostgreSQL table containing time-series data and familiarity with SQL or psql inspection commands.
What you can do after
Operate/configure a hypertable, inspect its chunks, and recognize when partition intervals need adjustment.
How it connects
Connects PostgreSQL tables with partitions, chunks, range dimensions, indexes, and retention policies.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Just Use Postgres!. The section links point to the parts of the book it draws on.