For years, MySQL was the default database for many web applications.
Then MongoDB became popular, especially among developers building applications with JavaScript and JSON-based APIs.
Today, PostgreSQL seems to be getting more attention than both.
But why?
Is PostgreSQL actually better? Is MongoDB losing its appeal? And does choosing MySQL for a new application mean you're making an outdated decision?
I've worked with SQL databases, MongoDB, and PostgreSQL across backend systems and AI applications. What interests me isn't which database wins a popularity contest.
It's why PostgreSQL has become such a compelling default for modern software development.
Let's look at what the data says, the technical reasons behind that preference, and when MySQL or MongoDB might still be the better choice.
1. What the 2026 Developer Survey Tells Us
The 2026 Stack Overflow Developer Survey provides an interesting snapshot.
Among 12,061 respondents to the database question:
| Database | Used in the past year | Admired |
|---|---|---|
| PostgreSQL | 57.9% | 62.3% |
| MySQL | 35.1% | 38.2% |
| MongoDB | 19.0% | 38.5% |
Here, "admired" means the percentage of developers who used a database and want to continue using it.
PostgreSQL leads in both measures.
However, these numbers don't mean 57.9% of all developers worldwide use PostgreSQL. They represent survey respondents, who could select multiple databases.
Another source, the November 2026 DB-Engines ranking, still places MySQL above PostgreSQL in overall popularity.
Different measurements tell different stories.
What we can reasonably say is that PostgreSQL has strong adoption and developer preference, particularly among developers responding to this survey.
The more interesting question is why.
2. Modern Applications Need Relationships, Not Just Documents
Imagine building a SaaS platform.
At first, your data model is simple:
- Users
- Organizations
- Projects
- Subscriptions
- Payments
As the product grows, those entities become connected.
A user can belong to multiple organizations. An organization can own hundreds of projects. Subscriptions have billing histories, and payments need to reference the correct customers.
PostgreSQL handles these relationships naturally.
CREATE TABLE organizations ( id BIGSERIAL PRIMARY KEY, name TEXT NOT NULL ); CREATE TABLE users ( id BIGSERIAL PRIMARY KEY, email TEXT NOT NULL UNIQUE ); CREATE TABLE memberships ( organization_id BIGINT NOT NULL REFERENCES organizations(id), user_id BIGINT NOT NULL REFERENCES users(id), role TEXT NOT NULL, PRIMARY KEY (organization_id, user_id) ); The database enforces these relationships.
An invalid organization ID cannot silently become a valid membership.
MongoDB can represent the same data using embedded documents or references. It also supports joins through $lookup and multi-document transactions.
The difference is in the modeling approach.
MongoDB often works well when related information can be stored and retrieved together as a document.
PostgreSQL becomes particularly attractive when relationships are complex, records change independently, and consistency rules matter.
MongoDB's own data-modeling documentation recommends references for complex many-to-many relationships.
Neither approach is automatically better.
But for business applications with interconnected data, relational modeling is often a natural starting point.
3. PostgreSQL Is More Flexible Than Many Developers Think
One reason developers choose MongoDB is its flexible document structure.
You can store JSON-like data without defining every field in advance.
That's useful when product requirements change frequently.
But PostgreSQL doesn't force every attribute into a rigid relational column.
It supports JSONB.
Consider an orders table:
CREATE TABLE orders ( id BIGSERIAL PRIMARY KEY, customer_id BIGINT NOT NULL, total_amount NUMERIC(12, 2) NOT NULL, metadata JSONB NOT NULL DEFAULT '{}' ); The important business fields remain structured, while metadata can hold flexible information:
{ "source": "mobile", "campaign": "summer-sale", "device": { "platform": "ios" } } You can query this data directly:
SELECT id, total_amount FROM orders WHERE metadata @> '{"source": "mobile"}'; For suitable workloads, PostgreSQL can use a GIN index:
CREATE INDEX idx_orders_metadata ON orders USING GIN (metadata); This doesn't make PostgreSQL a complete replacement for every document-database use case.
JSONB updates, indexing, and large documents have their own performance considerations.
But it means developers no longer need to choose between relational integrity and flexible JSON storage.
MySQL also supports a native JSON type, JSON functions, and indexing through generated columns or functional indexes.
The distinction is about capabilities and implementation trade-offs, not whether MySQL supports JSON.
References: PostgreSQL JSON Types and MySQL JSON Documentation.
4. Why PostgreSQL Is Attractive for AI Applications
This is where PostgreSQL becomes especially interesting to me.
I've built an Enterprise RAG Knowledge Assistant using PostgreSQL, pgvector, hybrid search, and reranking.
A RAG system typically needs to manage several kinds of information:
- Documents and their ownership.
- Text chunks and metadata.
- Vector embeddings for semantic search.
- Access permissions and organizational relationships.
Using PostgreSQL with the pgvector extension, these can coexist in one relational database.
For example:
CREATE EXTENSION IF NOT EXISTS vector; CREATE TABLE document_chunks ( id BIGSERIAL PRIMARY KEY, document_id BIGINT NOT NULL, content TEXT NOT NULL, embedding vector(1536) ); The vector dimension must match the embedding model being used.
Semantic search becomes a database query:
SELECT document_id, content FROM document_chunks WHERE embedding IS NOT NULL ORDER BY embedding <=> $1::vector LIMIT 5; The <=> operator calculates cosine distance.
With pgvector, you can combine vector similarity with PostgreSQL's full-text search and relational filtering.
This is useful for applications that need both semantic relevance and exact keyword matching.
The practical benefit is architectural simplicity.
Instead of introducing a separate vector database immediately, a team can initially work with infrastructure it already understands.
However, MongoDB also supports vector search, full-text search, filtering, and RAG workflows.
And dedicated vector databases may provide better scalability or operational characteristics for certain workloads.
The decision should depend on retrieval quality, query latency, indexing requirements, and operational cost.
References: pgvector and MongoDB Vector Search.
5. Why Not Just Use MySQL?
This is a fair question.
MySQL is mature, reliable, and widely used. InnoDB supports ACID transactions, foreign keys, and indexes. MySQL also supports window functions, common table expressions, and JSON.
For many CRUD applications, MySQL and PostgreSQL can both do the job very well.
PostgreSQL becomes attractive when an application benefits from its broader extensibility, rich SQL capabilities, specialized data types, and indexing options.
But switching databases doesn't automatically make an application faster.
A poorly designed PostgreSQL schema can perform worse than a well-optimized MySQL implementation.
Query patterns, indexes, configuration, and workload characteristics matter more than popularity.
If a team's MySQL infrastructure is stable and developers understand it well, moving to PostgreSQL without a specific requirement may create more risk than value.
A database migration needs a business reason, not a trending chart.
6. The Hidden Advantage: Less Infrastructure Complexity
Here's a consideration that doesn't always appear in database comparisons.
Every new data system introduces operational responsibilities.
Suppose an application uses:
MySQL → Transactional data MongoDB → Flexible documents Search engine → Keyword search Vector DB → Embeddings This architecture can be justified.
But it also introduces more infrastructure to monitor, secure, back up, and maintain.
Data synchronization between systems can become another source of complexity.
For a smaller application, PostgreSQL might handle the transactional data, JSON metadata, keyword search, and embeddings in one place.
That doesn't guarantee lower costs.
A single PostgreSQL instance handling several demanding workloads might become difficult to scale or tune.
Still, reducing the number of moving parts can save engineering time, especially when a small team needs to move quickly.
As the application grows, individual workloads can be moved to specialized services when measurements justify the additional complexity.
I prefer starting with the simplest architecture that meets the requirements, then introducing specialization when there's a demonstrated need.
7. When I'd Choose Each Database
Despite PostgreSQL's advantages, I wouldn't choose it automatically for every project.
| Situation | My likely choice |
|---|---|
| New relational SaaS application | PostgreSQL |
| Existing stable MySQL platform | Keep MySQL |
| Document-centric application with embedded aggregates | MongoDB |
| AI application with relational data and moderate vector-search needs | PostgreSQL + pgvector |
| Existing MongoDB application adding semantic search | Evaluate MongoDB Vector Search first |
| Specialized search at significant scale | Benchmark dedicated search infrastructure |
The key questions are more useful than any ranking:
Does the application have complex relationships? How often does its schema change? What consistency guarantees are required? Which queries dominate the workload? What infrastructure can the team operate confidently?
And perhaps most importantly: what would make the database choice expensive to change later?
Those answers should drive the decision.
Final Thoughts
PostgreSQL's growing popularity makes sense.
It combines strong relational modeling with flexible JSON storage, advanced querying, and an ecosystem of extensions that support modern applications, including AI.
But that doesn't make MySQL obsolete or MongoDB unnecessary.
Three lessons stand out:
- Choose for your data model, not popularity. Relationships, access patterns, and consistency requirements matter more than survey rankings.
- Flexibility doesn't always require a document database. PostgreSQL's JSONB support can cover many hybrid use cases.
- Think about operational complexity. The best architecture isn't necessarily the one using the most specialized technologies.
For a new SaaS or AI-powered application, PostgreSQL would often be my starting point.
Not because it wins every benchmark, but because it provides a versatile foundation without requiring several different data systems from day one.
If you were starting a new backend project today, would you choose PostgreSQL, MySQL, or MongoDB? What would influence your decision?


