TimescaleDB PostgreSQL Time-Series: Setup Hypertable Compression 1000x Faster
Back to articles

TimescaleDB PostgreSQL Time-Series: Setup Hypertable Compression 1000x Faster

TimescaleDB Postgres extension hypertables continuous aggregates 90% compression 1M inserts/s IoT DevOps monitoring Docker setup production schema

Software Updated: January 8, 2026

TimescaleDB คือ PostgreSQL Extension สำหรับ Time-Series Data: เร็ว 1000x บีบอัด 90%
TimescaleDB เปลี่ยน PostgreSQL ให้เป็น time-series database ชั้นนำ ใช้ hypertables แบ่ง chunk อัตโนมัติ ACID compliant รองรับ IoT monitoring DevOps metrics

TimescaleDB vs PostgreSQL Performance

MetricPostgreSQLTimescaleDB
Insert Speed10K rows/s1M+ rows/s
Query Speed100ms0.1ms
Storage100GB10GB (90% less)
Compression95% native

Core Features

✅ Hypertables: Auto-partition by time
✅ Continuous Aggregates: Materialized views
✅ Compression: 90-95% storage reduction
✅ Retention Policies: Auto-drop old data
✅ SQL 100%: Full PostgreSQL features

Quick Setup & Hypertable

-- 1. Enable extension
CREATE EXTENSION timescaledb;
-- 2. Create hypertable (1 command!)
CREATE TABLE metrics (
time TIMESTAMPTZ NOT NULL,
device_id TEXT,
value DOUBLE PRECISION
);
SELECT create_hypertable('metrics', 'time');
-- 3. Insert 1M rows/second
INSERT INTO metrics (time, device_id, value)
VALUES (NOW(), 'sensor1', 23.5);
-- 4. Fast queries
SELECT time_bucket('1 hour', time) AS hour,
AVG(value) FROM metrics
GROUP BY hour ORDER BY hour DESC;

Production Use Cases

📊 DevOps: Prometheus remote storage
🔌 IoT: Sensor data (1M+ devices)
💰 Fintech: Tick data/trades
🎮 Gaming: Player metrics
🌡️ Observability: Cloudflare/Netflix

Continuous Aggregates (Magic)

-- Auto-aggregate every 5min
CREATE MATERIALIZED VIEW hourly_avg
WITH (timescaledb.continuous) AS
SELECT time_bucket('1 hour', time) AS hour,
AVG(value) AS avg_temp
FROM metrics GROUP BY hour;
-- Auto-refreshed, query like normal table
SELECT * FROM hourly_avg WHERE hour > NOW() - INTERVAL '1 day';

Compression Setup

-- Compress chunks > 7 days old
ALTER TABLE metrics SET (
timescaledb.compress,
timescaledb.compress_segmentby = 'device_id'
);
-- 90% storage reduction, 15x query speedup
SELECT * FROM metrics_compressed;

Docker Production Setup

# docker-compose.yml
services:
postgres:
image: timescale/timescaledb:latest-pg16
environment:
POSTGRES_DB: metrics
POSTGRES_PASSWORD: password
ports:
- "5432:5432"
volumes:
- pgdata:/var/lib/postgresql/data
volumes:
pgdata:

Schema Best Practices

✅ time TIMESTAMPTZ first column
✅ Partition: time_bucket('1h', time)
✅ Index: CREATE INDEX ON metrics (device_id, time DESC)
✅ Compress: >7 days old
✅ Retain: 90 days policy

Cloud Options 2026

ProviderManagedPrice
Timescale Cloud✅ Serverless$0.02/GB
Aiven$0.10/GB
AWS RDSManual$0.15/GB
Supabase$0.05/GB
D

DRITESTUDIO

DRITESTUDIO COMPANY LIMITED - Cloud, VPS, Hosting and Colocation provider in Thailand

Manage your cookie settings

We use different types of cookies to optimize your experience on our website. Click on the categories below to learn more and customize your preferences. Note that blocking some types of cookies may impact your experience.

Necessary Cookies

These cookies are essential for the website to function properly. They enable basic functions like page navigation and access to secure areas.

View cookies used
  • Session cookies (session management)
  • Security cookies (CSRF protection)
Always On

Functional Cookies

These cookies enable personalized features like language preferences and theme settings. Without these, some features may not work properly.

View cookies used
  • lang (language preference)
  • theme (dark/light mode)

Analytics Cookies

These cookies help us understand how visitors interact with our website by collecting and reporting information anonymously.

View cookies used
  • _ga (Google Analytics)
  • _gid (Google Analytics)

Marketing Cookies

These cookies are used to track visitors across websites to display relevant advertisements based on your interests.

View cookies used
  • Advertising cookies
  • Remarketing pixels

Privacy Policy