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
| Project | How it uses PostgreSQL |
|---|---|
| Dify | Main database for apps, workflows, users and logs; pgvector is one supported vector store |
| Langfuse | Transactional data such as projects, users and prompts; traces go to ClickHouse in v3 and later |
| n8n | Recommended production database for workflows and execution history; SQLite is the default for small installs |
| AnythingLLM | Optional replacement for the default SQLite database |
| LibreChat | Postgres 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.
| Version | Released | Supported until |
|---|---|---|
| 19 | November 2026 (planned) | November 2031 |
| 18 | September 2025 | November 2030 |
| 17 | September 2024 | November 2029 |
| 16 | September 2023 | November 2028 |
| 15 | October 2022 | November 2027 |
| 14 | September 2021 | November 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.
| Approach | Good up to | Notes |
|---|---|---|
| pgvector with HNSW | A few million vectors per table | One database, transactions, SQL joins |
| pgvectorscale or VectorChord | Tens of millions | Extensions with disk-based indexes |
| Dedicated vector database such as Qdrant | Hundreds of millions | Quantization, 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
| Provider | Free tier | Notes |
|---|---|---|
| Supabase | 500 MB database, pauses after a week inactive | Postgres plus auth, storage and APIs; Pro from $25 a month |
| Neon | Yes | Serverless Postgres with branching and scale to zero; acquired by Databricks in 2025 |
| AWS RDS and Aurora | Limited trial | Many instance sizes; Aurora adds a custom storage engine |
| Google Cloud SQL and AlloyDB | Trial credits | AlloyDB adds AI features such as built-in embeddings |
| Azure Database for PostgreSQL | Trial credits | Flexible 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_dumpfor small databases, or use pgBackRest or WAL-G for continuous archiving and point-in-time recovery. Test restores. - Memory settings. Set
shared_buffersto about a quarter of RAM, and raisemaintenance_work_memwhen 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:17rather thanlatest, so an image update never attempts to start a new major version on old data files.
Postgres versus other databases in AI tools
| Database | Used by | Strength |
|---|---|---|
| PostgreSQL | Dify, Langfuse, n8n | General purpose, vectors, mature tooling |
| SQLite | Jan, GPT4All, AnythingLLM default | Zero setup, single file |
| MongoDB | LibreChat | Flexible document storage |
| ClickHouse | Langfuse traces | Fast analytics over billions of events |
| Redis | Dify, Langfuse, LiteLLM | Caching, 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.
Full-text and hybrid search
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.