MySQL vs PostgreSQL: Real‑World Lessons, Pitfalls, and Choosing the Right One
The article shares a seasoned DBA’s firsthand comparison of MySQL and PostgreSQL, covering their histories, performance quirks, real‑world case studies, lock mechanisms, backup strategies, and practical selection guidelines to help developers decide which database best fits their workload.
Background
MySQL originated as a lightweight, easy‑to‑install relational database (the classic LAMP stack) and has historically emphasized rapid development. PostgreSQL was created at the Berkeley labs under Michael Stonebraker and has always focused on correctness, extensibility, and advanced SQL features such as recursive CTEs, partitioned tables, and materialized views.
Real‑world case studies
Case 1 – JSON‑heavy social app
Initial stack: MySQL 5.7 with a JSON column for comments. With a few thousand users query latency stayed under 100 ms. After the user base grew to 200 k and the comment table reached 1 M rows, loading nested comment threads took 2–3 seconds. Indexes and query rewrites could not overcome MySQL’s limited JSON operators.
Migration: switched to PostgreSQL 11, stored comments in JSONB, and created a GIN index on the JSONB column. The same nested‑comment query dropped to ~50 ms even with five‑level nesting, demonstrating PostgreSQL’s superior JSONB indexing and query planner.
Case 2 – High‑traffic order engine
During a major sales event an e‑commerce system used the legacy MyISAM engine for the orders table. The sudden write surge caused table‑level locks, inflating the typical 200 ms response to >5 seconds and causing time‑outs.
Remediation: redirected writes to an InnoDB replica on the fly. The same hardware handled the load without lock contention, and throughput increased by roughly 30 %. The incident highlighted that MySQL 8.0’s InnoDB has matured for high‑concurrency writes, while reliance on MyISAM is outdated.
Performance and operational differences
Locking : InnoDB uses gap locks that can lead to deadlocks; PostgreSQL’s row‑level locking reports conflicts with clearer messages.
Backup & restore : mysqldump may lock large tables during export; pg_dump creates a consistent snapshot without locking.
Connection overhead : Each MySQL client connection consumes more memory, increasing OOM risk under high concurrency. PostgreSQL benefits from mature connection‑pooling solutions (e.g., PgBouncer).
Error diagnostics : PostgreSQL provides detailed, actionable error messages, whereas MySQL often returns terse error codes.
Upcoming features (2025 outlook)
MySQL 8.0+ has added CTEs, window functions, hidden indexes, and experimental vector similarity search for AI workloads. PostgreSQL’s ecosystem is expanding with cloud‑native extensions: Citus (now Microsoft‑owned) for distributed queries, TimescaleDB for time‑series data, and vector‑search extensions for LLM integration. Managed services such as Alibaba Cloud PolarDB and AWS Aurora blur the line between the two engines, making SLA and operational convenience key selection criteria.
Practical selection guidelines
Team expertise : Choose the engine that the operational team can manage confidently; a technically superior database is ineffective without skilled personnel.
Business workload shape : SaaS platforms benefit from PostgreSQL’s schema isolation and rich extensions; high‑traffic content sites may prefer MySQL’s mature replication and tuning options.
Iterative migration : Start MVPs with MySQL for rapid prototyping, then migrate core services to PostgreSQL once requirements solidify. Cloud‑based migrations are generally less painful than expected.
Xiao Liu Lab
An operations lab passionate about server tinkering 🔬 Sharing automation scripts, high-availability architecture, alert optimization, and incident reviews. Using technology to reduce overtime and experience to avoid major pitfalls. Follow me for easier, more reliable operations!
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
