Skip to main content
Home › Categories › Software Engineering, Cloud & Cybersecurity › PostgreSQL with pgvector vs Dedicated Vector Databases: Indexing, ACID Transactions, and Scaling Billions of Vectors

PostgreSQL with pgvector vs Dedicated Vector Databases: Indexing, ACID Transactions, and Scaling Billions of Vectors

Author: ZUVDEX Team 4 min read
pgvector vs vector database postgresql pgvector hnsw performance pgvector iterative index scans dedicated vector database vs postgres hybrid relational metadata filtering halfvec fp16 binary quantization pgvector

Adding vector search to an application forces an immediate infrastructure choice: enable the open-source `pgvector` extension inside your existing PostgreSQL database, or deploy a dedicated vector database alongside Postgres. Thanks to HNSW indexing, `halfvec` (FP16) and binary quantization, iterative filtered index scans, and DiskANN extensions, PostgreSQL now comfortably serves 5 million to 50+ million vectors at single-digit millisecond latency with full ACID transactional integrity—reserving standalone vector clusters for massive 100M-to-multi-billion-vector workloads.

Key Highlights

  • Eliminating 'dual-write drift' is pgvector’s biggest superpower: when a user deletes a document or revokes team permissions in Postgres, the vector embedding disappears or updates inside the exact same ACID transaction.
  • Modern `pgvector` (0.7 / 0.8+) fixed the classic 'filtered HNSW hole' via iterative index scans—automatically continuing graph traversal until enough rows matching your SQL `WHERE` clause are found.
  • Switching `vector(1536)` (6 KB/row) to `halfvec(1536)` (3 KB/row in FP16) halves RAM usage and doubles index build speed in PostgreSQL with virtually zero retrieval recall loss.
  • Dedicated vector databases (Qdrant, Milvus, Weaviate, Pinecone, Turbopuffer) pull ahead when vectors cross 100M–5B+ rows, need independent memory/compute sharding away from OLTP checkout traffic, or use object-storage-native cold/warm tiering.

1. The Hidden Operational Tax of Syncing Two Databases

Running a separate vector database alongside PostgreSQL looks clean on a whiteboard until day two of production. Every time an article is edited, a Slack channel’s ACL changes, or a customer exercises a GDPR deletion request, an asynchronous queue worker must sync that mutation from Postgres to the vector cluster.

Whenever a webhook retries out of order or a worker stalls, your AI assistant either hallucinates from stale deleted chunks or—far worse—retrieves confidential chunks whose permissions were revoked ten minutes ago. Keeping `documents`, `permissions`, full-text `tsvector` BM25 search, and `halfvec` embeddings inside PostgreSQL reduces all of that distributed plumbing to a single transactional `COMMIT`.

PostgreSQL (pgvector) vs Dedicated Vector Databases Side-by-Side
Architectural Factor PostgreSQL + pgvector Dedicated Vector Database (Qdrant / Milvus / Pinecone)
Operational Footprint Zero new infra if you already run RDS / Cloud SQL / Postgres Separate cluster, auth, backups, CDC sync & monitoring
Transactional Consistency Strict ACID joins with users, tenants & permissions Eventually consistent with primary OLTP database
Filtered Vector Search SQL `WHERE` + Iterative HNSW Scans + B-Tree/GIN indexes Purpose-built payload-aware HNSW / Roaring Bitmaps
Vector Compression FP32, `halfvec` FP16, `bit` binary & `sparsevec` Scalar INT8, Product Quantization (PQ), Binary, Disk/S3 tiering
Horizontal Sharding Vertical scale / read replicas (up to ~50M–100M vectors) Native distributed sharding across billions of vectors
OLTP Isolation Heavy index rebuilds share CPU/RAM unless on read replica Completely isolated from core checkout/transactional DB

2. Essential Production Tuning for PostgreSQL + pgvector

Default PostgreSQL settings (`shared_buffers = 128MB`, `maintenance_work_mem = 64MB`) will make HNSW index creation crawl! Apply four proven configurations whenever deploying `pgvector` in production:

  • Use `halfvec` by default: Define columns as `halfvec(1024)` or `halfvec(1536)` with `halfvec_cosine_ops` to cut index memory by 50% cleanly.
  • Raise `maintenance_work_mem` during index builds: Set `SET maintenance_work_mem = ‘4GB’` (or higher) and `max_parallel_maintenance_workers = 7` so HNSW graph construction finishes in minutes in RAM rather than thrashing disk.
  • Partition multi-tenant tables: If each enterprise customer only ever searches their own workspace, declarative PostgreSQL list/hash partitioning by `tenant_id` keeps per-partition HNSW graphs tiny, fast, and hot in cache.
  • Enable Iterative Scans (`SET hnsw.iterative_scan = relaxed_order;`): Guarantees full top-K results even when strict SQL `WHERE` filters match only 2% of rows.

3. When You Truly Outgrow pgvector

Migrate embeddings to a dedicated vector engine (or object-storage-backed vector store) when any of three concrete thresholds arrive: (1) your vector count crosses 100 million+ embeddings where holding HNSW graphs in primary Postgres RAM costs thousands of dollars monthly; (2) write-heavy streaming ingestion (5,000+ vector upserts per second) contends with sensitive OLTP locks; or (3) you have thousands of cold customer namespaces that rarely query simultaneously and benefit from S3/NVMe serverless cold storage.

FAQs

Should I run pgvector on the exact same Postgres instance as high-TPS financial payments?

Up to moderate load, yes; as vector QPS grows, route read-only RAG similarity queries to a dedicated PostgreSQL Read Replica (using streaming physical replication) so vector CPU/RAM usage never touches your primary transactional writer.

Can PostgreSQL do Hybrid BM25 + Vector Search natively without Elasticsearch?

Yes! Combine PostgreSQL’s native `tsvector` GIN full-text index (or the `pg_search` BM25 extension) with a `pgvector` HNSW query inside a single SQL Common Table Expression (`WITH semantic AS (...), lexical AS (...)`) joined via Reciprocal Rank Fusion in under 15 milliseconds.

Which index should I pick in pgvector: IVFFlat or HNSW?

Choose HNSW almost every time. Unlike IVFFlat—which requires existing data to train k-means centroids and degrades as data drifts without periodic `REINDEX`—HNSW can be created on an empty table, handles live inserts gracefully, and delivers markedly superior speed-recall curves.

References & Sources

  • Kane, A. & Contributors — pgvector: Open-Source Vector Similarity Search for Postgres (HNSW, halfvec, sparsevec & Iterative Scans).
  • PostgreSQL Global Development Group — PostgreSQL 17/18 Documentation: Index Access Methods & Parallel Maintenance.
  • Pan, J. J.; Wang, J.; Li, G. — Survey of Vector Database Management Systems, The VLDB Journal.