Spencer Nguyen - January 19, 2021
PostgreSQL and MySQL game

Although the differences between MySQL and PostgreSQL lessen with each passing year, both database systems continue to offer distinct advantages for different use cases. In this guide, we’ll take a detailed look at the characteristics of PostgreSQL vs. MySQL – and why you might choose one DBMS over the other. In particular, we’ll discuss the following:

Quick Comparison of PostgreSQL vs. MySQL
Overview of PostgreSQL
Overview of MySQL
Ask These Questions to Decide Between PostgreSQL and MySQL
Final Thoughts on PostgreSQL vs. MySQL

Did you know you can generate a full-featured, documented, and secure REST API in minutes using DreamFactory? Sign up for our free 14 day hosted trial to learn how! Our guided tour will show you how to create an API using an example MySQL database provided to you as part of the trial!

Create Your PostgreSQL and MySQL APIs Now

Quick Comparison of PostgreSQL vs. MySQL

Use this quick comparison of PostgreSQL vs. MySQL to get a sense of their differences:

  • MySQL: MySQL has fewer features than PostgreSQL, but this allows MySQL to focus on system stability and processing speed – particularly for read-only queries. MySQL has a reputation for being the best solution for websites and conducting online transactions. The system is also compatible with a wide variety of pluggable data storage engines.
  • PostgreSQL: PostgreSQL offers more features and extensibility than MySQL. PostgreSQL was designed to offer MVCC (concurrent transactions) and ACID compliance from the ground up. It is compatible with the broadest range of NoSQL formats and has a reputation for being the best solution for managing complex analytical processes on large data sets. It’s particularly good at processing concurrent read-write operations. 

It’s also important to note the similarities between PostgreSQL vs. MySQL, which are growing with each subsequent release. For example, MySQL now offers certain features that were once unique to PostgreSQL, such as:

  • JSON Compatibility
  • Common Table Expression (CTE) 
  • Geographic Information System (GIS) and Spatial Reference System (SRS) 
  • Multi-Version Concurrency Control (MVCC) 
  • Window Functions 

Similarly, PostgreSQL offers specific features that were formerly unique to MySQL, such as:

  • Logical Replication 
  • Declarative Partitioning 
  • Semi-Synchronous Replication 

Now, let’s look at both database systems in more detail.

Overview of PostgreSQL

PostgreSQL is a highly-extensible database management system that offers more features than MySQL and other DBMSs. As an object-relational database management system (ORDBMS), PostgreSQL has native NoSQL support for JSON, XML, key-value pairs with HSTORE, and it allows indexing of JSON data for faster access. This makes PostgreSQL a popular choice when dealing with data that doesn’t fit into a relational format.

Compared to MySQL, PostgreSQL is better at processing complex, high-volume operations and managing unusual database scenarios. Due to its catalog-driven operation, PostgreSQL allows you to define your data types, functional languages, and index types. So you’re not limited to storing information in tables and columns. PostgreSQL also includes advanced MVCC capabilities that allow for greater efficiency when processing concurrent read-write operations.

Here’s a complete overview of the features and characteristics of PostgreSQL:

  • Free and open-source: PostgreSQL features a liberal open-source license that lets you freely use, modify, and distribute PostgreSQL how you wish. 
  • ORDBMS, not RDBMS: PostgreSQL is an object-relational database management system PostgreSQL, which can manage both object-oriented and relational data. Therefore, your data does not have to match with traditional relational structures.
  • Extensible and customizable with many different languages: Users can extend PostgreSQL to suit their needs by developing custom plugins. Users have a lot of freedom to code custom functions for PostgreSQL using various languages like, SQL, C, C++, Go, pgSQL, Python, Perl, and Tcl. Additionally, open-source projects offer support languages like Java, Lua, R, and more.
  • MVCC Features: PostgreSQL was the first database management system to offer multi-version concurrency control (MVCC) capabilities. 
  • Mature, responsive community: PostgreSQL boasts a large community of volunteers and developers (PostgreSQL Global Development Group) who maintain and update PostgreSQL. The same community provides support to fellow PostgreSQL users. Paid, third-party support is also available. 
  • Two-Times Database of the Year Award Winner: PostgreSQL won the DB-Engines Database of the Year Award two years in a row in the 2017 and 2018.
  • SQL ISO/IEC 9075 Standard: PostgreSQL fulfills 150 of the 164 mandatory features required for full compliance to the standard.
  • User-Defined Types: one can extend PostgreSQL to support new data types. You can define new base types, which are data types defined below the SQL language level. To create a new base type, one must implement functions to operate on the type in a low-level language, i.e., C.
  • Strong performance metrics from ongoing feature additions and enhancements such as on the fly, data compression results in less IO work required for reading, and an asynchronous API for use by client applications boost performance.
  • PostgreSQL uses access control lists (ACL) for user permissions for databases, schemas, and tables. It also supports full-disk, file-based, table-level, column-level, and instance-level encryption for data at rest. The pgcrypto software is a popular add-on package included with the PostgreSQL source code distribution. And of course, for data in flight, there is native support for SSL connections for the encryption of client/server communications for robust security.
  • Migration safeguards: if there is a failure while applying modifications to one’s database, the entire modification gets rolled back to the origin point (where you started). In MySQL, it fails silently, and the error is sometimes not picked up until deployment.

One of the most common ways users interact with a PostgreSQL database is through the free PostgreSQL administration tool, pgAdmin. Here’s how it looks:

Here’s how one user summarizes PostgreSQL on G2Crowd:

“PostgreSQL is one of the most stable and functionally rich open-source RDBMS. It performs well while implementing complex queries. It is also convenient to shift your database architecture into PostgreSQL. Because of its ubiquity, you can find solutions to any issue you might face in the online community. PostgreSQL is offering an amazing amount of functionality for any database, let alone an open-source project. And in almost every case, the current functionality is just the first part of a long-term roadmap that the developers will continue to follow…”

“The business problem that I am solving with PostgreSQL was to query data for further processing. I worked on generating intelligent reports with data from an Alfresco Architecture whose data resided in a PostgreSQL database. The benefits I observed were, it was free to use, and the queries functioned perfectly.”

Overview of MySQL

MySQL is a relational database management system (RDBMS) with a reputation for speed, reliability, and general-purpose functionality. It is also the most popular database globally and the most common database used for dynamic websites and web applications.

According to ScaleGrid, 39% of developers are currently using MySQL for their projects, making it the most popular DBMS globally. This popularity is primarily due to several factors: (1) MySQL is easy to use and learn compared to other DBMS systems; (2) some of the largest content management platforms on the internet — like WordPress, Joomla, and Drupal — use MySQL for data management; (3) many cloud-service providers offer free or inexpensive MySQL hosting as well; and (4) it represents the “M” in the LAMP stack (Linux, Apache HTTP Server, MySQL, PHP), so it’s readily available to web app developers. 

Here’s a complete overview of the features and characteristics of MySQL:

  • Free and open-source: MySQL is open-source software that anyone is free to use under the GNU General Public License.
  • Oracle owned and maintained: Oracle has owned and maintained MySQL since acquiring Sun Microsystems in 2010. 
  • Regularly updated: MySQL developers update MySQL with needed security upgrades and new features regularly. MySQL 8.0.21 is the most recent version at the time of this writing, released on July 13, 2020.
  • Mature, responsive community: MySQL boasts a large community of highly responsive volunteers who help users troubleshoot and resolve problems. 
  • MySQL provides comprehensive support for application developers. For example, stored procedures, triggers, functions, views, cursors, ANSI-standard SQL, and more. For embedded applications, plug-in libraries are available to embed MySQL database support within most applications. MySQL also provides connectors and drivers (ODBC, JDBC, etc.). Almost every paradigm and language has support for MySQL and vice versa.
  • MySQL is known for high-speed transaction processing, utilizing techniques such as caching and database indexes, which accelerates SELECT query statements’ performance for large data loads. To enhance performance, MySQL 8 has included indexes in performance schema to speed up data retrieval.
  • Reputation for reliability and stability: Database admins describe MySQL as a stable and reliable system, as this user notes, “…MySQL has been battle-tested for a long time. Any issues are known issues, and we pretty much don’t have any problems in production. So it’s very stable.”
  • ACID-compliant: MySQL is ACID-compliant for those using the InnoDB and NDB Cluster storage engines. 
  • Multi-Version Concurrency Control (MVCC) through InnoDB: Once the domain of PostgreSQL only, MySQL now offers MVCC when using the InnoDB storage engine. MVCC is “a database design theory that enables relational databases to support concurrency, or more simply, multiple user access to common data in your database.”
  • It’s worth noting that Uber migrated to MySQL from Postgresql. The following are some of the reasons. PostgreSQL needs to update all indexes on a table when updating rows in the table. As opposed to MySQL and InnoDB, which only needs to update the indexes that contain updated columns. The PostgreSQL approach causes more disk IOs for updates that change non-indexed columns. Much of this is Uber specific and heavily influenced by performance tradeoffs with Schemaless, a scalable and fault-tolerant data store built in house at Uber.

Most users interact with their MySQL databases with the free, visual interface called WorkBench. Here’s how it looks:

Here’s how one user summarizes MySQL on G2Crowd:

“It is a totally free database manager that can be used by anyone who wants it, has a huge community where we can easily clarify any questions that arise, the line of learning is very versatile, and also it’s intuitive to the development of the databases we are designing. It is ideal for medium complex processes since the data processing within these databases is incredibly fast concerning others. It also has a very useful viewer when it comes to locating the errors that have arisen in the data stored in the database of data …”

“With MySQL, I have developed and managed the databases of the different industrial processes that the company has had to carry, basically because of how simple it is and because of the security it guarantees us, in addition to having such a large community that quickly helps us solve any problems we have. Since using it, I have not had any problem with it, nor hang-ups inside the database, nor poorly executed processes between stored data.” 

Ask These Questions to Decide Between PostgreSQL and MySQL

Asking the following questions will help you decide between PostgreSQL vs. MySQL

Are you managing a lot of NoSQL (Non-Relational) data?

As a hybrid “object-relational database management system,” PostgreSQL supports object-oriented programming and relational programming simultaneously. PostgreSQL lets you define objects and table inheritance, which helps efficiently manage complex data structures. 

PostgreSQL also offers the widest range of native NoSQL support for data types like JSON, XML, Hstore. It lets you define custom data types and functions as well. MySQL supports JSON only. If you plan to use other NoSQL formats, PostgreSQL is a better choice.

Read-write operations or read-only queries?

PostgreSQL is ideal for complex read-write operations, especially when data needs validation. Meanwhile, the simplicity of MySQL allows it to process massive numbers of read-only queries faster and more reliably than PostgreSQL. By removing certain SQL features, MySQL stays light to prioritize the speed of concurrent, read-only functions. 

Multiprocess vs Single Process

PostgreSQL uses multiple processes, whereas MySQL runs on a single process. The MySQL Server (mysqld) executes as a single OS process, with multiple threads executing concurrently. MySQL does not have its own unique thread implementation and relies on the thread implementation of the underlying OS. MySQL utilizes a single process and maintains one thread (or path of execution) per connection, resulting in less memory pressure.

PostgreSQL starts a new process with its memory allocation for each connection it establishes – requiring a significant memory allocation on systems with a high number of client connections. Pressures caused by memory utilization becomes increasingly noticeable on both systems at scale. However, system performance at scale using PostgreSQL will require much more capacity and reliability planning than with MySQL.

Are you managing large volumes of data or a small cloud-based system?

There’s no limit to the size of your PostgreSQL databases. This DBMS can efficiently manage large data volume stores and complex queries on large databases. For example, this database administrator says that his company manages “200k to 500k events per second across around 100 database servers, 500 PostgreSQL instances, and around 500 databases,” and the individual databases are several terabytes to 20 terabytes in size. 

MySQL works better with smaller-size databases. According to 365DataScience, “MySQL works more efficiently for small, cloud-based applications and systems, while PostgreSQL is more effective for companies working with big data and complex queries.”

PostgreSQL vs. MySQL: Do you need data storage engine flexibility?

MySQL is an excellent choice when you want the flexibility to use different data storage engines. The flexibility of “pluggable” data engines lets you incorporate data from the widest variety of tables. MySQL is currently compatible with InnoDB, MyISAM, Memory, CSV, Archive, Blackhole, NDB/NDBCLUSTER, Merge, Federated, and Example. PostgreSQL is only compatible with its native ACID/MVCC engine.

Is MVCC a core requirement?

PostgreSQL was the first DBMS to offer native concurrent processing through multi-version concurrency control (MVCC), making it the de facto choice when multiple readers/writers are interacting with a large-scale database concurrently.

MySQL also offers MVCC when paired with its default storage engine InnoDB. Therefore, choosing between these MVCC-capable database systems largely depends on the context. According to Ken Ejima on Hackermoon, “MySQL works best for online transactions, and PostgreSQL works best for append-only, analytical processes such as data warehousing.”

Is ACID compliance a priority?

ACID compliance was built into PostgreSQL from the beginning, making it an excellent choice for those who need to prevent data corruption at the transaction level. MySQL is ACID-compliant, but only with its default storage engine, InnoDB, and the storage engine, NDB Cluster. InnoDB includes commit, rollback, and crash-recovery features for data protection. 

Are you looking for a database system that everyone knows how to use?

Since MySQL is the most popular database system in the world, it’s easier to find database administrators with MySQL experience. Plus, learning MySQL from scratch is more comfortable than PostgreSQL – mainly because of MySQL’s extensive documentation and tutorials. 

Final Thoughts on PostgreSQL vs. MySQL

PostgreSQL is usually the best choice when you want a feature-rich, extensible database that efficiently manages complex read-write operations on large datasets. On the other hand, MySQL is better for cloud and web-based applications, smaller datasets, and high-speed read-only queries.

Did you know you can generate a full-featured, documented, and secure REST API in minutes using DreamFactory? Sign up for our free 14 day hosted trial to learn how! Our guided tour will show you how to create an API using an example MySQL database provided to you as part of the trial!

Create Your PostgreSQL and MySQL APIs Now

DreamFactory: Rapidly Connect to any MySQL or PostgreSQL Database

Connecting to a MySQL or PostgreSQL database is a time-consuming and labor-intensive process. Not only will you need to code a custom API, but you’ll also have to secure and manage the connection. This is where DreamFactory can help. The DreamFactory API manager instantly generates custom REST APIs for any MySQL and PostgreSQL database, applies role-based access control, and generates an API key for the connection.

Want to see how easily and quickly DreamFactory can connect to a database? Read this part of our guide or start your free hosted trial of DreamFactory now!