If you are starting a new web app, you will almost certainly end up choosing between PostgreSQL and MySQL. Both are mature, free, open source and run some of the largest sites on the internet. Neither is a wrong answer for a typical app.
The differences matter at the edges: the data types you need, the extensions you want, what your framework expects and what your team already knows. This guide walks through those differences plainly, without picking a winner for everyone.
By the end you will know which one fits your project, how each connection string looks, and the mistakes that cause trouble months after launch.
The short version
PostgreSQL leans towards strictness and features: rich data types, a large extension ecosystem and close adherence to the SQL standard. MySQL leans towards simplicity and ubiquity: it is the default for a huge amount of PHP software, it is widely understood by hosting teams, and it is quick for straightforward read-heavy workloads.
Both handle transactions, foreign keys, JSON, full-text search, window functions and common table expressions (MySQL gained the last two in version 8.0). For a typical CRUD app with a few dozen tables, you will not hit a limit in either.
Data types and JSON
This is where PostgreSQL stands out most.
- JSONB: PostgreSQL stores JSON in a binary, indexable format. A GIN index lets you query inside documents efficiently.
- Arrays: a column can hold an array of integers or text, with operators to search inside it.
- Other types: ranges (for bookings and time windows),
uuid,inetfor IP addresses, and user-defined enum and composite types.
MySQL has a JSON column type with validation and functions, and you can index specific paths through generated columns or functional indexes. It works well, but querying deep inside documents is less flexible.
Here is the same idea in both. PostgreSQL:
CREATE TABLE events (
id bigserial PRIMARY KEY,
payload jsonb NOT NULL
);
CREATE INDEX events_payload_idx ON events USING GIN (payload);
SELECT id FROM events WHERE payload @> '{"type": "signup"}';MySQL:
CREATE TABLE events (
id BIGINT AUTO_INCREMENT PRIMARY KEY,
payload JSON NOT NULL
);
SELECT id FROM events WHERE payload->>'$.type' = 'signup';Standards and strictness
PostgreSQL follows the SQL standard closely and rejects bad data rather than guessing. Inserting text into an integer column fails loudly.
MySQL has historically been more forgiving, but strict mode has been on by default since 5.7, which closes most of the old surprises. Two differences still catch people out:
- Case sensitivity: with MySQL's default collations, string comparisons ignore case, so
'Alice' = 'alice'is true. In PostgreSQL it is false unless you useILIKE,lower()or thecitextextension. - Character sets: in MySQL, always use
utf8mb4. The olderutf8alias only stores up to three bytes per character and cannot hold emoji or some scripts. MySQL 8.0 usesutf8mb4by default.
Concurrency in general terms
Both databases use MVCC (multi-version concurrency control). Readers see a consistent snapshot and do not block writers, and writers do not block readers. For most apps this means you rarely think about locking.
The implementations differ. PostgreSQL keeps old row versions in the table itself and cleans them up with a background process called autovacuum. On busy tables that update constantly, autovacuum needs to keep up, or tables grow and slow down. MySQL's InnoDB engine keeps old versions in a separate undo log, so cleanup works differently.
Default isolation levels also differ: PostgreSQL uses Read Committed, InnoDB uses Repeatable Read. Most frameworks work fine with either, but be aware of it if you write code that relies on exact transaction behaviour.
One practical point: PostgreSQL starts a separate process per connection, which makes each connection relatively heavy. Apps with many workers often put a connection pooler such as PgBouncer in front, or keep the pool size in the app small. MySQL uses threads and copes with more idle connections, though pooling is still good practice.
Extensions
PostgreSQL's extension system is a genuine advantage:
- PostGIS adds geographic types, spatial indexes and hundreds of geo functions. It is the standard choice for mapping and location work.
- pgvector stores embeddings and runs similarity search, which is useful for AI features such as semantic search and retrieval.
- pg_trgm gives fuzzy text matching, and citext gives case-insensitive text.
MySQL has spatial types and functions built in, which cover many location needs. For vector search, the open-source ecosystem has settled more firmly around PostgreSQL and pgvector. Whether a given extension is available depends on where your database runs, so check before you design around one.
Replication and scaling
Both support primary-replica replication out of the box. PostgreSQL offers physical streaming replication (an exact copy of the whole server) and logical replication (selected tables, useful for migrations and upgrades). MySQL replicates from its binary log and also offers Group Replication for multi-node setups.
For most small and medium apps, a single well-sized database server with good backups is enough. See scaling a web application for when replicas start to make sense.
Ecosystem and framework defaults
Your software often decides for you:
- WordPress requires MySQL or MariaDB. Do not try to run it on PostgreSQL.
- Laravel supports MySQL, MariaDB, PostgreSQL and SQLite. MySQL is the traditional default in tutorials, but PostgreSQL works well.
- Django supports PostgreSQL, MySQL, MariaDB, SQLite and Oracle. Its documentation and the
django.contrib.postgresmodule make PostgreSQL a popular pairing. - Rails, Prisma and most Node ORMs support both.
Connection strings for both
Most frameworks and hosts pass the database location as a single URL. The formats look like this:
postgresql://app_user:s3cret@db.example.com:5432/app_db?sslmode=require
mysql://app_user:s3cret@db.example.com:3306/app_dbThe default ports are 5432 for PostgreSQL and 3306 for MySQL. Some tools write the PostgreSQL scheme as postgres://, which most drivers accept. If the password contains characters such as @, : or /, they must be percent-encoded.
Reading the URL in Node.js looks like this:
// PostgreSQL with the pg package
const { Pool } = require('pg');
const pgPool = new Pool({ connectionString: process.env.DATABASE_URL });
// MySQL with the mysql2 package
const mysql = require('mysql2/promise');
const mysqlPool = mysql.createPool({ uri: process.env.DATABASE_URL });On Launchpad you can add a managed PostgreSQL, MySQL or Redis database to an app. Connecting a PostgreSQL or MySQL database adds its connection string to the app as DATABASE_URL, so code like the above works without hard-coding anything.
Choosing: a simple table
| If you need… | Lean towards | Why |
|---|---|---|
| WordPress or most PHP CMSs | MySQL | They are built for MySQL or MariaDB |
| Heavy JSON querying | PostgreSQL | JSONB with GIN indexes |
| Maps, geofencing, spatial queries | PostgreSQL | PostGIS |
| Embeddings and semantic search | PostgreSQL | pgvector is mature and widely used |
| Team already runs MySQL well | MySQL | Familiarity beats small feature gaps |
| Strict data integrity by default | PostgreSQL | Rejects bad data and is case-sensitive |
If none of these rows applies, pick the one your framework's documentation uses and your team knows best.
Step by step: choose and connect a database
- List the software you will run. If WordPress or a MySQL-only package is in the list, the decision is made.
- List the features you need now or soon: JSON querying, geo, vectors. If any apply, choose PostgreSQL.
- Check your framework's supported databases and which one its tutorials use.
- Create the database and copy the connection URL. On Launchpad, connect it to the app and
DATABASE_URLappears in the Variables tab. - Read the URL from the environment in your code, never from a committed file. The environment variables guide covers this in detail.
- Run your migrations and set up backups before real data arrives.
Common mistakes
- Using MySQL's
utf8instead ofutf8mb4. Fix: create databases and tables withutf8mb4and autf8mb4collation. - Relying on case-insensitive matching and then switching to PostgreSQL. Fix: normalise emails and usernames to lower case on write, or use
citext. - Opening a new connection per request in PostgreSQL. Fix: use a pool and keep it modest in size.
- Ignoring autovacuum on very busy tables. Fix: watch table bloat and tune autovacuum for hot tables rather than turning it off.
- Hard-coding the connection string. Fix: read
DATABASE_URLfrom the environment.
Security notes
- Never expose the database port (5432 or 3306) to the public internet. Only the app should reach it.
- Give the app a dedicated user with access to its own database only, not a superuser or
root. - Use TLS for connections that cross a network you do not control.
- Use parameterised queries or your ORM's query builder. String-building SQL invites injection attacks.
- Keep connection strings out of Git and out of logs.
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
ECONNREFUSED or timeout on connect | Wrong host or port, or database not running | Check the URL and that the database service is up |
password authentication failed (PostgreSQL) | Wrong password, or special characters not encoded | Percent-encode the password in the URL |
SQLAlchemy says it can't load the postgres dialect | SQLAlchemy 1.4+ rejects the postgres:// scheme | Rewrite the scheme to postgresql:// before creating the engine |
too many connections | Each worker opens its own large pool | Reduce pool size or add a pooler such as PgBouncer |
Emoji become ???? in MySQL | Table or connection uses utf8 (3-byte) | Convert to utf8mb4 and set the connection charset |
Frequently asked questions
Is PostgreSQL faster than MySQL?
It depends on the workload. MySQL has a reputation for quick simple reads, and PostgreSQL often does better on complex queries and mixed workloads. For a typical app, indexes and query design matter far more than the engine.
Can I switch from MySQL to PostgreSQL later?
Yes, but it is real work. Tools such as pgloader help move data, and you will need to fix SQL that relies on MySQL behaviour such as case-insensitive comparisons. Choosing carefully at the start is cheaper.
Should I use MariaDB instead of MySQL?
MariaDB works well for most software that supports MySQL, including WordPress. Check your framework's documentation, since a few newer features differ between them.
Do I need Redis as well?
Not always. Redis is an in-memory store for caches, sessions and queues, not a replacement for your main database. Add it when you have a specific need such as background jobs.
Next steps
Both databases will serve a typical app well for years. Choose based on your software's requirements and the features you genuinely need, then spend your energy on indexes, backups and sensible connection handling.
- Deploy a Python FastAPI app with PostgreSQL
- Deploy a Laravel app from GitHub
- Backups and disaster recovery for small teams
- Back up and restore on Launchpad
- Add a managed PostgreSQL or MySQL database to your app on Launchpad




