PostgreSQL
An open-source, ACID relational database with a SQL planner, strong types, constraints, server-side functions and a large extension ecosystem (pgvector, PostGIS, TimescaleDB). Every commit is written to the write-ahead log first, and that log drives crash recovery, replication and point-in-time restore. PostgreSQL licence (BSD-style), free, no paid tier. It fits any workload of concurrent, transactional, tabular reads and writes; analytics over billions of rows and deep graph traversals fit other engines better.
PostgreSQL is an open-source relational database for data that is tabular, written by many clients at once and needs real transactional guarantees. It stores typed rows under constraints the server enforces, and it runs domain logic next to the data in server-side functions. The official docs at postgresql.org/docs own the SQL reference; this page covers how it works, when it fits and how it runs in the GL stack.
What it is
A relational, ACID-compliant SQL database. One server process per connection, streaming replicas for read scaling and hot standby for failover. Tables carry strong types, foreign keys and check constraints, and the query planner has been refined over decades of releases. The licence is the PostgreSQL Licence, a short BSD-style licence. There is no enterprise tier.
Release line. A new major version ships about once a year, and each major gets five years of minor releases. The current majors are 18 (18.6) and 17 (17.11); the latest minors for every supported line shipped on 2026-08-13. PostgreSQL 19 RC 1 shipped on 2026-10-15; the project advises against running a release candidate in production. PostgreSQL 14 reaches end of life on 2026-11-12.
PostgreSQL 18 added an asynchronous I/O subsystem (io_method = worker, io_uring or sync), planner statistics kept through pg_upgrade, uuidv7(), virtual generated columns as the default, oauth authentication and skip scan on multicolumn B-tree indexes. Two changes matter on upgrade: md5 password authentication is deprecated (use SCRAM), and initdb now enables data checksums by default, so pg_upgrade from a cluster without checksums needs the new cluster created with --no-data-checksums.
Distribution: official packages for Linux and macOS, the Docker image, Kubernetes operators (CloudNativePG and others) and managed offerings on every cloud. The wire protocol is stable, and libpq-based drivers exist for every major language.
How it works
A client connects to the postmaster, which forks a backend process for that connection. The backend parses, plans and runs each statement against shared buffers in memory. A change is first written as a record to the write-ahead log (WAL). At COMMIT, PostgreSQL flushes the WAL to disk before it reports success; the changed data pages are written to the table files later, by the background writer and at checkpoints. After a crash, the server replays WAL from the last checkpoint to rebuild a consistent state.
The same WAL stream is the basis for replication and backup. Streaming replicas apply it continuously. Continuous archiving copies each completed WAL segment to an archive (archive_command or archive_library, with wal_level at replica or higher). A base backup plus the archived WAL after it allows point-in-time recovery (PITR): restore the base backup, set restore_command and a recovery_target_time, and the server replays WAL up to that moment. Each completed recovery starts a new timeline, so later archives do not overwrite the history they branched from. PITR works on the whole cluster only; a single database cannot be restored this way, which is why a logical pg_dump per database is still useful next to it.
In a Kubernetes setup with CloudNativePG, the operator configures archiving for each instance, the Barman Cloud plugin sidecar uploads WAL segments and base backups to S3-compatible storage, and a restore always bootstraps a new cluster from that store.
Step 1 of 4. The API runs SELECT on a function such as fn_place_order with typed arguments. The whole function body runs in one transaction.
A transactional write through a stored procedure, and a point-in-time restore into a new cluster with CloudNativePG.
The figure shows the two paths that matter most for a self-hosted database: how a committed write becomes durable and then off-site, and how that off-site copy turns back into a running database at a chosen moment.
When to use it
Reach for it when:
- The data is tabular: users, accounts, positions, trades, subscriptions. Rows, columns, foreign keys.
- You need multi-row transactions that commit or roll back as one unit.
- The team and its tools speak SQL: every BI tool and most LLM coding tools write queries against it.
- The workload is OLTP: many small reads and writes, low latency, high concurrency.
- You want extensions: pgvector for embeddings, PostGIS for geospatial, TimescaleDB for time series, pgTAP for SQL unit tests.
- You want to move between hosts later: managed offerings run the same engine and protocol, so a dump and restore moves the data.
Skip it when:
- The workload is analytics over very large scans: columnar engines such as DuckDB or ClickHouse are built for it.
- The data is graph-shaped and queries walk many hops: recursive CTEs get slow and hard to read. Use Neo4j.
- The need is single-file and zero-ops: an embedded database such as SQLite fits better than a server.
- The state is ephemeral: caches, sessions, rate-limit counters. Redis fits that shape.
At a glance
Core concepts
- Table: rows of typed columns with constraints (NOT NULL, UNIQUE, CHECK, FOREIGN KEY).
- Schema: a namespace for tables, functions and types inside one database.
- Transaction: BEGIN / COMMIT / ROLLBACK. The default isolation is READ COMMITTED; REPEATABLE READ and SERIALIZABLE are available.
- MVCC: each update writes a new row version. VACUUM reclaims old versions once no transaction can see them.
- Index: B-tree by default; GIN for JSONB and full-text; GiST for geometry; BRIN for very large append-only tables.
- Function / procedure: server-side logic in PL/pgSQL or SQL. Logic that must be transactional runs next to the data.
- WAL: the write-ahead log behind durability, replication and PITR.
- Extension: a packaged add-on loaded with
CREATE EXTENSION, for exampleCREATE EXTENSION vector;.
Supported versions (as of 2026-10-17)
| Major | Current minor | First release | End of support |
|---|---|---|---|
| 18 | 18.6 | 2025-09-25 | 2030-11-14 |
| 17 | 17.11 | 2024-09-26 | 2029-11-08 |
| 16 | 16.15 | 2023-09-14 | 2028-11-09 |
| 15 | 15.19 | 2022-10-13 | 2027-11-11 |
| 14 | 14.24 | 2021-09-30 | 2026-11-12 |
Minor upgrades replace the binaries and restart; no dump is needed. Major upgrades need pg_upgrade or a dump and reload.
Backup methods
| Method | What it captures | Restore granularity | Point in time |
|---|---|---|---|
pg_dump |
One database, as SQL or a custom archive | One database, or chosen tables | No, only the moment of the dump |
| Base backup + WAL archive | The whole cluster, physically | The whole cluster | Yes, any moment inside the archive |
| Streaming replica | A live copy of the whole cluster | Failover only | No, it replays mistakes too |
How to integrate
Run it on Kubernetes with CloudNativePG
An ObjectStore describes the bucket, the Cluster names it as its WAL archiver, and a ScheduledBackup takes the base backups.
apiVersion: barmancloud.cnpg.io/v1
kind: ObjectStore
metadata:
name: backup-store
spec:
configuration:
destinationPath: s3://pg-backups/
endpointURL: http://object-store:8333
s3Credentials:
accessKeyId:
name: backup-store-creds
key: ACCESS_KEY_ID
secretAccessKey:
name: backup-store-creds
key: ACCESS_SECRET_KEY
wal:
compression: gzip
retentionPolicy: "14d"
---
apiVersion: postgresql.cnpg.io/v1
kind: Cluster
metadata:
name: pg
spec:
instances: 1
imageName: ghcr.io/cloudnative-pg/postgresql:17.11
storage:
size: 20Gi
plugins:
- name: barman-cloud.cloudnative-pg.io
isWALArchiver: true
parameters:
barmanObjectName: backup-store
---
apiVersion: postgresql.cnpg.io/v1
kind: ScheduledBackup
metadata:
name: pg-nightly
spec:
schedule: "0 0 2 * * *" # six fields: seconds first
cluster:
name: pg
method: plugin
pluginConfiguration:
name: barman-cloud.cloudnative-pg.io
A point-in-time restore is a new Cluster whose bootstrap.recovery.source names an externalClusters entry that uses the same plugin, barmanObjectName and the original serverName, with recoveryTarget.targetTime set to a timestamp that carries a timezone.
Put the logic in the database
CREATE FUNCTION app.fn_place_order(p_user_id bigint, p_sku text, p_qty int)
RETURNS bigint
LANGUAGE plpgsql AS $$
DECLARE v_order_id bigint;
BEGIN
IF p_qty <= 0 THEN
RAISE EXCEPTION 'qty must be positive';
END IF;
UPDATE app.stock SET on_hand = on_hand - p_qty
WHERE sku = p_sku AND on_hand >= p_qty;
IF NOT FOUND THEN
RAISE EXCEPTION 'insufficient stock for %', p_sku;
END IF;
INSERT INTO app.orders (user_id, sku, qty)
VALUES (p_user_id, p_sku, p_qty)
RETURNING id INTO v_order_id;
RETURN v_order_id;
END $$;
The application calls SELECT app.fn_place_order($1, $2, $3). The function is the contract: diffs to it are reviewable, and pgTAP tests (SELECT has_function(...), SELECT throws_ok(...)) run against the real schema with pg_prove.
Keep a logical dump too
pg_dump --format=custom --file="app-$(date +%F).dump" "$DATABASE_URL"
pg_restore --list "app-$(date +%F).dump" > /dev/null # proves the file reads back
A per-database dump restores one product without touching the others, which a physical, whole-cluster restore cannot do.
In the GL stack
Postgres 17.11 runs as one CloudNativePG cluster on each of the beta and prod Kubernetes clusters. The image carries pgTAP. One cluster serves every product, with one database per product, so paiddaily.io, sagedaily.io and the others each own their schema and roles without a server each.
- Logic in stored procedures. Business logic lives in database functions, and the applications call them instead of sending inline SQL. pgTAP tests in the image cover those functions.
- Beta is a copy of prod. Beta databases are snapshots refreshed from prod, so beta runs against realistic data without writing to prod.
- Backups, two layers. CloudNativePG 1.30.1 with the Barman Cloud plugin v0.15.1 takes a nightly base backup and archives WAL continuously to the S3 backup store on SeaweedFS, with 14 days of retention. Velero skips the database volumes, because the operator's backups already cover them. A point-in-time restore has been drilled. On top of that, a nightly
pg_dumpof each database is kept for 7 days on the VM and 14 days in the backup store, for single-database restores. - Old names kept. The Kubernetes services keep the names of the container-era database, so every connection string in every product kept working through the move to the operator.
- Restart by pod. CloudNativePG manages the pods directly, not through a Deployment, so a restart means deleting the instance pod and letting the operator recreate it, not
kubectl rollout restart. - Airflow is separate. The shared Airflow keeps its own Postgres, so scheduler load and metadata churn stay out of the product databases.
Gotchas
- Connection count. Each connection is a process. Many idle clients without a pooler waste memory; put PgBouncer (CloudNativePG ships a
Poolerresource for it) between the apps and the server. - Long transactions block VACUUM. A transaction left open for hours keeps old row versions alive and tables bloat. Set
idle_in_transaction_session_timeout. - READ COMMITTED is the default. Two concurrent read-then-write transactions can both act on stale reads. Use
SELECT ... FOR UPDATEor SERIALIZABLE with retries where it matters. - Archive failures can be quiet.
pg_stat_archiverdoes not show every failure mode (a command killed by a signal, exit codes above 125). Alert on the age of the last archived WAL, not only on errors. - A full
pg_walstops the server. If archiving stalls, WAL piles up until the disk fills and PostgreSQL shuts down with a PANIC. Size the volume with headroom and alert on usage. - PITR targets need a timezone. CloudNativePG reads a
targetTimewithout one as UTC, and recovery fails if no transaction happened after the target. - Config files are not in WAL.
postgresql.confandpg_hba.confare not in a base backup restore; keep them in Git or in the operator spec. - md5 on the way out. PostgreSQL 18 deprecates
md5password authentication. Move roles to SCRAM before a major upgrade.
Risks
- Vertical scaling first. One large server goes a long way. Sharding needs Citus or an application-level layer, which is a real project.
- Major upgrades are real work.
pg_upgradeor dump and reload, extension version checks, and the PostgreSQL 18 checksum default. Plan a window and rehearse on a copy. - Backups are only as good as the last restore. A self-hosted setup has no provider behind it. Drill a restore on a schedule, not only once.
- Project health is strong. A community project with many contributing companies, a fixed release cadence and published end-of-life dates. The licence permits forks and commercial use without fees.
Alternatives
- MySQL / MariaDB: pick when inheriting an existing MySQL estate or tooling. Fewer data types and a smaller extension ecosystem.
- SQLite: pick for single-process, embedded, single-file data. No server boundary and one writer at a time. See SQLite.
- CockroachDB / YugabyteDB: pick when multi-region writes with strong consistency are a hard requirement. Higher cost and operational weight for a single-site system.
- DuckDB: pick for embedded analytics over Parquet or CSV next to Postgres. Not built for many concurrent writers. See DuckDB.
Related
- CloudNativePG: the operator that runs the cluster, its failover and its backups.
- SeaweedFS and Velero: the S3 backup store and the cluster-level backups around it.
- Airflow: the scheduler that keeps its own Postgres.
- Neo4j and Redis: the graph and cache stores that sit next to Postgres.
- paiddaily.io database: schemas, migrations and procedures for one product.
- Official: PostgreSQL docs, versioning policy, continuous archiving and PITR, CloudNativePG recovery.
