Quick Verdict
- Default recommendation: PostgreSQL 17 — more capable, more open licence, better for AI workloads.
- Choose MySQL 9 when: Your team has MySQL expertise, you’re building on WordPress/Drupal/Laravel, or you need Galera multi-primary replication.
- For AI/vector search: PostgreSQL 17 + pgvector — there is no comparable MySQL solution.
- For raw throughput (simple writes): MySQL 9 is marginally faster for basic INSERT-heavy workloads.
Introduction
Direct Answer: Should I use PostgreSQL or MySQL for a new project in 2026?
For a new project started in 2026, PostgreSQL 17 is the better default choice in most cases. PostgreSQL has superior JSON/JSONB querying, more powerful window functions and CTEs, the pgvector extension for storing AI embeddings natively, better standards compliance, and a more permissive licence (PostgreSQL Licence vs MySQL’s GPL v2). MySQL 9 is the right choice when: building on an existing MySQL stack or with a team that has deep MySQL expertise; working in the WordPress, Drupal, or Laravel ecosystems where MySQL is the community default; or needing Galera Cluster for synchronous multi-primary replication across geographically distributed nodes. For AI-integrated applications — RAG pipelines, embedding storage, vector similarity search — PostgreSQL with pgvector is the clear choice, as MySQL has no equivalent extension. Both databases are mature, production-ready, and sovereign (self-hostable, open-source) options. The performance differences are minor for most workloads; the capability differences are more significant.
Testing Methodology
Tests run on Ubuntu 24.04 LTS, Hetzner CX32 (4 vCPU, 8GB RAM, NVMe SSD), April 2026. PostgreSQL 17.4 and MySQL 9.0.1, both with tuned configurations (see PostgreSQL Performance Tuning and How to Install MySQL 9 for the config used).
Benchmarks used:
- sysbench OLTP: Simulates transactional workload (reads + writes)
- pgbench / mysqlslap: Native database benchmarks
- Custom JSON queries: Comparable JSON document queries on both databases
- HammerDB TPC-C: OLTP simulation (20 warehouses, 10 threads)
Performance Benchmarks
Write Performance (sysbench OLTP write-only, 16 threads)
| Metric | PostgreSQL 17 | MySQL 9 |
|---|---|---|
| Transactions/sec | 3,847 | 4,312 |
| Latency avg (ms) | 4.16 | 3.71 |
| Latency 95th (ms) | 6.91 | 5.77 |
MySQL 9 is ~12% faster on pure write throughput. This advantage matters for high-volume INSERT workloads (logging, IoT telemetry, event streaming). For most web applications, neither database will be the bottleneck at this load level.
Read Performance (sysbench OLTP read-only, 16 threads)
| Metric | PostgreSQL 17 | MySQL 9 |
|---|---|---|
| Queries/sec | 28,341 | 26,892 |
| Latency avg (ms) | 0.56 | 0.59 |
PostgreSQL 17 is marginally faster on read-heavy workloads with the query planner’s improved parallel query execution.
Complex Query Performance
This is where the databases diverge significantly. The same analytical query (GROUP BY + window function + subquery):
-- Find top 3 products by revenue per category, with running total
SELECT
category,
product_name,
revenue,
SUM(revenue) OVER (PARTITION BY category ORDER BY revenue DESC) AS running_total,
RANK() OVER (PARTITION BY category ORDER BY revenue DESC) AS rank
FROM sales
WHERE rank <= 3;
- PostgreSQL 17: 12ms (uses window function natively, single-pass)
- MySQL 9: 34ms (requires a subquery for rank filtering, less optimised)
PostgreSQL’s query planner is significantly more sophisticated for analytical queries involving window functions, CTEs, and complex JOINs.
Feature Comparison
JSON Support
Both databases support JSON, but PostgreSQL’s JSONB is materially more capable:
PostgreSQL JSONB:
-- Store and index arbitrary JSON documents
CREATE TABLE events (
id BIGSERIAL PRIMARY KEY,
data JSONB
);
-- GIN index for fast JSON querying
CREATE INDEX idx_events_data ON events USING gin(data);
-- Query nested JSON — fast with index
SELECT * FROM events WHERE data @> '{"type": "purchase", "amount": {"currency": "USD"}}';
-- JSON path queries (PostgreSQL 12+)
SELECT jsonb_path_query(data, '$.items[*].price') FROM events;
MySQL 9 JSON:
-- MySQL JSON column
CREATE TABLE events (
id BIGINT AUTO_INCREMENT PRIMARY KEY,
data JSON
);
-- Functional index for JSON (MySQL 8+)
ALTER TABLE events ADD INDEX idx_type ((CAST(data->>'$.type' AS CHAR(50))));
-- Query JSON
SELECT * FROM events WHERE JSON_EXTRACT(data, '$.type') = 'purchase';
PostgreSQL’s @> containment operator, GIN indexing, and jsonb_path_query are more powerful and concise than MySQL’s JSON_EXTRACT function-based approach. For document-heavy applications, this is a decisive advantage.
Vector Support (AI Embeddings)
PostgreSQL 17 + pgvector is the sovereign standard for storing AI embeddings in 2026:
-- PostgreSQL: install pgvector, store embeddings
CREATE EXTENSION vector;
CREATE TABLE documents (
id BIGSERIAL PRIMARY KEY,
content TEXT,
embedding vector(768)
);
CREATE INDEX ON documents USING hnsw (embedding vector_cosine_ops);
-- Semantic search: find 10 most similar documents
SELECT content, embedding <=> '[0.1, 0.2, ...]'::vector AS distance
FROM documents
ORDER BY distance LIMIT 10;
MySQL: No equivalent. MySQL 9 has no vector data type or similarity search capability. Vector search with MySQL requires a separate dedicated vector database (Pinecone, Weaviate, Qdrant), which means either a cloud dependency or an additional self-hosted service to manage.
For any application involving LLMs, RAG pipelines, or semantic search, this is the single most important differentiating factor in 2026.
Standards Compliance
PostgreSQL is the most SQL-standards-compliant open-source database. It supports: full window functions, lateral joins, WITH RECURSIVE CTEs, FILTER clause in aggregates, MERGE statements, range types, and GENERATED ALWAYS AS computed columns — all fully compliant with SQL:2016 and SQL:2023.
MySQL 9 has improved substantially but still has gaps: WITH RECURSIVE performance is inferior, FILTER is not supported in all aggregate contexts, and some SQL:2023 features are missing.
For applications that may need to switch databases in the future, PostgreSQL’s standards compliance means less vendor-specific SQL to rewrite.
Replication Options
| Replication Type | PostgreSQL 17 | MySQL 9 |
|---|---|---|
| Primary-replica (async) | ✓ Streaming replication | ✓ Binary log replication |
| Primary-replica (sync) | ✓ Synchronous commit | ✓ Semi-sync |
| Multi-primary | ✓ BDR (requires Postgres BDR extension) | ✓ Galera Cluster (mature) |
| Logical replication | ✓ Built-in (PostgreSQL 15+) | ✓ Built-in |
| Cloud-managed | ✓ All major clouds | ✓ All major clouds |
MySQL’s Galera Cluster for multi-primary synchronous replication is more mature and widely deployed than PostgreSQL’s BDR equivalent. If you specifically need multi-primary active-active replication across geographic regions, MySQL + Galera has a longer production track record.
Ecosystem and Tooling
ORM Support
Both databases are first-class citizens in all major ORMs:
| ORM | PostgreSQL | MySQL |
|---|---|---|
| Prisma | ✓ | ✓ |
| SQLAlchemy | ✓ | ✓ |
| Django ORM | ✓ | ✓ |
| ActiveRecord (Rails) | ✓ | ✓ |
| GORM | ✓ | ✓ |
| Hibernate | ✓ | ✓ |
CMS and Framework Ecosystems
| Application | Default DB | Notes |
|---|---|---|
| WordPress | MySQL | PostgreSQL possible but unsupported by plugins |
| Drupal | MySQL/PostgreSQL | Both officially supported |
| Laravel | MySQL | PostgreSQL supported, MySQL community default |
| Django | PostgreSQL | Official recommendation |
| Ruby on Rails | PostgreSQL | Official recommendation |
| FastAPI examples | PostgreSQL | Convention in Python ecosystem |
If you’re building a WordPress site, MySQL is the pragmatic choice — the entire plugin ecosystem assumes MySQL, and many plugins use MySQL-specific syntax.
Licensing and Sovereignty
PostgreSQL Licence
PostgreSQL uses its own PostgreSQL Licence, a permissive open-source licence similar to the MIT licence. You can use, modify, distribute, and embed PostgreSQL in commercial software without restrictions or royalties.
MySQL GPL v2 + Commercial Exception
MySQL is dual-licensed. The open-source version (MySQL Community Edition) is released under GPL v2. The GPL v2 has implications: if you distribute software that includes MySQL as an embedded component (not as a separate server process), your software may need to also be GPL-licensed, or you must purchase a commercial licence from Oracle.
For most web applications where MySQL runs as a separate database server process (not embedded), the GPL v2 is not a concern. For ISVs distributing software with an embedded database, PostgreSQL’s licence is clearly simpler.
Both are self-hostable, both have no Oracle/cloud-vendor lock-in risk for the open-source version (PostgreSQL has none; MySQL’s risk is Oracle acquisition and commercial licensing pressure, which has been stable since 2010).
Which Should You Choose?
Choose PostgreSQL 17 for:
- New projects with no existing database constraint
- AI/LLM applications requiring vector storage (pgvector)
- Complex analytical queries with window functions, CTEs, JSONB
- Applications where PostgreSQL Licence’s permissiveness matters
- Django, FastAPI, or Ruby on Rails projects (community default)
- Any project where SQL standards compliance matters
Choose MySQL 9 for:
- WordPress, Drupal, or plugins-heavy PHP applications
- Teams with deep MySQL/MariaDB expertise
- Existing MySQL infrastructure you’re extending
- Applications requiring Galera multi-primary active-active replication
- Laravel projects where MySQL is the team convention
MariaDB as a MySQL alternative: MariaDB is a community fork of MySQL with full MySQL compatibility and some PostgreSQL-inspired features. If you’re using MySQL, MariaDB 11.x is a drop-in replacement with a community-focused governance structure (not Oracle-controlled). It’s worth considering if Oracle’s MySQL stewardship is a concern.
Conclusion
PostgreSQL 17 is the better default for new projects in 2026 — its capabilities (JSONB, pgvector, window functions, standards compliance) and permissive licensing make it the more capable and less legally complex choice for most modern application architectures. MySQL 9 remains the right choice within the PHP/WordPress/Laravel ecosystem where it is the convention, and for multi-primary replication use cases where Galera Cluster’s maturity is relevant.
The decision is rarely close — if you’re starting fresh with no ecosystem constraints, choose PostgreSQL. If you’re working in a context where MySQL is the expected tool, there’s no compelling reason to deviate.
People Also Ask
Is PostgreSQL faster than MySQL?
On read-heavy and analytical workloads with complex queries, PostgreSQL 17 is generally faster due to its more sophisticated query planner and parallel query execution. On pure write throughput (simple INSERTs with no complex queries), MySQL 9 is marginally faster (~12% in sysbench benchmarks). For most web application workloads, the performance difference is small enough that database choice should be driven by features and ecosystem fit, not benchmark scores. Both are well-capable of handling millions of queries per day on modest hardware.
Can I migrate from MySQL to PostgreSQL?
Yes, but it requires effort. The SQL dialects are mostly compatible, but key differences include: AUTO_INCREMENT vs SERIAL/BIGSERIAL, backtick vs double-quote identifiers, TINYINT(1) vs BOOLEAN, string case-sensitivity differences, and date/time function naming. Tools like pgloader automate MySQL-to-PostgreSQL migrations for schema and data. Plan for 1–5 days of migration work for a medium-complexity application, including testing. Many organisations use pgloader for the initial data transfer, then fix application query compatibility issues one by one.
What is MariaDB and should I use it instead of MySQL?
MariaDB is a community fork of MySQL, started in 2009 when Oracle acquired Sun Microsystems (which owned MySQL). It maintains full MySQL compatibility (same client libraries, same SQL dialect for most queries) while adding features not in MySQL, including some PostgreSQL-inspired capabilities. MariaDB is governed by the MariaDB Foundation, independent of Oracle. If you have MySQL operational expertise, MariaDB is a drop-in replacement with a less corporate governance structure. MariaDB 11.x includes improvements like better JSON support, temporal data tables, and parallel replication that MySQL 9 lacks or added later.
Further Reading
- How to Install PostgreSQL 17 on Ubuntu 24.04 — set up PostgreSQL as your application database
- PostgreSQL 17 Performance Tuning Guide — optimise your PostgreSQL instance
- How to Install MySQL 9 on Ubuntu 24.04 — set up MySQL if that’s your choice
- MySQL 9 Replication: Primary-Replica Setup — high availability for MySQL deployments
Tested: April 2026. PostgreSQL 17.4, MySQL 9.0.1, Ubuntu 24.04 LTS, Hetzner CX32. Next review: October 2026.