Of all technical decisions to reverse, your choice of database is among the hardest to undo. Rewrite a component when you switch frontend framework and routes get updated when you change API design.
When you change your database, you move data around, rewrite queries, rearchitect application logic and most often find data integrity problems you did not know you had. The decision calls for more careful thought than it most often gets.
Standard advice says to use what you know and that works fine for prototypes. Production systems that will run for years need a closer look and MySQL, PostgreSQL and MongoDB each have genuine strengths as well as real weaknesses.
A social media platform calls for the wrong database that a financial ledger does not need. A database that fits a three-person startup may not work for a team of thirty.
The comparison looks at 2026 realities. PostgreSQL has cut down a lot on MongoDB's document storage advantages through its JSONB improvements. The pgvector extension for AI workloads.[1]MongoDB has brought in transactions and schema validation that fix some of the weaknesses the database had historically.[3]
MySQL 8.0 improved greatly on MySQL 5.7 and many production systems are still running that version.[2] What counts more than repeating conventional wisdom from 2018 is knowing where things stand now for each.
The DB-Engines Ranking as of March 2026 ranks Oracle first, MySQL second and PostgreSQL third among relational databases. Yet among new projects and startups choosing new technology, PostgreSQL has passed MySQL for the third year running in Stack Overflow's Developer Survey.
MongoDB holds the top spot among document databases with no close second.[11]
"Show me your data model and I will tell you your future."
Martin Kleppmann, author of 'Designing Data-Intensive Applications'[4]
Key Differences at a Glance
| Feature | MySQL 8.0 | PostgreSQL 16 | MongoDB 7 |
|---|---|---|---|
| License | GPL / Commercial | PostgreSQL (permissive) | SSPL (restrictive for hosting) |
| Data model | Relational | Relational + JSONB | Document (BSON) |
| ACID transactions | Yes (InnoDB) | Yes | Yes (since 4.0) |
| JSON support | Basic | JSONB (excellent) | Native (excellent) |
| Full-text search | Basic | Good | Good |
| Horizontal sharding | Vitess (external) | Citus (extension) | Built-in |
| Read replicas | Yes | Yes | Yes (replica sets) |
| Stored procedures | Yes | Yes | Limited |
| Partitioning | Yes | Excellent | Yes |
| Schema enforcement | Required | Required | Optional (validator) |
| Managed cloud options | Many (RDS, PlanetScale, etc.) | Many (RDS, Supabase, Neon) | Atlas (primary) |
| Default port | 3306 | 5432 | 27017 |
| Vector search (AI) | No | Yes (pgvector extension) | Yes (Atlas Vector Search) |
| Geographic queries | Limited | Excellent (PostGIS) | Good (2dsphere index) |
| Window functions | Yes (8.0+) | Yes (full, since 8.4) | No (aggregation pipeline) |
| CTE support | Yes (8.0+) | Yes (full, recursive) | No |
| Connection model | Thread-per-connection | Process-per-connection | Thread pool |
| DB-Engines rank (March 2026) | #2 | #3 | #5 |
MySQL: The Workhorse That Built the Web
MySQL powered the internet's first era of scale. Facebook, Twitter, Airbnb, and YouTube all built on MySQL at various points.
Its success came from predictability, documentation and ubiquity. Almost every web host supported it and almost every web developer knew SQL and there was an ecosystem of tools, ORMs and backup solutions that was without equal.
Think about the scale of MySQL's deployment to see why it has stayed strong. MySQL AB (now Oracle) said there were over 10 million active MySQL installs as of their last public report. Hundreds of millions more installs come from WordPress needing MySQL or MariaDB alone.
The ecosystem around MySQL (including MariaDB, Percona Server, and PlanetScale's Vitess) means that MySQL-compatible databases will be maintained long after any individual corporation's involvement.
MySQL's Genuine Strengths
Read performance for simple queries in MySQL is hard to beat. When workloads consist mainly of SELECT statements on well-indexed tables (which is the pattern of most web applications), MySQL performs very well. The InnoDB buffer pool together with MySQL's query optimizer is tuned well for this pattern.
On commodity hardware that is properly tuned, benchmark studies show MySQL 8.0 doing more than 500,000 simple primary key lookups a second.[12]
InnoDB, which has served as MySQL's default storage engine since version 5.5, delivers full ACID compliance, row-level locking and foreign key support. Its track record for reliability is rock solid.
Where data integrity matters most (financial transactions, inventory management and user authentication), InnoDB's guarantees have been proven across millions of production deployments.
In 2026, the LAMP stack integration that brings together Linux, Apache, MySQL and PHP continues to be relevant. Large amounts of web infrastructure run on this stack and WordPress, Drupal and many legacy PHP apps depend on MySQL.
If you are working in or near this ecosystem, MySQL is the path of least resistance - and the operational knowledge in your team is likely to already include MySQL administration.
PlanetScale, the MySQL-compatible database built on Vitess, has made MySQL sharding accessible to teams without dedicated database expertise.
MySQL's two biggest historical operation pain points get fixed by PlanetScale's branching model that works like Git branches for database schema changes and by non-blocking schema migrations. For MySQL as the right database but where operational complexity counts, PlanetScale is something to consider.
MySQL's Honest Weaknesses
SQL compliance is imperfect. MySQL takes in some queries that other databases would reject and gives unexpected results instead of errors. Up to MySQL 8.0, specific GROUP BY behaviors broke the SQL standard and gave results that were technically wrong but were accepted silently.
Developers used to PostgreSQL's stricter SQL rules run into MySQL quirks time after time as window functions, common table expressions and recursive queries arrived in MySQL 8.0 after years as standard in PostgreSQL.
MySQL 5.7 brings in JSON support, which works but is less powerful than PostgreSQL's JSONB. MySQL's JSON columns do not allow indexing with the same flexibility as JSONB GIN indexes and its JSON query operators have less expressiveness.
MySQL is unable to index any arbitrary path within a JSON document without creating a generated column explicitly. With a single GIN index declaration PostgreSQL can index the whole contents of a JSON document.
Commercial use calls for attention to the licensing situation. Oracle owns MySQL. The Community Edition is GPL but many enterprise features need commercial licenses. Companies that distribute MySQL as part of a product run into complications from the GPL license.
With its permissive BSD-style license, PostgreSQL gets around those problems entirely. Some businesses also look to MariaDB, the GPL-compatible fork of MySQL created following Oracle's acquisition, as an alternative license.
PostgreSQL: The Engineer's Database
PostgreSQL is what you get when a database is built by engineers who care deeply about correctness, standards compliance and extensibility. Database specialists tend to pick it whenever they have a free hand. Its market share has climbed steadily as teams put developer experience ahead of old LAMP-stack habits.
According to Stack Overflow's 2025 Developer Survey, PostgreSQL was the most used database among professional developers for the third year running, with 49.7% of respondents reporting its use.[10] MySQL came second at 40.3%.
Every year since 2022 the gap has grown wider again. That reflects a generational change in how developers are trained and what cloud providers recommend as default settings.
"PostgreSQL is not just a database. It is a platform for building databases. The extension system means you can add capabilities that other vendors would need to build entirely separate products for."
Bruce Momjian, PostgreSQL Core Team member, speaking at PGConf 2024
What Makes PostgreSQL Different
The feature set is genuinely broader than MySQL. With partial indexes you can index a subset of rows. That cuts index size dramatically for tables that have many null values or where you only query a particular status.
Expression indexes let you index the output of a function. Queries on computed values stay fast.[5] And GIN indexes on JSONB columns let you index the full contents of a JSON document efficiently.
PostgreSQL's window functions, CTEs, lateral joins and full-text search are more powerful and more standard-compliant than MySQL's equivalents. That makes writing complex analytical queries much easier.
EXPLAIN ANALYZE produces output that is more detailed and easier to read and it displays buffer hit rates, loop counts and timing for every node in the query plan. That is invaluable when debugging slow queries.
The extension ecosystem is a superpower. PostGIS adds full geographic information system capabilities to PostgreSQL, including real spatial indexing, distance calculations, geographic projections and topology operations that otherwise need a dedicated GIS server.
Automatic partitioning by time and up to 90% compression ratios for time-series data turn PostgreSQL into a time-series database that is what TimescaleDB does.[8]
As it grows more relevant for what AI applications will need in 2026, pgvector brings vector similarity search to PostgreSQL. That lets semantic search and embedding storage take place directly in the database. Citus also shreds PostgreSQL horizontally across many nodes and turns a single-node database into a distributed system.[9]
JSONB: PostgreSQL's Answer to MongoDB
JSONB (binary JSON) keeps JSON data in a decomposed binary format that allows indexing as well as efficient querying.
A JSONB column can hold arbitrary nested JSON and GIN indexes on that column make it possible for queries like "find all rows where the JSON document has key 'active' with value true" to run without going through the whole table.
Many use cases that could push teams toward MongoDB can be met within PostgreSQL. The result is that you have document storage flexibility for metadata, user preferences or configuration together with the reliability of relational tables for core business data.
Running one database instead of two reduces operational complexity, reduces infrastructure cost, and eliminates the consistency challenges that come from synchronizing data across two data stores.
For a concrete example, a SaaS app could put users in a normalized relational table (fixed schema, foreign keys, constraints) and use JSONB for user_settings that have variable structure per user and do not need any schema migration when new settings are added.
In MongoDB it becomes impossible and in MySQL it gets awkward to use relational tables for structure and JSONB for flexibility in this hybrid method.
pgvector and AI Applications
In 2026, the explosion of AI applications that use vector embeddings has made pgvector one of the most significant reasons to choose PostgreSQL for new projects.
Vector embeddings (numerical representations of text, images, or other data produced by machine learning models) are the foundation of semantic search, recommendation systems, and retrieval-augmented generation (RAG) systems.
pgvector, released in 2021 and now at version 0.7, adds a vector data type to PostgreSQL and supports approximate nearest-neighbor search using HNSW and IVFFlat indexing algorithms.[6]
On a properly indexed table that holds millions of vectors, a query such as "find the 10 articles most semantically similar to this user query" can go through in milliseconds.
Keeping a separate vector database such as Pinecone, Weaviate or Qdrant next to your relational database comes with an added cost for infrastructure, more operational complexity. The consistency issues that come from trying to keep two systems in sync.
For most applications, pgvector within PostgreSQL is sufficient and substantially simpler.
PostgreSQL's Limitations
PostgreSQL's write performance under very high concurrency has historically lagged MySQL in specific benchmarks, though the gap has narrowed in recent versions. The process-per-connection model means each connection spawns a separate operating system process.
For applications with thousands of concurrent connections, PgBouncer connection pooling is essentially mandatory rather than optional - it collapses thousands of application connections into a smaller pool of actual database connections.
The operational learning curve is steeper than MySQL. Vacuum, autovacuum, table bloat, and index bloat are concepts that MySQL developers encounter much less frequently.
PostgreSQL uses a multi-version concurrency control (MVCC) system where deleted and updated rows are not immediately removed from disk - a background vacuum process cleans them up.
Without grasping this mechanism, teams that come from a MySQL background can see PostgreSQL performance drop in ways that surprise them.
MongoDB: Documents First
When MongoDB launched in 2009, it came with a promise. The idea was that you could store data the way application code thinks about it, as nested objects with variable structure rather than having to put data into flat relational tables. Developers who had grown up finding SQL foreign key relationships and normalization tedious answered that promise.
MongoDB has matured substantially since its early "web scale" marketing era. The platform now has multi-document ACID transactions, schema validation, time-series collections, and Atlas Vector Search.
Gartner placed MongoDB as a Leader in the 2024 Cloud Database Management Systems Magic Quadrant and that shows that MongoDB is seen as a legitimate enterprise platform.[17]
The Document Model's Real Advantages
Genuinely document-centric data makes the document model come more naturally. Without any need for junction tables or nullable columns, a blog post with a variable count of tags, an e-commerce product carrying attributes particular to its category and a user profile with optional fields all fit MongoDB's model.
Document operations get a lot done through the MongoDB query language, which is not SQL but still powerful enough to handle filtering, projecting, grouping, unwinding arrays and computing values in a composable way. Teams that mainly work in JavaScript and JSON find the transition easy.
Though performance falls short of what PostgreSQL can do with its join optimization as collections grow larger, the $lookup stage in the aggregation pipeline does perform left outer joins between collections.
More built into MongoDB than either MySQL or PostgreSQL is its horizontal scaling story. Data gets distributed across many servers according to a shard key and that is a first-class feature along with operational tooling for sharding.
For write-heavy workloads at very high scale, this architecture is easier to operate than sharding a PostgreSQL cluster via Citus.
Years of production learning go into the MongoDB documentation that gives clear guidance on how to choose a shard key, move chunks around and configure the balancer.
MongoDB's Historical Problems (Mostly Solved)
Early on, MongoDB got a reputation for data loss from default write concern settings that put performance ahead of durability. Writes were acknowledged before being flushed to disk by default in the first versions. The defaults changed in MongoDB 3.0 and today's defaults are safe.
The reputation lingered longer than the problem lasted. A useful reminder came out of that to evaluate tools by what they are now instead of what they were in 2013.
Applications that needed referential integrity ran into a real architectural limit from the absence of multi-document transactions. MongoDB 4.0 brought in ACID transactions across multiple documents and collections. Though they do work, these transactions come with a performance cost compared to what single-document operations offer.
Designing schemas to avoid multi-document transactions wherever possible by putting related data in one document instead of referencing across collections is what the MongoDB documentation says to do. The advice is right but it departs from how relational systems think.
The SSPL license introduced in MongoDB 3.6 is more restrictive than MIT or Apache licenses. The Server Side Public License requires companies that offer MongoDB as a managed service to open-source their entire stack - not just modifications to MongoDB itself.[7]
This does not affect typical application development, but it caused AWS, Google, and Azure to discontinue their MongoDB-compatible managed services and create their own document database products (DocumentDB, Firestore, Cosmos DB for MongoDB API).
If you want a fully MongoDB-compatible managed service, MongoDB Atlas is essentially your only option.
Atlas: The Managed MongoDB Experience
MongoDB Atlas, the managed cloud service, has become the primary way most teams run MongoDB in production. It handles sharding, backups, monitoring, scaling, and version upgrades. Atlas includes a vector search capability for AI applications, full-text search via Lucene integration, and a Charts feature for data visualization.
Atlas costs more than RDS equivalents at equivalent specifications. A dedicated cluster of type M10 (2 vCPUs, 2GB RAM) starts at around $57 monthly.[13] By way of comparison, a similar RDS PostgreSQL instance comes to about $30 to $40 monthly.
Still, Atlas comes with operational features that you would have to set up yourself on self-managed instances. These are automatic backups, point-in-time recovery and automated failover.
When a team does not have dedicated database operations expertise, paying the premium for self-managed instances becomes worthwhile.
Performance in Practice
Results from benchmarks differ markedly by workload and most published benchmarks come out of the database vendor. Independent testing by Percona, EnterpriseDB and Fauna's open benchmark suite shows that these generalizations hold up:
Simple read queries on indexed columns: MySQL comes out slightly faster, PostgreSQL performs comparably within 5 to 10 percent and MongoDB is slightly slower for equivalent point queries because of the cost of BSON deserialization.
Complex analytical queries with aggregations: Here, PostgreSQL comes out as the winner. The query planner handles complex joins and aggregations better than MySQL does and MongoDB's aggregation pipeline is powerful but it cannot match the full flexibility of full SQL.
PostgreSQL most often beats MySQL by 20 to 40 percent on TPC-H benchmark queries (what is a standard analytical workload). That is for complex multi-join queries.
High-volume document inserts. With unordered inserts, the right write concerns and a good shard key, MongoDB is fastest at writing large volumes of documents. On event logging and other systems that append a lot, MongoDB's document model and write path really do run faster.
Mixed read/write workloads: All three are comparable in typical web application workloads. The 80/20 read/write pattern of most CRUD applications does not produce meaningful differences between the three databases when properly indexed.
Almost always the bottleneck is the query planner hitting a missing index or a schema design choice and not the database engine itself.
JSON document queries. Most query patterns find PostgreSQL JSONB with GIN indexes as fast as MongoDB. Deeply nested document traversals and queries depending on MongoDB-specific operators such as $elemMatch on embedded arrays make MongoDB faster.
Vector similarity search: When it comes to vector similarity search, PostgreSQL using pgvector and HNSW indexing is quick enough for production use up to about 10 to 50 million vectors on one node. MongoDB Atlas Vector Search scales across nodes and deals better with larger datasets. Brute-force cosine similarity computation is much slower than both of them.
Pricing and Managed Cloud Options
Self-hosting all three databases on your own infrastructure is free. It is managed service pricing that brings about the only real differences:
MySQL: A db.t3.micro instance that has 1 vCPU and 1GB RAM costs about $25 per month as a starting point for Amazon RDS MySQL. The smallest dedicated instance of Aurora MySQL, Amazon's MySQL-compatible managed database, comes in at around $65 a month but it gives better performance, multi-AZ reliability and faster failover.
PlanetScale offers a free tier with 5GB storage and 1 billion row reads per month - one of the most generous free tiers in the managed database space.[16]
PostgreSQL: Amazon RDS PostgreSQL costs about the same as RDS MySQL. Supabase gives a large free tier that includes 500MB of database storage, 2GB of file storage and full PostgreSQL access with no limit on rows.[14]
With a consumption-based pricing model and autoscaling to zero when idle, Neon gives serverless PostgreSQL that is cost-effective for development environments and low-traffic production sites.[15] Railway and Render also have simple PostgreSQL hosting starting at $5-7/month.
MongoDB: A 512MB M0 shared cluster that is enough for development and very small production workloads begins at $0 in Atlas. The M10 dedicated cluster starts at about $57 per month.
Atlas costs about $400 per month at the M30 tier (4 vCPUs, 16GB RAM) versus about $200 per month for a comparable RDS PostgreSQL instance. The premium for Atlas is real but it comes with the operational features described above.
Recommendations by Use Case
Traditional web application (user accounts, sessions, relational data). PostgreSQL. It has a better feature set than MySQL, presents no practical performance disadvantage for most workloads and has better licensing. JSONB takes care of any need for document storage without adding a second database.
WordPress or LAMP stack application. MySQL. The ecosystem takes a lot for granted and fighting those assumptions is not worth it. Specifically built for MySQL, WordPress creates its database schema and optimization tools like WP-CLI and Percona Toolkit work with MySQL and across the WordPress community, operational knowledge centers on MySQL.
Application requiring flexible schema for user-generated content. Most of the time, PostgreSQL with JSONB meets what the app needs. The app goes to MongoDB when the whole data model is truly document-centric, when the team knows more JavaScript than SQL and when horizontal sharding has to be built in from day one.
High write volume, horizontal scale from day one: On top of MongoDB and Atlas. The sharding that comes built in is easier to operate than what PostgreSQL gives (Citus takes more manual work to set up) and when you really need to write millions of documents per second across many geographies, MongoDB's design fits the bill.
Analytics or reporting alongside transactional data. PostgreSQL manages this job much better than what the alternatives can do. Window functions, complex joins, materialized views and extensions like TimescaleDB for time-series data handle it all.
When you need OLAP-scale analytics, use PostgreSQL for OLTP together with a separate columnar store such as Redshift, BigQuery or DuckDB for analytics.
AI applications storing embeddings or doing semantic search: PostgreSQL with pgvector. By 2026, this has become a compelling reason to pick PostgreSQL specifically. Most new AI apps run on PostgreSQL as their main database with pgvector so they avoid the operational complexity of a separate vector store.
Regulated industries including financial services, healthcare and government. Procurement processes that must comply call for compliance across MongoDB's SSPL licensing. Its audit logging is less mature by comparison with what enterprise relational databases offer and with PostgreSQL or MySQL as well.
PostgreSQL's audit extension (pgaudit) and mature role-based access control are well-understood by security auditors.[18]
Migration Considerations
Moving between these databases is expensive. The cost is worth understanding before you commit.
Migrating from MySQL to PostgreSQL is the most common migration in this category.
MySQL and PostgreSQL are both relational databases with similar SQL dialects, but the differences (MySQL's case-insensitive string comparison, its different handling of GROUP BY, its JSON type differences) mean a migration is never a simple export/import.
Automating much of the work, tools like pgloader can handle much of the work but each query still needs testing against PostgreSQL's stricter behavior.
When moving from MongoDB to PostgreSQL, you have to rethink your data model. Documents that contain embedded arrays as well as nested objects do not translate cleanly into normalized relational tables. During migration, teams most often find out that what their MongoDB schema captured was convenience at the application layer rather than the actual relationships in the data.
This is not necessarily bad (the migration is an opportunity to build a more correct model) but it is time-consuming.
When teams move from PostgreSQL or MySQL to MongoDB, they do so less often because we need more flexibility and more often because we need horizontal sharding and document storage for this particular new service. Most teams end up running both instead of doing a full migration.
Sources & Further Reading
- PostgreSQL 16 Release Notes - View source
- MySQL 8.0 Reference Manual -
- MongoDB 7 Documentation -
- 'Designing Data-Intensive Applications' - Martin Kleppmann, O'Reilly 2017
- 'Use the Index, Luke' - SQL Performance Explained -
- pgvector GitHub Repository -
- MongoDB SSPL License Analysis - View source
- TimescaleDB Documentation -
- Citus Documentation -
- Stack Overflow Developer Survey 2025 - survey.stackoverflow.co/2025
- DB-Engines Ranking March 2026 -
- Percona MySQL 8.0 Benchmark Report 2024 -
- MongoDB Atlas pricing - mongodb.com/pricing/cloud
- Supabase pricing and free tier -
- Neon serverless PostgreSQL - neon.tech
- PlanetScale free tier -
- Gartner Magic Quadrant for Cloud DBMS 2024 -
- pgaudit documentation -

