decorative image for blog on postgresql vs mariadb
September 9, 2021

PostgreSQL vs. MariaDB: Features, Performance, Use Cases

Databases
Open Source

For companies searching for a new relational database management systems (RDBMS), established open source RDBMS like PostgreSQL and MariaDB will likely be at the top of the list. Each offer their own advantages and disadvantages, so comparing PostgreSQL vs. MariaDB head to head is a worthwhile exercise.

In this blog, we compare Postgres vs MariaDB, with sections that compare data types, performance, scalability, consistency, availability, security, and when to use one option over the other.

PostgreSQL vs. MariaDB

At the surface, PostgreSQL and MariaDB are very similar databases. Both are mature, open source relational database management servers (RDBMS). MariaDB is over a decade old and PostgreSQL is over 22 years old.  PostgreSQL is the more mature of the two offerings, is offered on more platforms, and includes additional APIs and access methods.

 RelatedStructuredReadWrite
PostgreSQL
HeavyModerate
MariaDB
HeavyModerate

From a popularity perspective, PostgreSQL is currently ranked as the 4th most popular database on db-engines.com, with MariaDB the 12th most popular. Among RDBMS, PostgreSQL remains the 4th most popular, with MariaDB as the 8th most popular option.

Read Our Full Guide to Open Source Databases

Get detailed analysis of the top 15 open source database in use today with our Decision Makers Guide to Open Source Databases.

Download for Free

Data Types

PostgreSQL supports the JSON and JSONB data types, whereas MariaDB offers a LONGTEXT column to offer similar functionality. This enables both databases to store unstructured data typical with a NoSQL database.

MariaDB is more forgiving and autocorrects data types that do not match the schema being used for inserts and updates while PostgreSQL offers no such mechanism and is strictly typed.

Performance

MariaDB is a lighter database than PostgreSQL which allows a smaller memory footprint. PostgreSQL outperforms MariaDB in regard to reads and writes and is therefore more efficient.

MariaDB is more suitable for smaller databases, and is also capable of storing data entirely in-memory — something not offered by PostgreSQL. PostgreSQL uses an internal cache and the server’s page cache for retrieving frequently accessed data, which helps it to perform better than MariaDB’s query cache.

Scalability

MariaDB supports sharding via the Spider storage engine and Galera Cluster, while PostgreSQL does not offer horizontal partitioning of tables across multiple servers. MariaDB offers the ability to store less frequently accessed data in a separate partition which can speed up queries. PostgreSQL does scale well vertically, but it does not scale horizontally as well as MariaDB.

Consistency and Availability

The replication strategies between PostgreSQL and MariaDB are notably different. Both MariaDB and PostgreSQL focus on consistency and availability and can be deployed on multiple nodes.

PostgreSQL only supports master-slave replication, while MariaDB supports both asynchronous master-slave and master-master replication. PostgreSQL offers cascading replication, streaming replication, and synchronous replication. This means there are several options depending on your high availability requirements.

Security

MariaDB has frequent security patches, which is an indication that the community addresses security very seriously. Similarly, the PostgreSQL Global Development Group (PGDG) publishes a list of active Common Vulnerabilities and Exposures (CVEs) which is addressed by a large and vibrant community. It is imperative to keep open-source software up to date with the latest patches and releases. The ability to apply these patches in a short time frame is key.

When to Use PostgreSQL Over MariaDB

PostgreSQL has advanced features such as materialized views and partial indexes which enhances performance. Materialized views can be used for expensive joins and aggregation that are frequently performed.

Traditional indexes must be created for all the records for a table which can be expensive to create and maintain, but PostgreSQL allows an index for a subset of the data which is called a partial index. Partial indexes are useful for recently inserted or frequently queried data.

When to Use MariaDB Over PostgreSQL

MariaDB allows data type flexibility when it comes to insertions and updates where it converts the data to the correct type. This can be advantageous, but more care is required by the application to make sure the data conforms to the schema. MariaDB’s support of master-master replication is great for applications that require high availability and low latency.

Final Thoughts

There are advantages and disadvantages to both MariaDB and PostgreSQL. Ultimately, choosing the right database for your system requires careful consideration of the needs of your system and a full understanding of how a given database can fulfill those needs. That's not taking into account the need for organizational expertise with that database, the organizational capacity to implement or migrate to the database, or the ability to support that database if something goes wrong.

Get Support for Your Open Source Data Stack

From PostgreSQL to Apache Spark, OpenLogic supports the top open source data technologies used today. To learn more about how we can support your open source data technologies, visit our database solutions page, or talk with an expert today.

Talk to an Expert

Additional Resources