Vibe Engines is free, interactive AI engineering & system design — runs in your browser. Pick a learning path →
PostgreSQL vs MySQL: correctness or simplicity?
Both are mature, free, battle-tested relational databases you can build a company on — so the choice rarely comes down to raw capability. The character differs: Postgres prizes correctness, standards-compliance and advanced features; MySQL prizes simplicity and fast, read-heavy operation. Knowing the grain of each keeps you from fighting your database later.
The core difference: character, not capability
PostgreSQL is the feature-rich, standards-first database: rich types (JSONB, arrays, ranges, geospatial), advanced indexing, powerful concurrency via MVCC, extensions, and strict correctness by default. MySQL is the simpler, extremely popular workhorse tuned historically for fast reads and straightforward web workloads, with a gentler learning curve and huge hosting ubiquity. Neither is "better" — they’re shaped differently.
Complex queries, data integrity, advanced types, or you’ll grow into heavy features? Postgres — increasingly the default for new projects. A simple, read-heavy app, or an ecosystem/host that favors it (much of classic PHP/WordPress-era web)? MySQL is perfectly solid.
Head to head
| Dimension | PostgreSQL | MySQL |
|---|---|---|
| Philosophy | Correctness, standards, features | Simplicity, speed, ubiquity |
| Data types | Very rich (JSONB, arrays, geo, custom) | Solid core types; JSON support newer |
| Concurrency | MVCC, strong under mixed read/write | MVCC via InnoDB; historically read-tuned |
| Advanced SQL | Window fns, CTEs, full-text, extensions | Good; historically trailed on some features |
| Extensibility | Extensions (PostGIS, pgvector…) | Storage engines; fewer extensions |
| Ease of start | Slightly steeper | Very approachable |
| Ecosystem | Default for many modern stacks | Enormous, especially classic web hosting |
Note: MySQL and its fork MariaDB have closed much of the historical feature gap, and Postgres has always been fast — treat the old "MySQL is faster, Postgres has more features" shorthand as a rough tendency, not a law.
When to use each
Reach for PostgreSQL
- Complex queries, analytics, reporting
- Rich data: JSONB, geospatial (PostGIS), vectors (pgvector)
- Strict data integrity and correctness
- You expect to grow into advanced features
- New greenfield project with no host constraint
Reach for MySQL
- Simple, read-heavy web applications
- Existing MySQL expertise or ecosystem (WordPress, LAMP)
- A host or platform that strongly favors it
- You value a gentle learning curve
- Straightforward CRUD without exotic types
For new projects with a free choice, Postgres has become the common default — it does everything MySQL does, adds a deep well of features (including pgvector for AI retrieval), and you rarely outgrow it. Choose MySQL when the ecosystem, team expertise, or a specific host makes it the pragmatic pick.
How MVCC differs under the hood — and why it matters at scale
Both databases use MVCC (multi-version concurrency control) so readers never block writers and vice versa, but they implement it differently, and the difference shows up under real production load. Postgres stores old row versions directly in the same table (a new row version is appended, the old one marked dead) and relies on a background process called VACUUM to reclaim that dead space later. Under heavy write/update churn without tuned autovacuum settings, table bloat is a real, well-known operational concern — dead row versions accumulate faster than vacuum reclaims them, tables grow larger than their live data would suggest, and query performance degrades until you tune or manually intervene.
MySQL's InnoDB engine takes a different approach: it keeps the current row version in the main table and pushes old versions into a separate structure called the undo log, which is purged once no transaction needs those old versions anymore. This avoids Postgres-style table bloat from old row versions living in the main table, but comes with a different sharp edge: a single very-long-running transaction can prevent the undo log from being purged, causing it to grow unboundedly and — in extreme cases — fill available storage.
Postgres's MVCC needs vacuum tuning as a routine operational discipline on write-heavy tables. InnoDB's MVCC needs vigilance against long-running transactions holding old versions hostage. Neither is "solved" — both are things you learn to operate, not set-and-forget.
A worked scenario: adding a JSON-backed feature flag system
Say a product team wants per-user feature flags stored as flexible JSON — each user can have an arbitrary set of enabled experiments, and the query pattern is "find all users with experiment X enabled" plus "get user Y's full flag set." This is a genuinely useful test of the two databases' different strengths.
In Postgres, this is a JSONB column with a GIN index on it: CREATE INDEX ON users USING GIN (flags), then WHERE flags @> '{"experiment_x": true}' uses the index directly, because JSONB is a genuinely indexed, queryable binary format — not just a text blob you happen to store JSON in. You get relational guarantees (foreign keys to the user, transactions across flag updates and other user data) plus document flexibility in the same row, in the same query.
In MySQL, JSON support has matured significantly (generated columns can extract and index specific JSON paths), but it's a later addition to the engine rather than a first-class citizen designed in from the start — querying arbitrary nested JSON structure efficiently often means either extracting the specific paths you'll query into indexed generated columns ahead of time (workable, but you have to anticipate the query pattern) or accepting a slower path. For a schema that's genuinely mixed relational-plus-flexible-document, Postgres's JSONB tends to need less workaround engineering.
Anywhere the data is "mostly relational, with a few genuinely flexible/schemaless fields" — feature flags, user preferences, event metadata, API request/response logs — Postgres's JSONB plus GIN indexing tends to be the smoother fit. Pure key-value or document-native workloads with no relational needs at all are a different conversation (see SQL vs NoSQL).
Common mistakes
| Mistake | Why it bites |
|---|---|
| Ignoring autovacuum tuning on high-churn Postgres tables | Default autovacuum settings are conservative and can fall behind on tables with heavy update/delete traffic, leading to bloat and, in the worst case, transaction ID wraparound risk on very old, never-vacuumed tables — a real production incident category, not a theoretical one. |
| Leaving a MySQL transaction open and idle | An open transaction (even one doing nothing) holds InnoDB's undo log from being purged for everything that started after it — a forgotten idle transaction in a connection pool can quietly cause unbounded undo log growth across the whole database, not just its own rows. |
| Assuming default MySQL isolation matches Postgres's | MySQL's InnoDB defaults to REPEATABLE READ; Postgres defaults to READ COMMITTED. Application code that assumes one isolation level's specific anomaly behavior (e.g., phantom reads) can behave subtly differently after a migration between the two if isolation level isn't set explicitly. |
| Treating "MySQL is simpler" as "MySQL needs less tuning at scale" | MySQL's approachable defaults are genuinely easier for a small app, but at high write volume both databases need real operational tuning — buffer pool sizing, replication lag management, index strategy. Simplicity at the start doesn't mean simplicity forever. |
The picture: one UPDATE on each engine
balance=100. They disagree on where it lives. Postgres writes the new version beside the old one in the table, and every index may gain an entry for it. InnoDB overwrites the row inside the primary-key tree and moves the old values to the undo log. So Postgres’s cleanup job (VACUUM) works on the table and its indexes, and InnoDB’s (purge) works on a separate log. That is the page’s MVCC section as storage, and it is why the two engines bloat in different places: Postgres in its tables and indexes, InnoDB in its undo history.Cost and trade-offs, operation by operation
Here Case is one operation on one engine. Time is the I/O work it does. Space is what it leaves behind or holds. No benchmark numbers: these are the storage mechanics that decide which way a benchmark goes for your workload.
| Case | Time | Space | Why |
|---|---|---|---|
| UPDATE a non-indexed column, Postgres | Writes a whole new tuple; no index writes if it is a HOT update | A dead tuple until VACUUM | HOT needs free space on the same page, which a lower fillfactor buys. |
| UPDATE a non-indexed column, InnoDB | Changes the row in place in the clustered index and copies the old values to undo | An undo record until purge | Secondary indexes are untouched: they store the primary key, not a physical address. |
| UPDATE an indexed column, Postgres | A new tuple plus a new entry in every index | Dead entries in every index, not just the changed one | One indexed column changing rules out HOT for the whole update. |
| UPDATE an indexed column, InnoDB | In place, plus delete-mark the old entry and insert a new one in that index only | Undo plus a delete-marked entry until purge | The other secondary indexes stay as they were. |
| Primary-key lookup, Postgres | Index descent, then a trip to the heap page | Index and table are separate files | The heap trip is skipped only by an index-only scan. |
| Primary-key lookup, InnoDB | One B-tree descent; the row sits in the leaf | The table is the primary-key index | This is InnoDB’s home ground for key-value-style reads. |
| Secondary-index lookup, Postgres | Index descent, then the heap page its ctid names | Index entries hold a physical address | Index-only when the index covers the query and the page is all-visible. |
| Secondary-index lookup, InnoDB | Secondary descent, then a second descent of the clustered index by primary key | Every secondary entry carries a copy of the primary key | A wide primary key makes every secondary index bigger. A covering index skips the second descent. |
| Random UUID primary key | InnoDB: inserts land on random leaf pages of the table itself. Postgres: only the key index takes random inserts | InnoDB: page splits and half-full pages | In InnoDB the primary key decides the physical order of the rows, so a sequential key keeps inserts on the last page. |
| A long-running transaction | Postgres: VACUUM cannot remove versions newer than its snapshot. InnoDB: purge stalls | Postgres: table and index bloat. InnoDB: undo history grows | In InnoDB, old-snapshot reads also walk longer version chains and slow down. |
| One client connection | Postgres: a forked process. MySQL: a thread | A process carries more memory than a thread | Both like a pooler; Postgres needs one sooner. |
| Schema change inside a transaction | Postgres: DDL is transactional and rolls back. MySQL: DDL commits implicitly | None | A failed Postgres migration can be rolled back as a whole; a MySQL one can stop halfway. |
| COUNT(*) on a large table | Both scan, because the right count depends on each transaction’s snapshot. InnoDB walks its smallest secondary index; Postgres can use an index-only scan when the visibility map is clean | No stored row count on either | If you need a fast approximate count, read the planner’s statistics; if you need an exact one often, keep a counter table. |
| Deleting millions of old rows | Postgres marks each tuple dead; VACUUM makes the space reusable. InnoDB delete-marks each row; purge removes it | On both, the table’s file does not shrink on its own | Partition by time and drop the old partition instead: it is a metadata change, with no dead rows left to clean. |
| Replicating to a read replica | Postgres: physical streaming of the WAL, a byte-for-byte copy (logical replication for selected tables). MySQL: the binary log, applied as row events on the replica | Postgres keeps WAL a lagging replica still needs; MySQL keeps binlogs until they expire | Both replicas lag the primary, so read-your-own-writes needs routing to the primary on either engine. |
Read the table as a workload test. Many updates to columns no secondary index touches, and lookups by primary key, suit InnoDB’s layout. Many secondary indexes, mixed reads and writes, and migrations you want to roll back suit Postgres, as long as someone tunes autovacuum. Both engines punish long transactions, in different places. That is the page’s “character, not capability” point made concrete. Before you pick, write down your three most frequent writes and your three most frequent reads, then find each one in this table. The engine whose rows match your workload is usually the one that will need less fighting at 3am.
Which would you pick?
Three situations. Pick the side you'd actually build — the explanation follows.
A table takes heavy update and delete traffic on Postgres, and query times are slowly degrading with no schema change.
Default autovacuum settings are conservative and can fall behind on heavy update/delete traffic, leaving dead tuples as bloat and, on very old never-vacuumed tables, transaction ID wraparound risk. It is a documented production incident category, not a theoretical one — and it is a tuning problem, not a reason to change database.
A MySQL application opens a transaction at the start of a long request and sometimes leaves it idle for minutes.
An open transaction does not need to be doing anything to cause damage. Under InnoDB's default REPEATABLE READ, its read view, once taken, lives until it commits, so purge cannot discard undo history for changes committed after that snapshot. History accumulates and performance degrades system-wide. "Doing no work" describes the transaction, not its effect on everyone else. READ COMMITTED softens this: each statement gets a fresh read view, so an idle RC transaction mostly stops holding back purge. It is still not harmless: it keeps its row and metadata locks and its own uncommitted changes until it ends.
A team is choosing between Postgres and MySQL for a standard CRUD application with no exotic requirements.
The page frames this as a difference of character rather than capability: both handle ordinary CRUD comfortably, so the deciding factor is which one your team can operate, tune and debug at 3am. A feature checklist picks a winner on capabilities this workload will never exercise.
Quick answers
Is PostgreSQL better than MySQL?
Neither is universally better — both are excellent. Postgres leans toward correctness, advanced features and rich data types; MySQL toward simplicity and read-heavy speed with huge hosting ubiquity. For new projects with a free choice, Postgres is often the default because you rarely outgrow it.
Is MySQL faster than PostgreSQL?
Historically MySQL had an edge on simple read-heavy workloads and Postgres led on complex queries and mixed read/write, but the gap has narrowed enormously. In practice both are fast; performance depends on your schema, indexes and workload far more than the engine choice.
Should I use Postgres or MySQL for a new app?
Default to Postgres unless a specific reason points elsewhere — it handles rich types (JSONB, geo, vectors), complex queries and strict integrity, and scales further than most apps need. Choose MySQL when your ecosystem, team expertise, or host strongly favors it.
What about MariaDB?
MariaDB is a community fork of MySQL, largely compatible, created after MySQL’s acquisition by Oracle. It has added features and is a drop-in replacement in many cases. The Postgres-vs-MySQL trade-offs apply broadly to MariaDB as well.
Explore the topic
See this alongside everything else on the same subject — handbooks, system designs, challenges and tools, in one place.
More Handbooks
- Concurrency, Locks & Isolation LevelsHow overlapping operations stay correct — race conditions, optimistic vs pessimistic locking, the four isolation levels and their anomalies, MVCC, and distributed locks with fencing tokens. Part of System Design Fundamentals.Read →
- Partitioning, Sharding & ReplicationHow one dataset becomes many — range vs hash partitioning, consistent hashing and virtual nodes, hot partitions, replication topologies, replication lag, and quorums. Part of System Design Fundamentals.Read →
- The SQL HandbookWhat the database does underneath your SELECT — the relational model and keys, joins (inner/left/right/full), indexes and B-trees, the query planner and reading EXPLAIN, transactions and ACID, isolation levels and the anomalies they prevent, normalization vs denormalization, and the pitfalls (N+1, missing indexes, SELECT *).Read →
- The PostgreSQL Internals HandbookUPDATE never updates, and a janitor keeps it working. Heap pages and tuples, MVCC's row versions (xmin/xmax visibility arithmetic), VACUUM, bloat and the wraparound scare, B-trees, HOT updates and index-only scans, the WAL's three superpowers (recovery, replication, PITR), reading the planner honestly, and why PgBouncer is infrastructure.Read →
- SQL vs NoSQLFramed as a war, it’s really a menu. Relational databases give you schema, joins and ACID; NoSQL is an umbrella of document/key-value/wide-column/graph stores that drop some of that for flexibility and horizontal scale. The relationships-vs-scale core difference, the CAP trade-off, and why to start relational.Read →
- OLTP vs OLAPOne storage-layout decision explains the whole comparison: row-oriented OLTP makes fetching one record cheap, column-oriented OLAP makes aggregating one column across millions of rows cheap. Why you can’t run heavy analytics well on your production database.Read →