DEV Community

Shahid
Shahid

Posted on

Stop Running 5 Databases: PostgreSQL Does It All in 2026

How a 35-year-old open-source database became the default choice for relational storage, full-text search, vector AI workloads, geospatial queries, and event-driven architecture — in a single deployment.


Most production architectures look like a small city: a relational database for core data, a document store for flexible schemas, an Elasticsearch cluster for search, a vector database for AI-powered features, and a message broker stitching it all together. Five services. Five deployment pipelines. Five monitoring dashboards. Five points of failure — all to solve problems that, in most applications, one database already handles.

That database is PostgreSQL. It started as a research project at UC Berkeley in the 1980s and has quietly evolved into one of the most capable data platforms ever built. In 2026, as teams race to bolt AI onto their stacks without doubling infrastructure costs, Postgres has emerged as the default answer — not because it's new, but because it was built right.


What Makes Postgres Different

At its core, Postgres is a relational, ACID-compliant SQL database: tables, rows, foreign keys, joins, everything you'd expect. What separates it architecturally from MySQL or SQLite is that it was built for extensibility from day one. There is a formalized plugin API that lets you add new data types, new index strategies, and entirely new capabilities via a single CREATE EXTENSION command. This is not a bolt-on feature or a marketing checkbox — it is a deeply deliberate design choice baked into the query engine itself.

The result: Postgres doesn't just store data. It becomes the entire data layer of your application, without stitching together a fleet of specialized services you need to deploy, monitor, and keep in sync.


Replacing the Document Store: JSONB

The standard pitch for MongoDB has always been: relational schemas are too rigid for modern applications. Postgres answers that directly with JSONB — a binary-encoded JSON column type that lets you store fully schemaless documents right next to your strict relational tables, in the same database, under the same transaction.

You can query deep into nested JSON using path expressions, check for key existence, test containment, and — critically — put a GIN index on the entire document so those queries stay fast at scale:

CREATE TABLE users (
  id     SERIAL PRIMARY KEY,
  email  TEXT NOT NULL,
  data   JSONB
);

CREATE INDEX idx_users_data ON users USING GIN (data);

-- Find all users on the 'pro' plan
SELECT email
FROM users
WHERE data @> '{"plan": "pro"}';
Enter fullscreen mode Exit fullscreen mode

Your schemaless layer and your relational layer live in the same table, under the same backup, in the same SELECT. No data synchronization. No eventual consistency headaches. No second server.


Replacing Elasticsearch: Built-in Full-Text Search

Elasticsearch is powerful — but it's also one of the heaviest pieces of infrastructure you can operate. It needs its own cluster, its own memory tuning, its own index lifecycle management, and it demands you keep two copies of your data in sync at all times.

Postgres has a native full-text search engine that handles tokenization, stemming (so "running" matches "run" and "runs"), stop-word filtering, relevance ranking, and indexed retrieval. For the overwhelming majority of product search boxes and content discovery features, it is more than sufficient:

-- GIN-indexed full-text search
CREATE INDEX idx_articles_fts
ON articles USING GIN (to_tsvector('english', title || ' ' || body));

-- Ranked search results
SELECT title,
       ts_rank(to_tsvector('english', title || ' ' || body), query) AS rank
FROM articles,
     to_tsquery('english', 'distributed & systems') AS query
WHERE to_tsvector('english', title || ' ' || body) @@ query
ORDER BY rank DESC;
Enter fullscreen mode Exit fullscreen mode

The only time Elasticsearch genuinely pulls ahead is at massive scale with advanced requirements — complex multi-language synonym pipelines, cross-cluster federation, or deep faceted navigation. For everything else, Postgres saves you an entire infrastructure tier.


Replacing Pinecone and Weaviate: AI-Native Vector Search

This is the capability that has become non-negotiable in 2026. Every application now has an AI feature. Every AI feature needs semantic search. The pgvector extension adds a native vector column type and approximate nearest-neighbor (ANN) search, making Postgres the backbone of Retrieval-Augmented Generation (RAG) pipelines without standing up a dedicated vector database.

CREATE EXTENSION IF NOT EXISTS vector;

CREATE TABLE documents (
  id        SERIAL PRIMARY KEY,
  content   TEXT,
  embedding vector(1536)
);

-- HNSW index for fast approximate nearest-neighbor search
CREATE INDEX ON documents USING hnsw (embedding vector_cosine_ops);

-- Semantic similarity search
SELECT content,
       1 - (embedding <=> '[0.12, 0.47, ...]') AS similarity
FROM documents
ORDER BY embedding <=> '[0.12, 0.47, ...]'
LIMIT 5;
Enter fullscreen mode Exit fullscreen mode

For workloads under roughly 100 million vectors, Postgres with pgvector eliminates dedicated vector database overhead with no measurable quality trade-off. The real advantage over standalone vector databases isn't just eliminating a service — it's composability: your vector search can be combined with WHERE filters, JOINs across tables, and Row-Level Security in a single query. Pinecone cannot join against your application data. Postgres can.


Replacing Redis and RabbitMQ: Queues and Pub/Sub

Two underused, underappreciated Postgres features handle most messaging needs without introducing a broker.

LISTEN / NOTIFY is a lightweight pub/sub mechanism built directly into the wire protocol. One session publishes a text payload to a named channel; every subscribed session receives it in milliseconds. It's not Kafka — but for triggering background workers, pushing cache invalidation events, or wiring up a simple notification system, it's zero-infrastructure pub/sub.

SELECT FOR UPDATE SKIP LOCKED turns an ordinary table into a reliable, concurrent job queue. Multiple workers pull jobs simultaneously without race conditions, because each SELECT atomically locks the row it claims and skips all rows already locked by other workers:

-- Worker atomically claims the next available job
BEGIN;

SELECT * FROM jobs
WHERE status = 'pending'
ORDER BY created_at
FOR UPDATE SKIP LOCKED
LIMIT 1;

-- ... process the job ...

UPDATE jobs SET status = 'done' WHERE id = :id;
COMMIT;
Enter fullscreen mode Exit fullscreen mode

If a worker crashes mid-job, the transaction rolls back and the row becomes claimable again — automatic exactly-once delivery, built on the ACID guarantees you already have.


Replacing Geospatial APIs: PostGIS

The PostGIS extension is one of the most capable geospatial engines in the entire software ecosystem — commercial or otherwise. It adds geometry and geography column types (points, lines, polygons, multipolygons), spatial indexing via GiST, and a rich library of functions for distance calculations, intersection tests, buffering, and coordinate system transformations:

-- Find all stores within 5km of a user's location in Bengaluru
SELECT name,
       ST_Distance(location, ST_MakePoint(77.5946, 12.9716)::geography) AS dist_meters
FROM stores
WHERE ST_DWithin(
  location,
  ST_MakePoint(77.5946, 12.9716)::geography,
  5000
)
ORDER BY dist_meters;
Enter fullscreen mode Exit fullscreen mode

Entire commercial GIS platforms used by governments and logistics companies worldwide are built on PostGIS. It replaces the need for a separate geospatial API service for any proximity or boundary query against your own data.


The SQL You're Probably Under-Using

Beyond extensions, most developers use roughly 60% of Postgres's SQL capabilities. The remaining 40% eliminates entire categories of application-layer code.

Window Functions compute aggregates across rows related to the current row without collapsing them like GROUP BY does — running totals, moving averages, percentile ranks, all in a single pass:

SELECT
  order_date,
  amount,
  SUM(amount) OVER (ORDER BY order_date) AS running_total,
  AVG(amount) OVER (
    ORDER BY order_date
    ROWS BETWEEN 6 PRECEDING AND CURRENT ROW
  ) AS rolling_7day_avg
FROM orders;
Enter fullscreen mode Exit fullscreen mode

Recursive CTEs walk tree structures — org hierarchies, category trees, threaded comments, dependency graphs — in pure SQL, with no application-side recursion or multiple round trips:

WITH RECURSIVE category_tree AS (
  SELECT id, name, parent_id, 0 AS depth
  FROM categories WHERE parent_id IS NULL

  UNION ALL

  SELECT c.id, c.name, c.parent_id, t.depth + 1
  FROM categories c
  JOIN category_tree t ON c.parent_id = t.id
)
SELECT * FROM category_tree ORDER BY depth, name;
Enter fullscreen mode Exit fullscreen mode

Atomic Upserts handle the classic insert-or-update race condition with a single statement — no optimistic locking, no read-then-write, no race:

INSERT INTO inventory (product_id, stock)
VALUES (42, 100)
ON CONFLICT (product_id) DO UPDATE
  SET stock = EXCLUDED.stock,
      updated_at = NOW();
Enter fullscreen mode Exit fullscreen mode

Indexes: A Write Tax for a Read Benefit

Postgres gives you multiple index types, each precision-engineered for a different access pattern. Picking the right one is one of the highest-leverage optimizations available:

Index Type Best For Typical Use Case
B-tree Equality, ranges, ordering (default) WHERE created_at > '2025-01-01'
GIN JSONB keys, full-text search, arrays data @> '{"plan": "pro"}'
GiST Geometry, ranges, fuzzy matching ST_DWithin(location, point, 500)
BRIN Massive append-only time-series tables IoT sensor logs, event streams
HNSW / IVFFlat Vector ANN similarity search Embedding-based semantic retrieval

Every index is a write tax for a read benefit — it makes INSERT, UPDATE, and DELETE slightly slower because Postgres maintains the index alongside the table. Add indexes surgically, guided by EXPLAIN ANALYZE output, not speculatively:

EXPLAIN (ANALYZE, BUFFERS)
SELECT * FROM orders WHERE customer_id = 1234 AND status = 'shipped';
Enter fullscreen mode Exit fullscreen mode

The most important thing to look for in the output: Seq Scan vs Index Scan. A sequential scan on a large table is your bottleneck. An appropriately chosen index on the same query is your fix.


PostgreSQL 18: Built for the AI Era

PostgreSQL 18, released in 2026, doubles down on AI-era workloads with several meaningful improvements.

  • Asynchronous I/O significantly reduces latency on storage-bound operations, directly benefiting heavy embedding writes and similarity search workloads
  • Skip-scan on multicolumn indexes makes filtering around vector similarity searches dramatically faster
  • UUIDv7 index optimization improves insert and scan performance for tables that use UUID primary keys — common in distributed and event-driven systems
  • Automatic data checksums are now enabled by default on new clusters, eliminating a common silent data corruption risk
  • OAuth 2.0 authentication support out of the box for enterprise identity integration

These aren't cosmetic improvements — they're direct responses to the workload patterns that have emerged as teams integrate LLMs and AI features into their production stacks.


Under the Hood: Three Mechanisms That Explain Everything

Three internal systems explain most of Postgres's observable behavior — and knowing them prevents a category of production incidents.

MVCC (Multi-Version Concurrency Control) is why readers and writers never block each other. When you update a row, Postgres doesn't overwrite it. It writes a new version of the row and marks the old one as expired. Every transaction sees the world as it existed when that transaction started, regardless of what other transactions are doing concurrently. This is what makes SERIALIZABLE isolation achievable without locking tables.

WAL (Write-Ahead Log) is why Postgres survives crashes with full consistency. Every change is written to a sequential log before it's applied to data files on disk. On restart after a crash, Postgres replays the WAL and arrives at exactly the state it would have been in had the crash never happened. The same WAL stream is also shipped to read replicas in real time — replication is essentially a free side effect of crash recovery.

VACUUM and Dead Tuple Bloat is the tax you pay for MVCC. Because old row versions aren't overwritten, they accumulate as "dead tuples" on disk. The background autovacuum process reclaims this space continuously. In write-heavy workloads, autovacuum can fall behind — leading to table bloat, index bloat, and eventually a transaction ID wraparound emergency. Monitor pg_stat_user_tables for n_dead_tup values that keep climbing.


Scaling Postgres: What's Real and What's Honest

Read scaling is well-understood: stream the WAL to standby servers and route SELECT queries across them. Read replicas are typically milliseconds behind the primary.
Write scaling is the honest hard limit. One primary accepts all writes. When you genuinely hit that ceiling, these are your options:

  • Table Partitioning — splits large tables (by month, by region, by tenant) into physical partitions; Postgres prunes irrelevant partitions at query time, dramatically reducing scan sizes on time-series or multi-tenant data
  • Citus — distributes both data and queries across a cluster of Postgres nodes, enabling horizontal write scaling while keeping the full Postgres SQL interface
  • PgBouncer — not a scaling tool but an operational necessity. Each Postgres connection is a full OS process consuming 5–10MB of RAM. Serverless functions and connection-heavy frameworks will exhaust your connection limit quickly. PgBouncer pools thousands of application connections onto a small, stable set of real server connections, and it belongs in every production deployment ***

When to Reach for Something Else

Postgres is honest about its limits. You should be too.

  • Pure hot-path in-memory cache at millions of ops/sec → Redis; Postgres is not a memory store
  • Horizontal write sharding across 10+ nodes from day one → purpose-built distributed systems like Cassandra or CockroachDB
  • Petabyte-scale OLAP with complex aggregations → columnar engines like ClickHouse, DuckDB, or BigQuery will be orders of magnitude faster
  • High-throughput real-time event streaming → Kafka or Redpanda own that space; NOTIFY doesn't match their throughput guarantees

The engineering discipline is: start with Postgres, measure your actual bottlenecks, and add specialized tooling only when you've conclusively outgrown what Postgres offers. The biggest architectural mistake teams make is adding distributed complexity in anticipation of hypothetical scale that never arrives.


Why the License Is a Competitive Moat

Postgres is governed by the PostgreSQL Global Development Group — a community intentionally structured so that no single company can change its terms. The license is permissive, similar in spirit to BSD/MIT. You own your deployment. You control your upgrade path.

This is not a footnote. In recent years, MongoDB switched to SSPL and Redis changed to BSL, sending engineering teams scrambling for alternatives. That cannot structurally happen with Postgres. The community governance model is the moat — and in a world where vendor lock-in risk has become a real architecture consideration, that stability has genuine business value.


The Single-Database Architecture

One database. One backup strategy. One set of credentials. One monitoring dashboard. One EXPLAIN ANALYZE. It handles your relational data, your documents, your full-text search, your vector embeddings, your geospatial queries, your job queue, and your pub/sub events — and it has been reliably doing so for production systems at scale for over thirty years.

In 2026, the question isn't whether Postgres is capable enough. The question is whether your architecture has already added five services it didn't need.

Top comments (0)