Skip to content

Technology · 11 min read

PostgreSQL vs MySQL: How to Choose a Database

How to choose between PostgreSQL and MySQL by workload: JSON, search, replicas, tenancy and hosting, and what breaks if you migrate later.

Abidhusain ChidiFounder and CEO

PostgreSQL vs MySQL drawn as a chalk balance scale with a postgres database in one pan and a mysql database in the other

Key takeaways

  • Choose by workload: PostgreSQL for reporting, JSON attributes and multi-tenant SaaS, MySQL for stable read-heavy apps and WordPress.
  • PostgreSQL can enforce tenant isolation with row security policies; on MySQL the tenant filter has to live in the application.
  • Both engines replicate asynchronously by default, so send read-after-write requests to the primary on either one.
  • MySQL commits the open transaction on DDL, so write MySQL migrations as single steps that can each be reversed alone.
  • A move from MySQL to PostgreSQL costs rewritten SQL, views and triggers far more than copying the data.
  • A working, well-indexed MySQL application with no missing feature should be tuned, not migrated.

PostgreSQL vs MySQL is best settled by workload: PostgreSQL for reporting, JSON data and multi-tenant SaaS, MySQL for stable, read-heavy PHP apps. PostgreSQL and MySQL are both free, mature and fast enough for almost anything a product team builds. The differences that matter sit in the features you lean on in year two, and in the price of changing course once the data is in.

PostgreSQL vs MySQL drawn as a chalk balance scale with a postgres database in one pan and a mysql database in the other

We run both in production. Three of our five published case studies sit on MySQL: Bloomford’s recruitment platform, the Plugin tennis club’s bookings and payments, and the Snappy Stats scheduling app. Another, CyberFind, is a peer-review platform for security buyers built on Next.js, Node.js and PostgreSQL. Our PostgreSQL development services usually put the database behind a Node.js or NestJS API, while most of our MySQL work runs under PHP and Laravel. The sections below work through PostgreSQL vs MySQL for a team choosing today.

Versions matter in any database comparison. We checked every documentation page linked below on 25 November 2026, against PostgreSQL 19, which shipped on 19 November 2026, and the MySQL 9.7 reference manual.

PostgreSQL vs MySQL at a glance

The table lists only the differences that change a design decision. Everything else, from foreign keys to indexes and transactions, works well in both.

AreaPostgreSQLMySQL
JSONjsonb, with GIN indexes on any keyJSON type, indexed through a generated column
Full-text searchtsvector and tsquery types, ranked resultsFULLTEXT indexes, MATCH() AGAINST()
Window functionsYesYes
Schema changes in a transactionYes, with a few exceptionsNo: DDL commits the open transaction
ReplicationStreaming to standbys, plus logical; asynchronous by defaultSource to replicas; asynchronous by default
Automatic failoverNeeds separate softwareGroup Replication elects a new primary
Tenant rules in the databaseRow security policiesNo row security statement
NamespacesDatabase, then schema, then tableA schema is a database
LicencePostgreSQL License, similar to BSD or MITCommunity edition under GPLv2

Neither column is a verdict. A booking app on Laravel gains nothing from row security it will never switch on. A SaaS product that keeps every customer’s records in shared tables, on the other hand, gains a great deal.

Where PostgreSQL and MySQL differ in practice

JSON columns

Both engines have a native JSON type, so the real question is how you query it. PostgreSQL’s jsonb stores a parsed binary form, and one GIN index can then search for keys or key/value pairs across a large number of documents. MySQL does not index a JSON column directly. Instead, you add a generated column that extracts one value and index that, or use a multi-valued index on an array.

In practice, the MySQL route is fine when you know in advance which two or three fields you filter on. When customers can attach any attribute to a record and expect to find records by it, PostgreSQL covers that with a single index rather than a new column for every field.

PostgreSQL has text search built in, with a tsvector type for prepared documents, a tsquery type for queries and sorting by relevance. MySQL offers FULLTEXT indexes on InnoDB or MyISAM tables, for CHAR, VARCHAR and TEXT columns. You query them with MATCH() AGAINST() in natural language, boolean or query expansion mode.

Either one handles search across a product catalogue, a help centre or a candidate database. Once search becomes the product, with facets and typo tolerance, a dedicated search engine usually sits next to the database, whichever engine that is.

Window functions and reporting SQL

Both PostgreSQL and MySQL support window functions, which compute a value for each row from the rows related to it: running totals, rank within a group, change against the previous month. PostgreSQL still goes further in two places that reporting work touches. First, it accepts INSERT, UPDATE, DELETE and MERGE inside a WITH clause, so a multi-step data fix can be one statement. Second, it has materialised views, which store a query’s result until you refresh it. MySQL 9.7’s list of data definition statements has no materialised view, so on MySQL the usual substitute is a summary table refreshed on a schedule.

Replication and read replicas

Both engines replicate asynchronously by default. PostgreSQL streams its write-ahead log to standby servers, and it also offers logical replication on a publish and subscribe model. MySQL copies changes from a source to replicas, which do not need to stay connected. Asynchronous means a replica can run a moment behind. A user who saves a form and then reloads it from a replica may see the old value. For that reason, send read-after-write requests to the primary and let replicas take reports and searches.

Failover is where they part ways. PostgreSQL does not provide the software that spots a failed primary and tells a standby to take over, so a self-hosted cluster needs a separate tool for it. MySQL’s Group Replication, in single-primary mode, elects a new primary automatically. That gap is one of the main reasons to look at managed hosting, below.

Schema changes and failed migrations

PostgreSQL runs most schema changes inside a transaction, so a migration that fails halfway rolls back as a whole. The exception to know is CREATE INDEX CONCURRENTLY, which cannot run in a transaction block. In MySQL, CREATE TABLE, ALTER TABLE, CREATE INDEX and most other DDL statements end any open transaction as if you had committed it. As a result, a three-step migration that fails on step two leaves step one applied. On MySQL, therefore, write each migration as one change that can be reversed on its own.

PostgreSQL vs MySQL performance by workload

Published benchmarks rarely settle PostgreSQL vs MySQL. A missing index usually matters more than the choice of engine. A test tuned for one engine also says little about your schema, so test on a copy of your own data. What follows is how each engine behaves under three common workloads.

Read-heavy web apps

Booking screens, member portals and content sites mostly read rows by key and write a little. Either engine serves that well once the indexes match the queries, and both can push read traffic to replicas. Here MySQL is often the sensible pick, because the team and the hosting already assume it. WordPress, for one, recommends MySQL 8.4 or MariaDB 10.11 or later, so a WordPress build has already made its choice.

Write-heavy tables

The two engines keep old row versions in different places, and it shows on tables that change all day, such as stock levels, counters or job queues. In PostgreSQL, an UPDATE or DELETE does not immediately remove the old version of the row. VACUUM reclaims the space later, and for many installations the autovacuum daemon does that without help. A very hot table, however, needs its autovacuum settings tuned and watched. MySQL’s InnoDB engine keeps old versions in undo tablespaces rather than in the table itself.

Connections differ too. PostgreSQL starts a new process for each connection, so a busy API needs a pooler such as pgBouncer in front of it from the first release. Neither point is a reason to avoid an engine. Each just asks for a different kind of care, and the team running it should know which kind it signed up for.

Reporting and analytics

Reporting leans towards PostgreSQL. Its planner can use several CPUs to answer one query, and a materialised view lets a dashboard read a stored result instead of recomputing it on every load. On MySQL, summary tables refreshed by a scheduled job reach the same end. On either engine, month-end reports and large exports belong on a read replica, so they never compete with the tables taking orders.

Managed hosting for PostgreSQL and MySQL

Amazon, Google and Microsoft each run both engines as a managed service, so hosting rarely decides PostgreSQL vs MySQL for you. We checked each provider’s own page on 25 November 2026.

ServicePostgreSQLMySQLWorth knowing
Amazon RDSYesYesAurora, an RDS option, is compatible with both
Google Cloud SQLYesYesAlso runs SQL Server
Azure DatabaseYesYesA separate service for each engine
SupabaseYesNoEach project is a dedicated Postgres database, with access rules built on row security
PlanetScaleYesYesShards MySQL through Vitess for data that outgrows one server

Two things matter more than the provider’s name. The first is read replicas. Amazon RDS, for example, builds them with each engine’s own replication and copies updates to them asynchronously, so the replica lag described above applies on managed hosting as well. The second is the bill. Our guide to choosing a SaaS tech stack sets the managed premium against self-hosting, with dated prices, and the same reasoning applies to either engine.

Multi-tenant SaaS schemas in PostgreSQL and MySQL

A SaaS product keeps many customers’ data in one system, and there are three ways to keep them apart: shared tables with a tenant ID on every row, a schema per tenant, or a database per tenant. The same SaaS guide explains why that choice is so hard to undo. What it leaves out is the PostgreSQL vs MySQL side: how differently the two engines support each pattern.

Shared tables with row security

With shared tables, the risk is one query that leaves out the tenant condition. PostgreSQL can enforce that condition itself. Switch on row security for a table, write a policy, and every query sees only the rows the policy allows. If row security is enabled and no policy exists yet, the default is to deny, so nothing is visible. Superusers always bypass the policies, though, and table owners normally do too. The application’s database login should therefore be a plain role that owns none of the tables.

MySQL has no row security statement among its data definition statements. On MySQL the tenant filter lives in the application instead, usually as a global scope in the ORM, backed by code review and tests that try to read another tenant’s rows. That works with discipline. Still, one missed WHERE clause then returns another customer’s data rather than an empty result.

A schema or a database per tenant

In PostgreSQL, a database contains named schemas, which in turn hold tables. So each tenant can have its own schema while all of them share one database, one connection pool and one backup, and a privileged role can still report across tenants. In MySQL, CREATE SCHEMA is a synonym for CREATE DATABASE, which makes a schema per tenant and a database per tenant the same design there.

PostgreSQL vs MySQL object levels: in PostgreSQL a schema sits inside a database, while in MySQL a schema is a database
PostgreSQL has a schema level inside each database; in MySQL the two words name the same thing

Either way, each schema change runs once for every tenant, so deploy time grows with the customer count. On our PostgreSQL projects we settle row security or a schema per tenant at the start, because moving between them later means touching every query.

Moving from MySQL to PostgreSQL: what breaks

Copying the data is the easy part. pgloader reads a live MySQL database and creates the tables, indexes and foreign keys in PostgreSQL. By default it also lowercases identifiers and resets each sequence to the highest ID loaded. What breaks is the code that quietly relied on how MySQL behaves:

  • Case-insensitive matching. MySQL’s default collation, utf8mb4_0900_ai_ci, compares strings without regard to case. PostgreSQL’s standard collations are deterministic and treat two strings as equal only when their bytes match, so a login lookup on an email address can stop matching. Lower-case the address on write, or compare and index on lower(email).
  • Quoted names. MySQL quotes identifiers with backticks. PostgreSQL uses double quotes and folds unquoted names to lower case, so raw SQL with backticks fails. So does any query that quotes a mixed-case column name once pgloader has lowercased it.
  • Upserts. ON DUPLICATE KEY UPDATE becomes ON CONFLICT DO UPDATE, which must name the column or constraint it conflicts on.
  • Booleans. pgloader turns a tinyint(1) column into a real boolean, so code that compares it with 1 or 0 needs checking.
  • Views and triggers. pgloader migrates neither. Each one is rewritten and tested by hand.
  • Search queries. Every MATCH() AGAINST() query and its FULLTEXT index becomes a tsvector column, a GIN index and a new query.

What a later migration costs

The cost follows how much SQL the application writes by hand, not the size of the data. An application that talks to the database only through an ORM, Prisma for example, mostly needs its queries tested again. One full of raw queries, stored procedures and triggers needs each of them rewritten, then tested against production-shaped data. After that comes the cutover: a staged switch with a rollback plan, which is the pre-launch step in our own PostgreSQL process. The SaaS guide rates a change of engine as very high effort, measured in months. In short, choosing well now is far cheaper than moving later.

MySQL to PostgreSQL migration: pgloader moves tables, indexes, foreign keys and sequences, while views, triggers and MySQL specific SQL are rewritten by hand
The data moves with a tool; the SQL that relied on MySQL behaviour is rewritten and tested by hand

Choosing PostgreSQL or MySQL for a new project

For a new product, answer PostgreSQL vs MySQL from what the data must do in year two, then check that against the team who will run it.

  • Choose PostgreSQL for multi-tenant SaaS, reporting-heavy products, records with flexible JSON attributes, location search with PostGIS, and any system where the database should refuse bad data instead of trusting the application.
  • Choose MySQL for WordPress, for a team that already runs MySQL well, and for a stable data model with simple reads and writes, such as bookings, memberships or HR records.

Who should not switch

If your MySQL application works, is indexed properly and lacks no feature you need, do not migrate it. Upgrade MySQL, fix the slow queries and spend the budget on the product. Likewise, a small team that will self-host, with nobody to watch autovacuum and connection pooling, should not pick PostgreSQL by default. It should put PostgreSQL on a managed service or stay with the engine it knows. And nobody should choose either one from a benchmark chart.

A move makes sense when it rides on a rebuild that is happening anyway, or when one missing feature, such as row security, would cost more to work around than to migrate. For a MySQL database that is slow rather than wrong, our MySQL tuning work starts with a written performance report within a week, and that is often the cheaper fix.

TagsArchitecturebackendPostgreSQLSaaS DevelopmentTech Stack

Written by

Abidhusain Chidi

Founder and CEO

Founder of QalbIT Infotech and the engineer who still scopes most of its projects. Writes about what custom software really costs, how build-versus-buy decisions play out two years in, and the delivery habits that keep a product shipping, drawn from CRM, ERP, SaaS and MVP work Abid has been building since 2014 and the products QalbIT runs itself today.

FAQ


Frequently asked questions

Not in general. For most web workloads the indexes and the schema decide speed far more than the engine does. PostgreSQL brings more tools for heavy reporting, such as parallel query and materialised views, while MySQL serves simple, read-heavy apps well. Test on a copy of your own data rather than trusting a published benchmark.
PostgreSQL, in most cases. Row security lets the database enforce tenant isolation, schemas let tenants share one database, and jsonb handles flexible customer attributes with a single index. MySQL is still a sound choice if your team already runs it well and the data model is simple.
Yes. A tool such as pgloader copies the tables, indexes, foreign keys and data, and resets sequences. The work is in the application: case-insensitive comparisons, backtick quoting, ON DUPLICATE KEY UPDATE, views, triggers and full-text queries all need rewriting and testing, so plan it as a project with a rollback.
PostgreSQL. Its jsonb type takes a GIN index that finds keys or key/value pairs across many documents. MySQL stores JSON natively too, but you index it through a generated column for each field, which suits a fixed set of filters better than open-ended ones.
Yes. Amazon RDS, Google Cloud SQL and Azure run both engines as managed services. Supabase is PostgreSQL only, and PlanetScale offers both, with Vitess for sharding MySQL. We checked each provider's own page on 25 November 2026.
MySQL or MariaDB. WordPress recommends MySQL 8.4 or MariaDB 10.11 or later on its requirements page, so a WordPress build has already made the choice for you.
Yes, for many applications. Booking, membership and HR systems with a stable data model run well on MySQL with the right indexes and tested backups, and three of our five published case studies use it. Choose PostgreSQL when you need row security, rich JSON indexing or heavy reporting. See our MySQL development work.

Newsletter

Join 1,000+ smart readers

One email a month on building software that ships. Unsubscribe anytime.

Next step


Want the same clarity for your product?

A short call. A written range. No obligation.