Back to stack index

Database

PostgreSQL

Primary relational DB; often paired with pgvector.

Short answer

PostgreSQL is a free, open-source relational database first released in 1996, and it is the default database for most self-hosted AI applications. In our directory, Dify, Langfuse, n8n, AnythingLLM and LibreChat can store their data in it, and through the pgvector extension it also stores embeddings, so one database can hold users, conversations and vector search indexes. The current stable release is PostgreSQL 18.6, from August 13, 2026. PostgreSQL 19 reached its first release candidate on October 15, 2026, with general availability planned for November 19, 2026. PostgreSQL uses the permissive PostgreSQL License. For self-hosters the main tasks are choosing a supported major version, sizing memory, setting up automated backups, and planning major-version upgrades, which require a dump and restore or the pg_upgrade tool.

Current stable
PostgreSQL 18.6, August 13, 2026
postgresql.org
Next major
PostgreSQL 19 RC1 Oct 15; GA planned Nov 19, 2026
postgresql.org
License
PostgreSQL License (permissive)
postgresql.org
Vector search
pgvector extension
pgvector GitHub

Updated October 21, 2026How we evaluate tools

Official site

Directory projects (5)

  • Dify

    Visual builder for RAG apps and agents with deployable API endpoints.

  • Langfuse

    Open LLM engineering hub for traces, prompts, scores, and datasets.

  • n8n

    n8n accelerates app backends or internal tools with frameworks you can self-host.

  • AnythingLLM

    Document chat and workspaces with optional vector DB and multi-user mode.

  • LibreChat

    Multi-model chat UI with plugins, agents, and self-hosted deployment.

PostgreSQL in open-source AI tools: the database behind Dify, Langfuse, n8n and LibreChat in 2026

Why AI apps use PostgreSQL

An AI application stores the same things as any web app, plus a few more: users, workspaces, API keys, conversations, messages, prompt versions, evaluation results, workflow runs and, often, embeddings. PostgreSQL handles all of these. It has strong consistency, mature tooling, JSON columns for semi-structured data such as model responses and tool calls, full-text search, and an extension system that added vector search through pgvector. It is also the database most developers already know, and every cloud provider offers it as a managed service.

Which directory projects use it

ProjectHow it uses PostgreSQL
DifyMain database for apps, workflows, users and logs; pgvector is one supported vector store
LangfuseTransactional data such as projects, users and prompts; traces go to ClickHouse in v3 and later
n8nRecommended production database for workflows and execution history; SQLite is the default for small installs
AnythingLLMOptional replacement for the default SQLite database
LibreChatPostgres with pgvector for its RAG API; main data is in MongoDB

PostgreSQL 18 and 19

PostgreSQL ships one major version each autumn and minor releases every quarter. PostgreSQL 18, released in September 2025, added an asynchronous I/O subsystem that speeds up sequential scans and vacuum, native uuidv7() for time-ordered IDs, virtual generated columns, OAuth authentication support, and faster major-version upgrades that keep planner statistics. The current minor release is 18.6, from August 13, 2026, which fixed bugs and security issues.

PostgreSQL 19 reached release candidate 1 on October 15, 2026, with general availability planned for November 19, 2026. As usual, wait for your applications to declare support and for the first minor release before moving production systems.

VersionReleasedSupported until
19November 2026 (planned)November 2031
18September 2025November 2030
17September 2024November 2029
16September 2023November 2028
15October 2022November 2027
14September 2021November 2026

If you run PostgreSQL 14, plan an upgrade now: it reaches end of life next month.

pgvector for embeddings

pgvector adds a vector column type and distance operators for cosine, inner product and Euclidean distance, with two index types. HNSW indexes give fast, accurate queries at the cost of slower builds and more memory; IVFFlat builds faster with lower recall. Version 0.8 improved filtered queries with iterative index scans, which fixed a common problem where a filter on tenant or document type returned too few results. The halfvec type stores vectors at half precision to halve memory, and binary quantization reduces it further.

ApproachGood up toNotes
pgvector with HNSWA few million vectors per tableOne database, transactions, SQL joins
pgvectorscale or VectorChordTens of millionsExtensions with disk-based indexes
Dedicated vector database such as QdrantHundreds of millionsQuantization, multi-tenancy features, separate service

For most self-hosted RAG apps, pgvector is enough, and avoiding a second database simplifies backups and security.

Managed PostgreSQL options

ProviderFree tierNotes
Supabase500 MB database, pauses after a week inactivePostgres plus auth, storage and APIs; Pro from $25 a month
NeonYesServerless Postgres with branching and scale to zero; acquired by Databricks in 2025
AWS RDS and AuroraLimited trialMany instance sizes; Aurora adds a custom storage engine
Google Cloud SQL and AlloyDBTrial creditsAlloyDB adds AI features such as built-in embeddings
Azure Database for PostgreSQLTrial creditsFlexible Server with pgvector

Self-hosting PostgreSQL for AI tools

Most AI projects ship a Docker Compose file that includes a Postgres container. That is fine to start, but production use needs a few additions:

  • Persistent volumes. Store data on a named volume or host directory, never only inside the container.
  • Backups. Schedule pg_dump for small databases, or use pgBackRest or WAL-G for continuous archiving and point-in-time recovery. Test restores.
  • Memory settings. Set shared_buffers to about a quarter of RAM, and raise maintenance_work_mem when building HNSW indexes, which are much faster when the index fits in memory.
  • Connection limits. Python apps with many workers can exhaust connections. Use PgBouncer or the app's pool settings.
  • Pin the major version. Use a tag such as postgres:17 rather than latest, so an image update never attempts to start a new major version on old data files.

Postgres versus other databases in AI tools

DatabaseUsed byStrength
PostgreSQLDify, Langfuse, n8nGeneral purpose, vectors, mature tooling
SQLiteJan, GPT4All, AnythingLLM defaultZero setup, single file
MongoDBLibreChatFlexible document storage
ClickHouseLangfuse tracesFast analytics over billions of events
RedisDify, Langfuse, LiteLLMCaching, queues, rate limits

Designing tables for AI data

A few patterns recur across AI apps built on Postgres. Store each message as its own row with a conversation ID, role, content and token counts, rather than one large JSON blob per conversation, so you can search, paginate and delete messages individually. Keep raw model responses and tool-call arguments in jsonb columns, which can be indexed with GIN indexes when you need to query inside them. Put embeddings in a separate table keyed by document chunk, with the model name and dimension recorded, because changing embedding models means re-embedding everything and you will want old and new vectors side by side during the switch. Partition very large log or trace tables by month so old data can be dropped quickly.

Vector search finds passages with similar meaning but can miss exact terms such as product codes, names or error messages. PostgreSQL's built-in full-text search handles those. Hybrid search runs both queries and merges the results, often with reciprocal rank fusion, and usually retrieves better passages for RAG than either method alone. Extensions such as ParadeDB's pg_search add BM25 ranking, the scoring method used by dedicated search engines, inside Postgres.

Monitoring

The pg_stat_statements extension shows which queries take the most time, which is the first place to look when an AI app slows down. Vector queries without an index scan every row, so check that similarity searches use the HNSW index with EXPLAIN. Track disk use, since conversation logs and traces grow steadily, and set retention policies in apps that support them, such as Langfuse and n8n's execution pruning.

Security

Never expose PostgreSQL's port 5432 to the internet. Keep it on a private network or Docker network, require strong passwords or certificate authentication, and apply minor releases promptly, since each quarterly release usually includes security fixes. Default Compose files often use weak passwords such as postgres; change them before going live.

Related: Supabase stack, Redis stack, SQLite stack, Qdrant stack, Docker stack, Stack index.

Frequently asked questions

Can PostgreSQL replace a vector database?

For many AI apps, yes. The pgvector extension adds a vector column type and HNSW and IVFFlat indexes for similarity search. Up to a few million vectors, Postgres with pgvector performs well and keeps everything in one database. Dedicated vector databases such as Qdrant pull ahead at larger scale, with heavy filtering, or with advanced quantization.

Which PostgreSQL version should I run for Dify or Langfuse?

Use the version in the project's Docker Compose file or documentation. Most projects support PostgreSQL 15 through 18. Avoid moving to PostgreSQL 19 until the project lists it as supported, usually a few months after release.

How do I upgrade PostgreSQL major versions?

Major versions change the on-disk format, so you cannot swap the Docker image tag in place. Use pg_dump and restore into the new version, or pg_upgrade, or logical replication for minimal downtime. Back up first. Minor versions, such as 18.5 to 18.6, upgrade by replacing the binaries.

What is the cheapest managed PostgreSQL for a small AI app?

Supabase and Neon both have free tiers suitable for prototypes, with paid plans from about $19 to $25 a month. AWS RDS, Google Cloud SQL and Azure offer managed Postgres with more configuration and usually higher minimum cost.

How long is each PostgreSQL version supported?

Five years from its initial release. PostgreSQL 13 reached end of life in November 2025, and PostgreSQL 14 is supported until November 2026.

Sources

  1. PostgreSQL versioning policy
  2. PostgreSQL news
  3. pgvector on GitHub
  4. Langfuse self-hosting docs