Module A-15·23 min read

How Postgres extensions replace entire categories of specialized databases — without leaving ACID behind.

JJS
Written by Jatin Jain Saraf · Senior Software Engineer

Module 15 — The Extensions Ecosystem: pg_cron, TimescaleDB, Citus, and pgvector

What this module covers: PostgreSQL's extension system is its most underappreciated feature. Extensions add capabilities that match or exceed dedicated NoSQL databases — without leaving the ACID guarantees, SQL interface, and operational tooling you already have. This module covers the four extensions that most frequently eliminate the need for a separate database: pg_cron for background job scheduling, TimescaleDB for time-series at scale, Citus for horizontal sharding, and pgvector for AI/embedding workloads.


Why Extensions Matter

In Module 11, we compared Postgres to MongoDB, Cassandra, and ClickHouse. Those comparisons assumed vanilla Postgres. With extensions, the picture changes:

  • Need time-series with columnar compression? → TimescaleDB makes Postgres competitive with InfluxDB and ClickHouse
  • Need horizontal write scaling? → Citus distributes Postgres across many nodes
  • Need vector similarity search for AI? → pgvector makes Postgres competitive with Pinecone and Weaviate
  • Need background job scheduling? → pg_cron replaces external cron + application-layer job tables

Each extension adds specialized capabilities while keeping the full Postgres stack: MVCC, WAL, ACID, SQL, pg_stat_*, your existing monitoring, your existing connection pooler, your existing backup tooling.


pg_cron: Background Job Scheduling Inside Postgres

pg_cron runs SQL or stored procedures on a cron schedule, directly inside the database process. No external scheduler, no separate worker service, no application-layer job table.

Installation and Setup

sql

Scheduling Jobs

sql

Managing Jobs

sql

When pg_cron Is the Right Tool

pg_cron is ideal for:

  • Database maintenance tasks (ANALYZE, VACUUM, partition creation)
  • Data retention cleanup (delete rows older than N days)
  • Periodic aggregation into summary tables
  • Refreshing materialized views on a schedule

It is not suitable for:

  • Long-running jobs that need external resources (API calls, file I/O)
  • Jobs that need distributed coordination across multiple Postgres instances
  • Jobs with complex dependency graphs (use Airflow, Prefect, or similar)

TimescaleDB: Time-Series at Postgres Scale

TimescaleDB is an open-source extension that adds automatic time-based partitioning (hypertables), columnar compression, and time-series-specific query functions on top of Postgres.

Hypertables

A hypertable is a Postgres table with automatic time-based partitioning managed by TimescaleDB. Data is partitioned into "chunks" automatically — no manual CREATE TABLE partition ... required.

sql

The hypertable looks and behaves like a regular Postgres table. All standard SQL works. TimescaleDB handles partitioning transparently.

Columnar Compression

TimescaleDB's native columnar compression is the feature that makes it genuinely competitive with InfluxDB and ClickHouse for time-series workloads.

sql

Typical compression ratios for time-series data: 10–40x. A 100GB raw metrics table becomes 3–10GB compressed. Compressed chunks are read using a columnar scan — only the requested columns are decompressed, dramatically reducing I/O for aggregation queries.

Continuous Aggregates

Continuous aggregates are materialized views that update automatically as new data arrives:

sql

Sign in to keep reading

The rest of this module is free — sign in with Google to unlock it and track your progress.

Sign in & Register

Discussion

0

Join the discussion

Loading comments...

© 2026 Jatin Jain Saraf (JJS). All rights reserved.