Deploy TimescaleDB | Open Source Time-Series Database for PostgreSQL
Railway

Deploy TimescaleDB | Open Source Time-Series Database for PostgreSQL

Self Host TimescaleDB on Railway: hypertables, compression, full SQL & more

Deploy TimescaleDB | Open Source Time-Series Database for PostgreSQL

Just deployed

/var/lib/postgresql/data

TimescaleDB logo

Deploy and Host TimescaleDB on Railway

Deploy TimescaleDB on Railway to get a fully managed, persistent time-series database running in minutes. TimescaleDB is a PostgreSQL extension that transforms Postgres into a high-performance time-series database — hypertables, continuous aggregates, columnar compression, and real-time analytics, all with full SQL support.

Self-host TimescaleDB on Railway with this template and get a production-ready instance backed by persistent volume storage, automatic performance tuning via timescaledb-tune, and external TCP proxy access. The template deploys timescale/timescaledb:2.18.0-pg16 with a single service — no additional dependencies required since TimescaleDB runs as a native PostgreSQL extension.

Getting Started with TimescaleDB on Railway

After deployment, connect to your TimescaleDB instance using the external TCP proxy endpoint shown in the Railway dashboard (format: host:port). Use any PostgreSQL client — psql, pgAdmin, DBeaver, or your application's Postgres driver.

The TimescaleDB extension is pre-installed and ready to use. Create your first hypertable by running:

CREATE TABLE metrics (
  time TIMESTAMPTZ NOT NULL,
  device_id TEXT,
  temperature DOUBLE PRECISION,
  humidity DOUBLE PRECISION
);

SELECT create_hypertable('metrics', 'time');

Enable compression for long-term storage efficiency:

ALTER TABLE metrics SET (
  timescaledb.compress,
  timescaledb.compress_segmentby = 'device_id'
);

SELECT add_compression_policy('metrics', INTERVAL '7 days');

Your database credentials (POSTGRES_USER, POSTGRES_PASSWORD, POSTGRES_DB) are set as environment variables in Railway. Use the internal hostname timescaledb.railway.internal:5432 for service-to-service connections within the same Railway project.

About Hosting TimescaleDB

TimescaleDB (by Tiger Data, formerly Timescale) is a PostgreSQL extension with 22,000+ GitHub stars that adds time-series superpowers to the world's most trusted relational database. Unlike purpose-built TSDBs that force you to learn new query languages, TimescaleDB uses standard SQL — your existing Postgres knowledge, tools, and ORMs work immediately.

Key features:

  • Hypertables — automatic time-based partitioning, transparent to queries
  • Continuous aggregates — materialized views that refresh incrementally
  • Columnar compression — 10-15x storage reduction with automatic policies
  • Data retention — automatic drop policies for aging data
  • Full PostgreSQL — JOINs, foreign keys, indexes, extensions (PostGIS, pgvector)
  • Automatic tuningtimescaledb-tune optimizes Postgres config for your hardware

Why Deploy TimescaleDB on Railway

One-click deployment with zero infrastructure management:

  • Persistent volume storage — data survives redeploys and restarts
  • TCP proxy for secure external connections from any Postgres client
  • Auto-tuned performance based on container resources
  • Private networking for low-latency service-to-service connections
  • Full PostgreSQL ecosystem compatibility out of the box

Common Use Cases for Self-Hosted TimescaleDB

  • IoT telemetry — ingest millions of sensor readings per second with compression for historical data
  • DevOps monitoring — store infrastructure metrics (CPU, memory, network) and power Grafana dashboards
  • Financial analytics — record trades, pricing trends, and risk metrics with relational JOINs across account data
  • Application observability — track API response times, error rates, and user activity with real-time aggregation

Dependencies for TimescaleDB on Railway

  • TimescaleDBtimescale/timescaledb:2.18.0-pg16 (PostgreSQL 16 with TimescaleDB 2.18.0 extension)

No additional database or cache service is required — TimescaleDB is self-contained.

Environment Variables Reference for TimescaleDB

VariableDescriptionDefault
POSTGRES_USERDatabase superuser namepostgres
POSTGRES_PASSWORDDatabase superuser passwordRequired
POSTGRES_DBDefault database namepostgres
PGDATAData directory path/var/lib/postgresql/data/pgdata
TIMESCALEDB_TELEMETRYTelemetry level (off to disable)basic

Deployment Dependencies

Hardware Requirements for Self-Hosting TimescaleDB

ResourceMinimumRecommended
CPU1 vCPU2-4 vCPUs
RAM2 GB4-8 GB
Storage1 GB SSD10+ GB SSD (scales with data)
RuntimeDockerDocker

TimescaleDB auto-tunes PostgreSQL configuration based on available resources using timescaledb-tune. SSD storage is strongly recommended — HDD severely impacts query performance on time-series workloads.

Self-Hosting TimescaleDB with Docker

Run TimescaleDB locally with Docker:

docker run -d --name timescaledb \
  -p 5432:5432 \
  -v timescaledb_data:/var/lib/postgresql/data \
  -e POSTGRES_PASSWORD=mysecretpassword \
  -e PGDATA=/var/lib/postgresql/data/pgdata \
  timescale/timescaledb:2.18.0-pg16

Or with Docker Compose:

services:
  timescaledb:
    image: timescale/timescaledb:2.18.0-pg16
    ports:
      - "5432:5432"
    environment:
      POSTGRES_PASSWORD: mysecretpassword
      POSTGRES_DB: timescaledb
      PGDATA: /var/lib/postgresql/data/pgdata
    volumes:
      - timescaledb_data:/var/lib/postgresql/data

volumes:
  timescaledb_data:

Connect with psql: psql -h localhost -U postgres -d timescaledb

How Much Does TimescaleDB Cost to Self-Host?

TimescaleDB is dual-licensed under Apache 2.0 (core) and Timescale License (advanced features like compression policies and continuous aggregates). Both are free for self-hosting — the TSL only restricts offering TimescaleDB as a managed database service.

Self-hosting on Railway costs only infrastructure. A basic instance runs comfortably on Railway's standard resources. Tiger Data's managed cloud (Tiger Cloud) starts at $30/month for comparison, making self-hosting on Railway significantly more cost-effective.

TimescaleDB vs InfluxDB

FeatureTimescaleDBInfluxDB
Query languageFull SQLInfluxQL / Flux / SQL (v3)
Relational JOINsYes (native PostgreSQL)Limited
EcosystemPostgreSQL (pgAdmin, ORMs, extensions)Proprietary tooling
Compression10-15xCustom columnar
Best forMixed workloads (time-series + relational)Pure metrics/monitoring

TimescaleDB is the better choice when you need to JOIN time-series data with relational tables or want to leverage the PostgreSQL ecosystem.

FAQ

What is TimescaleDB and why self-host it? TimescaleDB is a PostgreSQL extension that adds time-series capabilities — hypertables, compression, continuous aggregates, and retention policies. Self-hosting gives you full control over data, zero vendor lock-in, and cost savings compared to managed time-series services.

What does this Railway template deploy? This template deploys a single TimescaleDB service using the timescale/timescaledb:2.18.0-pg16 Docker image with a persistent volume for data storage and a TCP proxy for external access. The TimescaleDB extension comes pre-installed and auto-enabled.

Why is PGDATA set to a subdirectory of the volume mount? Railway volumes contain a lost+found directory at the mount root. PostgreSQL's initdb refuses to initialize in a non-empty directory. Setting PGDATA to a subdirectory (/var/lib/postgresql/data/pgdata) avoids this conflict.

How do I connect Grafana to self-hosted TimescaleDB on Railway? Use the PostgreSQL data source in Grafana. For services within the same Railway project, use the internal hostname timescaledb.railway.internal:5432. For external Grafana instances, use the TCP proxy endpoint provided by Railway.

Can I use TimescaleDB with my existing PostgreSQL application? Yes — TimescaleDB is a PostgreSQL extension, not a separate database. Your existing tables, queries, indexes, and application code work unchanged. You only use hypertables for the time-series tables that need them.

How do I enable continuous aggregates on self-hosted TimescaleDB? Create a continuous aggregate with CREATE MATERIALIZED VIEW ... WITH (timescaledb.continuous) AS SELECT time_bucket(...) .... Then add a refresh policy with SELECT add_continuous_aggregate_policy(...). This works out of the box on the deployed image.


Template Content

More templates in this category

View Template
caring-vibrancy
Deploy and Host caring-vibrancy with Railway

View Template
Flask WebSocket Chat
Single file, realtime multi-user websocket chat using flask-socketio

Clement Ochieng
View Template
all-star-fashion-template
Deploy and Host all-star-fashion-template with Railway

Mai Thành Duy An