Why We Choose PostgreSQL Over MySQL for Most Projects
We have built production systems on both PostgreSQL and MySQL. Both are battle-tested, well-documented, and capable databases. But when we start a new project and have a choice, we reach for PostgreSQL almost every time. Here is why.
JSONB: Structured and Unstructured in One Database
Modern applications frequently need to store semi-structured data alongside relational data. User preferences, API responses, audit logs, configuration objects -- these do not fit neatly into rigid table schemas.
PostgreSQL's jsonb type handles this elegantly. You can store JSON documents, query nested fields, create indexes on specific JSON paths, and combine JSON queries with standard SQL joins. All in one database, one transaction, one backup.
MySQL has JSON support, but PostgreSQL's implementation is more mature, better indexed, and more deeply integrated with the query planner.
pgvector: AI and Similarity Search
This is increasingly a deciding factor. If your application uses embeddings for semantic search, recommendation, or AI features, pgvector lets you store and query vector embeddings directly in PostgreSQL.
We use this extensively in our facial recognition and intelligent search systems. Face embeddings are stored as vectors, and cosine similarity search runs directly in SQL. No separate vector database needed, no synchronization complexity, no additional infrastructure to manage.
For many AI-powered applications, pgvector means you can build the entire system on a single database.
Advanced Indexing
PostgreSQL offers indexing options that MySQL simply does not match:
- GiST indexes for full-text search, geometric data, and range types
- GIN indexes for JSONB fields, arrays, and full-text search
- BRIN indexes for large, naturally ordered tables (time-series data, logs)
- Partial indexes that only index rows matching a condition, saving space and improving performance
These are not theoretical advantages. In production, the right index type can turn a 3-second query into a 3-millisecond query.
Full-Text Search Without Elasticsearch
PostgreSQL has built-in full-text search with tsvector and tsquery. For many applications, this eliminates the need for a separate search engine like Elasticsearch.
You get stemming, ranking, highlighting, and phrase matching directly in SQL. Combined with GIN indexes, full-text search in PostgreSQL is fast enough for most applications.
We still use Elasticsearch when the search requirements are complex enough to justify it. But for many projects, PostgreSQL's built-in search saves significant infrastructure complexity.
Better Standards Compliance
PostgreSQL is more strict about SQL standards compliance. This catches bugs earlier and makes queries more portable. MySQL's permissive defaults -- like allowing invalid dates, silently truncating data, or treating empty strings differently from NULL in some contexts -- have caused real production bugs in our experience.
PostgreSQL's strictness is a feature, not a limitation.
Flyway Migrations Work Beautifully
We use Flyway for all database migrations, and it works well with both databases. But PostgreSQL's transactional DDL means that if a migration fails partway through, the entire migration is rolled back cleanly. In MySQL, DDL statements auto-commit, so a failed migration can leave your schema in a partially applied state.
This matters enormously in production. A failed migration on PostgreSQL is a non-event -- just fix and retry. A failed migration on MySQL can require manual cleanup.
When We Still Use MySQL
We are not dogmatic about this. MySQL is the right choice when:
- The project is a WordPress site or uses a framework with strong MySQL optimization
- The team has deep MySQL expertise and the project does not need PostgreSQL-specific features
- You are working with an existing MySQL database and migration is not justified
The Bottom Line
For the type of systems we build -- custom web applications with complex business logic, AI-powered features, JSONB data storage, and high reliability requirements -- PostgreSQL is the better foundation. It gives us more tools, stricter guarantees, and fewer workarounds.
The best database is the one that lets you focus on building your application instead of working around database limitations. For us, that is PostgreSQL.
Need help building something like this?
We build production-grade systems. Let's talk about your project.
Start a Conversation →