Why Choose PostgreSQL Over MySQL? A Technical Comparison of Their Strengths
The article analyzes why many Chinese cloud providers and enterprises prefer PostgreSQL to MySQL, detailing PostgreSQL's richer data types, native sequence support, extensible ecosystem, advanced monitoring, robust replication, open licensing, and MVCC implementation, while acknowledging MySQL's remaining advantages in specific scenarios.
Background
With the push for domestic innovation and the need for open, stable, and feature‑rich databases, PostgreSQL has become the preferred foundation for many Chinese technology companies.
Adoption by Major Cloud Providers
Tencent Cloud TDSQL PG (open‑source name: https://github.com/Tencent/TBase) – adds a global transaction manager (GTM) for cross‑shard transactions.
Alibaba Cloud PolarDB for PostgreSQL – redesigns the storage layer to enable "one‑write‑multiple‑read" shared storage and supports second‑level scaling of read replicas.
Huawei Cloud GaussDB (openGauss) – partially compatible with the PostgreSQL ecosystem, adds a column‑store engine and AI‑driven optimizer for HTAP workloads ( https://opengauss.org).
Hangzhou EasyView openHalo – an open‑source distributed PostgreSQL‑based system ( https://github.com/HaloTech-Co-Ltd/openHalo).
Why Choose PostgreSQL Over MySQL?
1. Richer Data Types
Array : PostgreSQL supports ARRAY to store multiple values in a single column.
Range : Types such as int4range and tsrange model intervals (time, price, etc.).
Composite : Custom structures (e.g., POINT(x,y)) can be defined directly.
JSONB : Stores JSON with indexing, query, and update capabilities, offering far better performance than plain JSON.
2. Native Sequence Support
MySQL 5.7+ simulates sequences with AUTO_INCREMENT + 3088413, but it lacks an independent sequence object that can be used outside a table.
-- PostgreSQL: create an independent sequence
CREATE SEQUENCE order_seq START WITH 1 INCREMENT BY 1;
-- Use the sequence to generate IDs
INSERT INTO orders (id, name) VALUES (nextval('order_seq'), 'test');In MySQL the equivalent requires binding to a table:
-- Must bind to a table's AUTO_INCREMENT
ALTER TABLE orders AUTO_INCREMENT = 1000;
-- Or simulate with a variable
SET @next_id = 3088413 + 1;Cannot share a sequence across tables.
Ensuring uniqueness in distributed environments often needs external tools such as Redis.
3. Extensible Ecosystem
TimescaleDB: Time‑series database with automatic partitioning and compression. pg_trgm: Fuzzy matching and similarity search. Citus: Distributed database extension. pg_stat_statements: SQL execution statistics and monitoring.
PostgreSQL is a "programmable database" that can be turned into an application platform, whereas MySQL behaves more like a pure execution engine.
4. Advanced Performance Monitoring
Built‑in statistics views such as pg_stat_activity, pg_stat_statements, and pg_locks.
Supports EXPLAIN ANALYZE to show actual execution time and row counts.
Mature third‑party tools: PgAdmin, pg_stat_monitor, and Prometheus + Grafana integration.
Active open‑source community with extensive documentation and debugging resources.
5. Replication and High Availability
MySQL replication drawbacks:
Default asynchronous replication introduces latency risk.
Lack of strong consistency; a primary failure may cause transaction loss on replicas.
GTID helps but misconfiguration can break replication.
Semi‑sync replication requires extra configuration and high‑quality network.
PostgreSQL solutions:
Streaming Replication – supports both async and sync modes.
Logical Replication – allows table‑level or cross‑version replication.
WAL (Write‑Ahead Logging) – mature mechanism ensuring durability and consistency.
Synchronous Replication – primary waits for at least one replica to confirm before committing, achieving zero data loss.
MySQL's replication resembles a "backup mechanism," while PostgreSQL's replication is an integral part of a high‑availability architecture.
6. Licensing and Community
License : MySQL – GPL + commercial license controlled by Oracle; PostgreSQL – BSD‑like, fully free.
Enterprise vs Community : MySQL enterprise adds features like auditing and encryption; PostgreSQL community edition is complete without feature cuts.
Source Transparency : MySQL core development is Oracle‑driven; PostgreSQL is maintained by a global community with open contributions.
Long‑term Stability : MySQL roadmap can shift with corporate decisions; PostgreSQL is governed by a foundation, independent of any single company.
Examples:
MySQL 8.0 introduced window functions only in version 8.0, whereas PostgreSQL supported them much earlier.
Oracle may deliberately slow community‑edition feature rollout to promote commercial products.
7. MVCC Implementation Differences
PostgreSQL stores multiple versions per row, keeping old versions in the heap until vacuum cleans them, providing full isolation and serializable snapshot isolation.
MySQL keeps only the current version; older versions reside in the undo log, offering faster reads but causing undo‑log bloat for long transactions.
In PostgreSQL, readers can see a previous state even while a writer is updating.
In MySQL, uncommitted changes may appear as dirty reads or non‑repeatable reads depending on the isolation level.
Conclusion
PostgreSQL and MySQL are not simply rivals; each fits different workloads. For systems that require long‑term evolution, complex data models, and strong consistency, PostgreSQL provides a more solid foundation. For fast‑to‑market, read‑heavy web applications, MySQL remains an efficient choice. The rise of domestic databases builds on PostgreSQL’s open, user‑driven, and technically superior base.
java1234
Former senior programmer at a Fortune Global 500 company, dedicated to sharing Java expertise. Visit Feng's site: Java Knowledge Sharing, www.java1234.com
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.
