TimescaleDB Time-Series Stack
Time-series database optimized for fast ingest and complex queries with visualization.
Overview
TimescaleDB is an open-source time-series database built as a PostgreSQL extension, combining the reliability and SQL capabilities of PostgreSQL with specialized time-series optimizations like automatic partitioning and compression. Developed by Timescale Inc., it addresses the limitations of traditional databases when handling high-volume time-series data while maintaining full PostgreSQL compatibility. This stack integrates TimescaleDB with Promscale (a Prometheus-TimescaleDB connector), Prometheus for metrics collection, and Grafana for visualization, creating a comprehensive observability platform. The combination leverages Promscale to bridge Prometheus's excellent short-term metrics collection with TimescaleDB's superior long-term storage and SQL query capabilities. Organizations benefit from this architecture when they need both real-time monitoring capabilities and historical data analysis, particularly in environments where correlating metrics with relational data is crucial. The stack is ideal for engineering teams building observability platforms, IoT companies managing device telemetry, and financial institutions requiring complex time-series analytics with the flexibility of SQL queries.
Key Features
- Automatic time-based partitioning (hypertables) for optimal query performance across large datasets
- Native Prometheus integration via Promscale for long-term metrics storage and PromQL compatibility
- 90%+ data compression using TimescaleDB's native compression algorithms
- Full PostgreSQL compatibility allowing joins between time-series and relational data
- Continuous aggregates for pre-computed rollups and faster dashboard queries
- Multi-dimensional data model with Prometheus labels stored as TimescaleDB dimensions
- Advanced SQL analytics capabilities including window functions and complex aggregations
- Grafana's native TimescaleDB data source with optimized time-series visualizations
Common Use Cases
- 1IoT platforms collecting sensor data that needs correlation with device metadata and user information
- 2DevOps teams requiring long-term Prometheus metrics storage beyond default 15-day retention
- 3Financial services analyzing trading data, market feeds, and risk metrics with complex SQL queries
- 4Manufacturing companies monitoring equipment performance and correlating with maintenance schedules
- 5SaaS applications tracking user behavior metrics alongside customer relationship data
- 6Energy companies managing smart grid data with geographic and temporal analysis requirements
- 7Healthcare systems storing patient monitoring data with integration to electronic health records
Prerequisites
- Minimum 4GB RAM recommended (TimescaleDB 2GB + Prometheus 1GB + Grafana 512MB + system overhead)
- Available ports 3000 (Grafana), 5432 (TimescaleDB), 9090 (Prometheus), and 9201 (Promscale)
- Basic understanding of PostgreSQL, SQL queries, and time-series data concepts
- Familiarity with Prometheus configuration and PromQL for metrics collection setup
- Docker Compose environment with persistent volume support for production deployments
- Network connectivity for Prometheus to scrape target applications and services
For development & testing. Review security settings, change default credentials, and test thoroughly before production use. See Terms
docker-compose.yml
docker-compose.yml
1services: 2 timescaledb: 3 image: timescale/timescaledb:latest-pg164 ports: 5 - "5432:5432"6 environment: 7 POSTGRES_USER: ${POSTGRES_USER}8 POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}9 POSTGRES_DB: ${POSTGRES_DB}10 volumes: 11 - timescale_data:/var/lib/postgresql/data12 healthcheck: 13 test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER} -d ${POSTGRES_DB}"]14 interval: 10s15 timeout: 5s16 retries: 517 networks: 18 - timescale-net19 restart: unless-stopped2021 promscale: 22 image: timescale/promscale:latest23 ports: 24 - "9201:9201"25 environment: 26 PROMSCALE_DB_URI: postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@timescaledb:5432/${POSTGRES_DB}?sslmode=disable27 depends_on: 28 timescaledb: 29 condition: service_healthy30 networks: 31 - timescale-net32 restart: unless-stopped3334 prometheus: 35 image: prom/prometheus:latest36 ports: 37 - "9090:9090"38 volumes: 39 - ./prometheus.yml:/etc/prometheus/prometheus.yml:ro40 - prometheus_data:/prometheus41 command: 42 - '--config.file=/etc/prometheus/prometheus.yml'43 - '--storage.tsdb.path=/prometheus'44 networks: 45 - timescale-net46 restart: unless-stopped4748 grafana: 49 image: grafana/grafana:latest50 ports: 51 - "3000:3000"52 environment: 53 - GF_SECURITY_ADMIN_PASSWORD=${GRAFANA_PASSWORD}54 volumes: 55 - grafana_data:/var/lib/grafana56 depends_on: 57 - timescaledb58 - prometheus59 networks: 60 - timescale-net61 restart: unless-stopped6263volumes: 64 timescale_data: 65 prometheus_data: 66 grafana_data: 6768networks: 69 timescale-net: 70 driver: bridge.env Template
.env
1# TimescaleDB2POSTGRES_USER=timescale3POSTGRES_PASSWORD=secure_postgres_password4POSTGRES_DB=timescale56# Grafana7GRAFANA_PASSWORD=secure_grafana_passwordUsage Notes
- 1TimescaleDB at localhost:5432
- 2Promscale for Prometheus long-term storage
- 3Grafana at http://localhost:3000
- 4Use hypertables for time-series data
Individual Services(4 services)
Copy individual services to mix and match with your existing compose files.
timescaledb
timescaledb:
image: timescale/timescaledb:latest-pg16
ports:
- "5432:5432"
environment:
POSTGRES_USER: ${POSTGRES_USER}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
POSTGRES_DB: ${POSTGRES_DB}
volumes:
- timescale_data:/var/lib/postgresql/data
healthcheck:
test:
- CMD-SHELL
- pg_isready -U ${POSTGRES_USER} -d ${POSTGRES_DB}
interval: 10s
timeout: 5s
retries: 5
networks:
- timescale-net
restart: unless-stopped
promscale
promscale:
image: timescale/promscale:latest
ports:
- "9201:9201"
environment:
PROMSCALE_DB_URI: postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@timescaledb:5432/${POSTGRES_DB}?sslmode=disable
depends_on:
timescaledb:
condition: service_healthy
networks:
- timescale-net
restart: unless-stopped
prometheus
prometheus:
image: prom/prometheus:latest
ports:
- "9090:9090"
volumes:
- ./prometheus.yml:/etc/prometheus/prometheus.yml:ro
- prometheus_data:/prometheus
command:
- "--config.file=/etc/prometheus/prometheus.yml"
- "--storage.tsdb.path=/prometheus"
networks:
- timescale-net
restart: unless-stopped
grafana
grafana:
image: grafana/grafana:latest
ports:
- "3000:3000"
environment:
- GF_SECURITY_ADMIN_PASSWORD=${GRAFANA_PASSWORD}
volumes:
- grafana_data:/var/lib/grafana
depends_on:
- timescaledb
- prometheus
networks:
- timescale-net
restart: unless-stopped
Quick Start
terminal
1# 1. Create the compose file2cat > docker-compose.yml << 'EOF'3services:4 timescaledb:5 image: timescale/timescaledb:latest-pg166 ports:7 - "5432:5432"8 environment:9 POSTGRES_USER: ${POSTGRES_USER}10 POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}11 POSTGRES_DB: ${POSTGRES_DB}12 volumes:13 - timescale_data:/var/lib/postgresql/data14 healthcheck:15 test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER} -d ${POSTGRES_DB}"]16 interval: 10s17 timeout: 5s18 retries: 519 networks:20 - timescale-net21 restart: unless-stopped2223 promscale:24 image: timescale/promscale:latest25 ports:26 - "9201:9201"27 environment:28 PROMSCALE_DB_URI: postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@timescaledb:5432/${POSTGRES_DB}?sslmode=disable29 depends_on:30 timescaledb:31 condition: service_healthy32 networks:33 - timescale-net34 restart: unless-stopped3536 prometheus:37 image: prom/prometheus:latest38 ports:39 - "9090:9090"40 volumes:41 - ./prometheus.yml:/etc/prometheus/prometheus.yml:ro42 - prometheus_data:/prometheus43 command:44 - '--config.file=/etc/prometheus/prometheus.yml'45 - '--storage.tsdb.path=/prometheus'46 networks:47 - timescale-net48 restart: unless-stopped4950 grafana:51 image: grafana/grafana:latest52 ports:53 - "3000:3000"54 environment:55 - GF_SECURITY_ADMIN_PASSWORD=${GRAFANA_PASSWORD}56 volumes:57 - grafana_data:/var/lib/grafana58 depends_on:59 - timescaledb60 - prometheus61 networks:62 - timescale-net63 restart: unless-stopped6465volumes:66 timescale_data:67 prometheus_data:68 grafana_data:6970networks:71 timescale-net:72 driver: bridge73EOF7475# 2. Create the .env file76cat > .env << 'EOF'77# TimescaleDB78POSTGRES_USER=timescale79POSTGRES_PASSWORD=secure_postgres_password80POSTGRES_DB=timescale8182# Grafana83GRAFANA_PASSWORD=secure_grafana_password84EOF8586# 3. Start the services87docker compose up -d8889# 4. View logs90docker compose logs -fOne-Liner
Run this command to download and set up the recipe in one step:
terminal
1curl -fsSL https://docker.recipes/api/recipes/timescaledb-stack/run | bashTroubleshooting
- Promscale connection failed: Ensure TimescaleDB health check passes before Promscale starts, check database credentials in PROMSCALE_DB_URI
- High memory usage in TimescaleDB: Enable compression on hypertables using SELECT add_compression_policy() and adjust shared_buffers in postgresql.conf
- Prometheus remote write errors: Verify Promscale is accessible on port 9201 and add remote_write configuration pointing to http://promscale:9201/write
- Grafana cannot connect to TimescaleDB: Use connection string postgres://username:password@timescaledb:5432/database and ensure TimescaleDB service is healthy
- Slow query performance: Create proper time-based indexes on hypertables and use time-bucketing functions like time_bucket() for aggregations
- Data retention issues: Configure data retention policies using SELECT add_retention_policy() for automated old data cleanup
Community Notes
Loading...
Loading notes...
Download Recipe Kit
Get all files in a ready-to-deploy package
Includes docker-compose.yml, .env template, README, and license
Components
timescaledbgrafanapromscaleprometheus
Tags
#timescaledb#time-series#postgresql#iot#metrics
Category
Database StacksAd Space
Shortcuts: C CopyF FavoriteD Download