MariaDB or PostgreSQL for a PHP application?
4 min read
Both are good databases. The choice is usually made by your application before you think about it. When the app decides, when you are free to choose, what really differs in daily work, and what both need from the server.
This question starts long discussions, and most of them miss the practical answer: for most PHP projects the application has already chosen. WordPress does not run on PostgreSQL. If you write your own application, you are free, and then the differences below matter.
Ubuntu 26.04 ships MariaDB 11.8, MySQL 8.4 and PostgreSQL 18, so both families are current on a new server.
In short
- WordPress, WooCommerce, PrestaShop, Joomla, Magento: MariaDB or MySQL. No choice to make.
- Laravel, Symfony, your own code: both work. Choose PostgreSQL unless you have a reason not to.
- Moodle, Nextcloud, Drupal: support both; follow the project's recommendation and your own experience.
- PostgreSQL is stricter and richer. MariaDB is more forgiving and is what most PHP hosting knowledge assumes.
- Running both on one small server costs memory twice. Pick one if you can.
When the application decides
| Application | Database |
|---|---|
| WordPress, WooCommerce | MariaDB / MySQL only |
| PrestaShop | MariaDB / MySQL only |
| Joomla | MariaDB / MySQL, PostgreSQL supported |
| Magento / Adobe Commerce | MariaDB / MySQL only |
| Drupal | both |
| Moodle | both |
| Nextcloud | both |
| Laravel, Symfony | both, plus SQLite |
For the first group, the plugins and themes are written against MySQL's dialect. There is nothing to compare.
When you are free to choose
Strictness. PostgreSQL refuses data that does not fit: a too-long string, an invalid date, text in a number column. MariaDB in its default mode is also strict today, but many older applications turn that off and rely on silent conversion. If you want the database to catch mistakes, PostgreSQL gives you less room to make them.
Data types. PostgreSQL has real booleans, arrays, ranges, UUIDs, network addresses, and jsonb with indexes that make JSON columns as fast to search as ordinary ones. MariaDB's JSON is text with validation and functions.
Queries. Both have window functions and common table expressions today. PostgreSQL goes further: partial indexes, expression indexes, RETURNING on every write, full-text search good enough to postpone a search engine, and extensions such as PostGIS and pgvector.
Schema changes. In PostgreSQL most ALTER TABLE statements run inside a transaction: a failed migration rolls back completely. In MariaDB a migration that fails halfway leaves the first half applied.
Concurrency. PostgreSQL's model handles many writers and long reports at the same time without them blocking each other. It pays for that with VACUUM, which normally runs by itself.
Simplicity of operations. MariaDB is what shared hosting ran for twenty years. Tools, tutorials and people who know it are everywhere. Replication is easy to set up. For a simple site this familiarity is worth something.
Connections. A PostgreSQL connection is a process and costs more memory than a MariaDB thread. PHP opens a connection per request, so with PostgreSQL keep max_connections modest and add PgBouncer when traffic grows.
What both need from the server
- Memory for the cache.
innodb_buffer_pool_sizefor MariaDB,shared_buffersfor PostgreSQL. The defaults are 128 MB for both, which is too small for anything real. - Listen locally. Both listen on
127.0.0.1by default on Ubuntu. Keep it that way; see How to check open ports. - Backups that are dumps, not copies of the data directory while the server runs:
mariadb-dump --single-transactionorpg_dump. - A tested restore. See A backup you have not restored is not a backup.
Upgrading the server
Coming from Ubuntu 24.04, both make a large step: MariaDB 10.11 to 11.8, PostgreSQL 16 to 18. PostgreSQL installs the new version next to the old one and waits for pg_upgradecluster; MariaDB upgrades in place. Take a dump before either. See Upgrading Ubuntu 24.04 to 26.04 with PHP sites.
Both on one server?
It works, and sometimes you must: WordPress next to a Laravel application on PostgreSQL. But each database wants its own cache, so on a 2 GB server both get too little. If a new project is free to choose and the server already runs one of them for another site, using the same one is a reasonable argument.
Our recommendation
- The application names a database: use it.
- A new Laravel or Symfony project: PostgreSQL. You get stricter data, transactional migrations and room to grow into JSON, search and geodata without another service.
- A team that knows MariaDB well and a plain CRUD application: MariaDB is fine. A database you understand beats a better one you do not.
With Zefily
Zefily installs MariaDB and PostgreSQL on your servers and manages databases and their users from the panel, including copying a database to another server. One-click apps get the database they need: WordPress and PrestaShop on MariaDB, the Next.js starter stack with PostgreSQL. Autotune sizes the database's memory for the server. See Databases.
Frequently asked questions
Does WordPress work with PostgreSQL?
No. WordPress and its plugins are written for MySQL and MariaDB.
Is PostgreSQL faster than MariaDB?
Neither is faster in general. For simple reads and writes they are close; PostgreSQL usually does better with complex queries and many concurrent writers. Indexes and memory settings matter more than the choice.
Which database should I use for Laravel?
Both are fully supported. For a new project PostgreSQL is a good default: stricter data handling, transactional schema changes and jsonb.
Can I run MariaDB and PostgreSQL on the same server?
Yes, but each needs memory for its own cache. On a small server it is better to use one.
Which versions does Ubuntu 26.04 have?
MariaDB 11.8, MySQL 8.4 and PostgreSQL 18 in its archive.
See Tuning PostgreSQL 18 on a small server for the settings to change first.