# timescale/timescaledb architecture

> Architecture diagram of the GitHub repository timescale/timescaledb, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-09). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/timescale/timescaledb
- Repository: https://github.com/timescale/timescaledb

## Overview

TimescaleDB is a PostgreSQL extension for time-series analytics. The README’s central workflow is to create a hypertable, insert time-series rows that are partitioned into chunks and may be stored in columnar form, then run time-bucketed analytical queries. The graph also preserves documented query optimizations and continuous aggregates. Source evidence is limited to the README and the supplied excerpts and SOURCE INDEX; unsampled subsystems are included only where the README documents their capability, without asserting unverified internal calls.

Main entry points: [`src/init.c`](https://github.com/timescale/timescaledb/blob/main/src/init.c) (TimescaleDB Extension), [`src/hypertable.h`](https://github.com/timescale/timescaledb/blob/main/src/hypertable.h) (Hypertable Management), [`src/planner/planner.c`](https://github.com/timescale/timescaledb/blob/main/src/planner/planner.c) (Hypertable Planner), [`src/chunk_tuple_routing.c`](https://github.com/timescale/timescaledb/blob/main/src/chunk_tuple_routing.c) (Insert Routing)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_data_model["Hypertables and Chunks"]
  node_hypertable["Hypertable Management<br/>[hypertable.h]"]
  node_chunk["Chunk Metadata<br/>[chunk.h]"]
end

subgraph group_write_path["Ingestion and Storage"]
  node_routing["Insert Routing"]
  node_compression["Columnar Compression"]
  node_compression_settings["Compression Settings"]
end

subgraph group_query_path["Query Execution"]
  node_planner["Hypertable Planner<br/>[planner.c]"]
  node_chunk_append["Chunk Append Scan<br/>[exec.c]"]
  node_columnar_scan["Columnar Scan<br/>[exec.c]"]
  node_vector_agg["Vectorized Aggregation<br/>[exec.c]"]
end

subgraph group_analytics["Analytics Features"]
  node_time_bucket["Time Bucketing<br/>[time_bucket.c]"]
  node_continuous_agg["Continuous Aggregates<br/>[refresh.c]"]
end

subgraph group_platform["Extension Internals"]
  node_extension["TimescaleDB Extension<br/>[init.c]"]
  node_catalog[("Metadata Catalog<br/>[catalog.h]")]
  node_background_jobs["Background Jobs<br/>[job.c]"]
  node_cross_module["Cross-Module Dispatch<br/>[cross_module_fn.h]"]
  node_compat["PostgreSQL Compatibility<br/>[compat.h]"]
  node_scan_iterator["Catalog Scan Iterator<br/>[scan_iterator.h]"]
  node_extension_config["Extension Configuration<br/>[guc.h]"]
end

node_user(("SQL User"))
node_postgres["PostgreSQL"]

node_user -->|"runs SQL"| node_postgres
node_postgres -->|"uses extension"| node_extension
node_extension -->|"creates hypertable"| node_hypertable
node_hypertable -->|"partitions data"| node_chunk
node_postgres -->|"inserts rows"| node_routing
node_routing -->|"finds chunk"| node_hypertable
node_postgres -->|"writes columnstore"| node_compression
node_compression -->|"uses settings"| node_compression_settings
node_postgres -->|"plans queries"| node_planner
node_planner -->|"optimizes scans"| node_chunk_append
node_postgres -->|"queries columnstore"| node_columnar_scan
node_postgres -->|"runs analytics"| node_vector_agg
node_postgres -->|"groups by time"| node_time_bucket
node_postgres -->|"creates aggregates"| node_continuous_agg
node_background_jobs -.->|"refreshes aggregates"| node_continuous_agg
node_hypertable -->|"references metadata"| node_catalog
node_scan_iterator -->|"scans metadata"| node_catalog
node_planner -->|"uses hypertable model"| node_hypertable
node_extension -.->|"dispatches features"| node_cross_module
node_extension -.->|"configures behavior"| node_extension_config
node_extension -.->|"adapts PostgreSQL APIs"| node_compat

click node_extension "https://github.com/timescale/timescaledb/blob/main/src/init.c"
click node_hypertable "https://github.com/timescale/timescaledb/blob/main/src/hypertable.h"
click node_chunk "https://github.com/timescale/timescaledb/blob/main/src/chunk.h"
click node_catalog "https://github.com/timescale/timescaledb/blob/main/src/ts_catalog/catalog.h"
click node_routing "https://github.com/timescale/timescaledb/blob/main/src/chunk_tuple_routing.c"
click node_compression "https://github.com/timescale/timescaledb/blob/main/tsl/src/compression/compression_storage.c"
click node_compression_settings "https://github.com/timescale/timescaledb/blob/main/src/ts_catalog/compression_settings.h"
click node_planner "https://github.com/timescale/timescaledb/blob/main/src/planner/planner.c"
click node_chunk_append "https://github.com/timescale/timescaledb/blob/main/src/nodes/chunk_append/exec.c"
click node_columnar_scan "https://github.com/timescale/timescaledb/blob/main/tsl/src/nodes/columnar_scan/exec.c"
click node_vector_agg "https://github.com/timescale/timescaledb/blob/main/tsl/src/nodes/vector_agg/exec.c"
click node_time_bucket "https://github.com/timescale/timescaledb/blob/main/src/time_bucket.c"
click node_continuous_agg "https://github.com/timescale/timescaledb/blob/main/tsl/src/continuous_aggs/refresh.c"
click node_background_jobs "https://github.com/timescale/timescaledb/blob/main/src/bgw/job.c"
click node_cross_module "https://github.com/timescale/timescaledb/blob/main/src/cross_module_fn.h"
click node_compat "https://github.com/timescale/timescaledb/blob/main/src/compat/compat.h"
click node_scan_iterator "https://github.com/timescale/timescaledb/blob/main/src/scan_iterator.h"
click node_extension_config "https://github.com/timescale/timescaledb/blob/main/src/guc.h"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_hypertable,node_chunk,node_user toneBlue
class node_routing,node_compression,node_compression_settings,node_postgres toneAmber
class node_planner,node_chunk_append,node_columnar_scan,node_vector_agg toneMint
class node_time_bucket,node_continuous_agg toneRose
class node_extension,node_catalog,node_background_jobs,node_cross_module,node_compat,node_scan_iterator,node_extension_config toneIndigo
```

## Components

### Hypertables and Chunks

- [Hypertable Management](https://github.com/timescale/timescaledb/blob/main/src/hypertable.h): `src/hypertable.h`
- [Chunk Metadata](https://github.com/timescale/timescaledb/blob/main/src/chunk.h): `src/chunk.h`

### Ingestion and Storage

- [Insert Routing](https://github.com/timescale/timescaledb/blob/main/src/chunk_tuple_routing.c): `src/chunk_tuple_routing.c`
- [Columnar Compression](https://github.com/timescale/timescaledb/blob/main/tsl/src/compression/compression_storage.c): `tsl/src/compression/compression_storage.c`
- [Compression Settings](https://github.com/timescale/timescaledb/blob/main/src/ts_catalog/compression_settings.h): `src/ts_catalog/compression_settings.h`

### Query Execution

- [Hypertable Planner](https://github.com/timescale/timescaledb/blob/main/src/planner/planner.c): `src/planner/planner.c`
- [Chunk Append Scan](https://github.com/timescale/timescaledb/blob/main/src/nodes/chunk_append/exec.c): `src/nodes/chunk_append/exec.c`
- [Columnar Scan](https://github.com/timescale/timescaledb/blob/main/tsl/src/nodes/columnar_scan/exec.c): `tsl/src/nodes/columnar_scan/exec.c`
- [Vectorized Aggregation](https://github.com/timescale/timescaledb/blob/main/tsl/src/nodes/vector_agg/exec.c): `tsl/src/nodes/vector_agg/exec.c`

### Analytics Features

- [Time Bucketing](https://github.com/timescale/timescaledb/blob/main/src/time_bucket.c): `src/time_bucket.c`
- [Continuous Aggregates](https://github.com/timescale/timescaledb/blob/main/tsl/src/continuous_aggs/refresh.c): `tsl/src/continuous_aggs/refresh.c`

### Extension Internals

- [TimescaleDB Extension](https://github.com/timescale/timescaledb/blob/main/src/init.c): `src/init.c`
- [Metadata Catalog](https://github.com/timescale/timescaledb/blob/main/src/ts_catalog/catalog.h): `src/ts_catalog/catalog.h`
- [Background Jobs](https://github.com/timescale/timescaledb/blob/main/src/bgw/job.c): `src/bgw/job.c`
- [Cross-Module Dispatch](https://github.com/timescale/timescaledb/blob/main/src/cross_module_fn.h): `src/cross_module_fn.h`
- [PostgreSQL Compatibility](https://github.com/timescale/timescaledb/blob/main/src/compat/compat.h): `src/compat/compat.h`
- [Catalog Scan Iterator](https://github.com/timescale/timescaledb/blob/main/src/scan_iterator.h): `src/scan_iterator.h`
- [Extension Configuration](https://github.com/timescale/timescaledb/blob/main/src/guc.h): `src/guc.h`

### Other components

- **SQL User**
- **PostgreSQL**

## Connections

- SQL User → PostgreSQL: runs SQL (evidence: `README.md`)
- PostgreSQL → TimescaleDB Extension: uses extension (evidence: `README.md`)
- TimescaleDB Extension → Hypertable Management: creates hypertable (evidence: `README.md`)
- Hypertable Management → Chunk Metadata: partitions data (evidence: `README.md`)
- PostgreSQL → Insert Routing: inserts rows (evidence: `README.md`)
- Insert Routing → Hypertable Management: finds chunk (evidence: `src/chunk_tuple_routing.c`)
- PostgreSQL → Columnar Compression: writes columnstore (evidence: `README.md`)
- Columnar Compression → Compression Settings: uses settings (evidence: `tsl/src/compression/compression_storage.c`)
- PostgreSQL → Hypertable Planner: plans queries (evidence: `README.md`)
- Hypertable Planner → Chunk Append Scan: optimizes scans (evidence: `README.md`)
- PostgreSQL → Columnar Scan: queries columnstore (evidence: `README.md`)
- PostgreSQL → Vectorized Aggregation: runs analytics (evidence: `README.md`)
- PostgreSQL → Time Bucketing: groups by time (evidence: `README.md`)
- PostgreSQL → Continuous Aggregates: creates aggregates (evidence: `README.md`)
- Background Jobs → Continuous Aggregates: refreshes aggregates
- Hypertable Management → Metadata Catalog: references metadata (evidence: `src/hypertable.h`)
- Catalog Scan Iterator → Metadata Catalog: scans metadata (evidence: `src/scan_iterator.h`)
- Hypertable Planner → Hypertable Management: uses hypertable model (evidence: `src/planner/planner.c`)
- TimescaleDB Extension → Cross-Module Dispatch: dispatches features
- TimescaleDB Extension → Extension Configuration: configures behavior
- TimescaleDB Extension → PostgreSQL Compatibility: adapts PostgreSQL APIs
