PostgreSQL vs MySQL: which one for your backend?
PostgreSQL and MySQL have both been around for decades, both are free, and both run huge production systems. Most comparisons end with "it depends". I'd rather give a rule: choose MySQL when raw performance on simple, high-volume queries is the main goal, and PostgreSQL as the general-purpose backend database.
Here is why.
The difference that matters: how rows are stored
Most of the performance differences come from one design decision.
MySQL (InnoDB) stores each table inside its primary key index. Reading a row by primary key lands directly on the data. When a row is updated, InnoDB changes it in place and keeps the old version in a separate undo log. Secondary indexes point at the primary key, so they don't need touching unless their own columns change.
PostgreSQL keeps rows in a separate heap, and an update writes a whole new version of the row. Indexes point at the physical location of a row version, so a new version can mean new entries in every index on the table. HOT updates avoid this when no indexed column changed and the page has free space, but it isn't guaranteed. Old versions stay in the table until VACUUM removes them.
What this means in practice:
- Update-heavy tables with many indexes cost PostgreSQL more write work, and they need autovacuum tuned properly.
- Lookups by primary key are MySQL's best case.
- MySQL pays elsewhere: secondary index lookups need a second walk through the primary key, and a large random primary key such as a UUIDv4 hurts it badly.
Uber's well-known 2016 article about moving from PostgreSQL to MySQL was largely about this write amplification and its effect on replication.
Connections
PostgreSQL starts one operating system process per connection, while MySQL uses one thread. A PostgreSQL connection costs more, so anything beyond a modest number of connections usually needs a pooler such as PgBouncer. MySQL is more forgiving here, though a pool is still a good idea.
Where PostgreSQL pulls ahead
PostgreSQL has the richer SQL and the stronger guarantees, and for a typical backend this matters every day.
A partial index covers only the rows you actually query:
CREATE INDEX orders_unpaid_idx ON orders (customer_id)
WHERE status = 'UNPAID';
RETURNING gives you the created row without a second query:
INSERT INTO users (email)
VALUES ('ada@example.com')
RETURNING id, created_at;
JSONB can be indexed as a whole, so semi-structured data can sit next to relational data:
CREATE INDEX events_payload_idx ON events USING GIN (payload);
SELECT id FROM events WHERE payload @> '{"type": "signup"}';
Schema changes are transactional, so a failed migration rolls back cleanly:
BEGIN;
ALTER TABLE users ADD COLUMN phone text;
UPDATE users SET phone = legacy_phone;
COMMIT;
In MySQL each DDL statement commits on its own, so a migration that fails halfway leaves you halfway.
PostgreSQL also has a stronger query planner for analytical work, with merge joins and parallel plans, and extensions like PostGIS and pgvector that turn it into a geospatial or vector database.
Side by side
| PostgreSQL | MySQL (InnoDB) | |
|---|---|---|
| Table storage | Heap, separate from indexes | Clustered on the primary key |
| Update | Writes a new row version | In place, old version in undo log |
| Cleanup | VACUUM |
Purge of the undo log |
| Connection | Process | Thread |
| Default isolation | Read Committed | Repeatable Read |
| Transactional DDL | Yes | No |
| Partial indexes | Yes | No |
RETURNING |
Yes | No |
| JSON | JSONB with GIN indexes |
JSON with generated columns or multi-valued indexes |
| Extensions | Large ecosystem | Limited |
Conclusion
Choose MySQL when performance is the priority and the workload is simple and high-volume: many short reads and writes by primary key, lots of connections, and queries that don't need much from the planner.
Choose PostgreSQL as your backend database for almost everything else: complex queries, data integrity, JSON next to relational data, and migrations you can trust. It is what I'd start a new backend with, and it is what stores the visit log of this site.
One caution: a rule like this is a starting point, not a benchmark. Schema, indexes and hardware often matter more than the engine, so if performance really decides it, test both with your own queries and your own data.