PostgreSQL vs. MySQL: Which Is the Best Open Source Database?

By on Friday, July 8th, 2011 in Technical | Related Software Packages: , , , , , , , , | Keywords: , ,

When you’re choosing a database, you’re making a long-term decision, because changing your mind later is difficult and expensive. You want to get it right the first time. Two popular open source databases, MySQL and PostgreSQL, are often the final two candidates when admins are preparing a new rollout. This high-level overview of these two open source powerhouses should help you choose which is more appropriate for your needs.

PostgreSQL

PostgreSQL (pronounced Post-gress-cue-ell) bills itself as the world’s most advanced open source database. Some of its fans say it is as good as Oracle, but without the baggage of high cost and snooty customer service. It has a long history, having been developed originally in 1985 at the University of California, Berkeley, as a descendant of the Ingres database.

PostgreSQL is a 100% community-driven open source project, maintained by a worldwide community of more than a thousand contributors. It provides a single completely functional version, rather than the multiple different community, commercial, and enterprise versions that MySQL offers. Its license is a liberal BSD/MIT-type, which allows organizations to use, copy, modify, and redistribute code with only a copyright notice required.

Reliablity is PostgreSQL’s top priority. It is known for being rock-solid and well-engineered, capable of supporting high-transaction, mission-critical applications. Documentation is first-rate, with comprehensive manuals available for free online, along with archives of manuals for older releases. Community support is excellent, and commercial support is available from independent vendors.



Get expert PostgreSQL support

OpenLogic offers support on more than 500 open source software packages.

Data consistency and integrity are also high priorities. PostgreSQL is fully ACID-compliant (atomicity, consistency, isolation, durability.) It has strong security for controlling access to the database, making good use of enterprise security tools such as Kerberos and OpenSSL. You can define your own checks to ensure data quality according to your own business rules. A favorite feature of many admins is point-in-time recovery (PITR), a flexible high-availability feature with powers such as the ability to create a warm standby server for fast failover, and snapshots and restores to specific points in time. But that’s not all – the project provides several methods to manage PostgreSQL for high availability, load-balancing, and replication, so you can use what fits your particular needs.

MySQL

MySQL is a relative youth, first appearing in 1994. It calls itself the world’s most popular open source database. MySQL is the M in LAMP, the software bundle frequently used for web development that also includes Linux, Apache, and Perl/PHP/Python. Most applications built on a LAMP stack incorporate MySQL, including such well-known applications as WordPress, Drupal, Zend, and phpBB.

Initially MySQL was designed to be a fast web server back end, using a fast indexed sequential access method (ISAM), with no ACID support. Since those lean, speedy early days MySQL has added support for a number of additional storage engines, and ACID compliance is now available via the InnoDB engine. MySQL also supports other storage engines, providing capabilities such as temporary tables using the MEMORY storage engine, an example for developers with the EXAMPLE storage engine, fast read-mostly databases using the MyISAM engine, plus several other core storage engines and a number of third-party engines.

MySQL documentation is abundant, and includes good free reference manuals, many books and online articles, and training and support from Oracle and third-party vendors.



Get expert MySQL support

OpenLogic offers support on more than 500 open source software packages.

MySQL has gone through changes in ownership and a fair bit of drama in recent years. It was first developed by MySQL AB, which sold itself to Sun Microsystems for a cool billion dollars in 2008. Sun was in turn acquired by Oracle in 2010. Oracle supports multiple editions: Standard, Enterprise, Classic, Cluster, Embedded, and Community. Some of these are free downloads, some cost money. The core code is GPL, and commercial licenses are available for developers and vendors who prefer not to use the GPL.

Nowadays there are even more choices for databases based on the original MySQL code, because several key MySQL developers have released MySQL forks. Michael “Monty” Widenius, one of the original founders of MySQL, appeared to develop a case of seller’s regret after the Sun sale, and developed his own MySQL fork, MariaDB, free of cost and licensed under the GPL. Drizzle, a fork by prominent MySQL developer Brian Aker, is a substantial rewrite and change in core concepts that is optimized for multi-CPUs, cloud and net applications, and massive concurrency.

Platforms and Workloads

Both MySQL and PostgreSQL power some of the Web’s highest-demand Web sites:

MySQL:

  • Slashdot
  • Twitter
  • Facebook
  • Wikipedia

PostgreSQL:

  • Yahoo runs a multi-petabyte modified PostgreSQL database that processes billions of events per day
  • Reddit
  • Disqus

Both MySQL and PostgreSQL run on multiple operating systems: Linux, Unix, Mac OS X, and Windows. Both are open source and free of cost, so the only cost for testing them is your time and hardware. Both are flexible and scale well for uses ranging from small deployments to giant distributed systems. MySQL goes one level smaller than PostgreSQL, down into the embedded space, with libmysqld. PostgreSQL does not support embedded applications, sticking instead with traditional client/server architecture.

MySQL is often thought of as the speedy database back end for websites and applications, performing fast reads and numerous small queries, but offering fewer sophisticated features and data integrity checks. PostgreSQL is considered the solemn, full-featured, no-nonsense workhorse for transactional enterprise applications, with strong ACID compliance and many data integrity checks. Each is faster at some tasks, and MySQL performs differently with different storage engines. The MyISAM engine for MySQL is by far the fastest, because it performs the fewest data integrity checks. It works great as a back end for busy read-mostly websites, but it is a disaster for any read/write database containing sensitive data, because MyISAM tables will inevitably become corrupted. MySQL has good tools for recovering corrupted MyISAM tables, but for sensitive data InnoDB, which is ACID-compliant, is a better choice.

In contrast, PostgreSQL is a complete integrated database server with a single storage engine. You can improve performance by tweaking parameters in postgresql.conf, and tweaking your queries and transactions. The PostgreSQL documentation goes into detail on fine-tuning performance.

Both MySQL and PostgreSQL are very configurable and can tuned to optimize performance for different tasks. Both support extensions for added functionality.

A common misconception is that MySQL is easier to learn than PostgreSQL. Relational database management systems are all complex, finicky beasts, and these two have comparable learning curves.

Standards Compliance

PostgreSQL aims for SQL standards compliance (the current standard is ANSI-SQL:2008). MySQL is mostly SQL-compliant, but also has its own extensions and support for non-SQL features, which are documented in the reference manual. There are pros and cons to each approach. Standards adherence makes life easier for database admins, database developers, and application developers, because it means they have only one standard to learn, a common set of features and commands to use and support, and their code is portable. This adds up to savings in time and effort, and freedom from vendor lock-in.

Arguments in favor of using non-compliant customizations include freedom to quickly roll out useful new features, rather than waiting for them to work through the standards process. ANSI/ISO standards change and evolve, so standards compliance is a moving target anyway; the big-name RDBMSes, such as Microsoft SQL Server, Oracle, and IBM’s DB2 are only partially compliant. Many of the MySQL’s customizations are not exactly game-changers; for example, the differences in the way single and double quotes and escape characters behave in MySQL don’t seem worth the bother or the potential for errors. MySQL adds even more complexity by supporting multiple SQL modes, such as ANSI, to conform more closely to standard traditional SQL for strict data input checking and various other strict and relaxed data-checking modes.

In Conclusion

Despite their different histories, engines, and tools, no clear differentiator distinguishes either PostgreSQL or MySQL for all uses. Many organizations favor PostgreSQL because it is so reliable and so good at protecting data, and because, as a community project, it is immune to vendor follies. MySQL is more flexible and has more options for being tailored for different workloads. Most times an organization’s proficiency with a particular piece of software is more important than differences in feature sets, so if your organization is already using one of these, that is a good reason to stick with it. If you held my dogs hostage and forced me to choose a database for a new project, I would pick PostgreSQL for all tasks, including Web site backends, because of its rock-solid reliability and data integrity. And I would keep Drizzle running on a test machine, to stay acquainted with it, until it is ready for prime time, and then roll it out for cloud and application servers.

Download the Free OSS Discovery Scanning Tool

Related posts:

  1. Open Source Database Applications Comparison Matrix
  2. How to Access a PostgreSQL Database from Any Language
  3. Three Top Open Source Bug Tracking Apps
  4. PostgreSQL FAQ
  5. MySQL 5.1 is GA

Related Open-Source Packages

Drupal: See all Drupal Articles » Get Drupal Support at OLEX »
MariaDB: See all MariaDB Articles » Get MariaDB Support at OLEX »
MIT Kerboros: See all MIT Kerboros Articles » Get MIT Kerboros Support at OLEX »
MySQL: See all MySQL Articles » Get MySQL Support at OLEX »
OpenSSL: See all OpenSSL Articles » Get OpenSSL Support at OLEX »
PhpBB: See all PhpBB Articles » Get PhpBB Support at OLEX »
PostgreSQL: See all PostgreSQL Articles » Get PostgreSQL Support at OLEX »
WordPress: See all WordPress Articles » Get WordPress Support at OLEX »
Zend Framework: See all Zend Framework Articles » Get Zend Framework Support at OLEX »

Carla Schroder

Carla Schroder is a Linux sysadmin and netadmin, author of The Book of Audacity, Linux Networking Cookbook, Linux Cookbook, and hundreds of how-to articles.

24 Responses to “PostgreSQL vs. MySQL: Which Is the Best Open Source Database?”

  1. [...] this link: PostgreSQL vs. MySQL: Which Is the Best Open Source Database? | Wazi Category: TipsTags: [...]

  2. Alan says:

    Postgresql also boasts a number of features that are vital to developers:

    – transactions (MySQL only supports in in certain backends)
    – Procedural SQL (AKA PL/SQL)
    – Embedded function support in multiple languages like Perl, PL/SQL, Python, Java, ruby, R, etc. (MySQL only supports stored SQL procedures)
    – Optional GeoSpatial layer for GIS/Mapping applications

    Personally, I think it has the most elegant SQL syntax of any RDBMS I’ve worked with.

  3. deanjo says:

    Neither of them are the “best” as they both have their strengths. However if you went by the most flexible and widely deployed that honor actually goes to SQLite.

  4. Adrian P says:

    Facebook trapped in MySQL ‘fate worse than death’
    http://gigaom.com/cloud/facebook-trapped-in-mysql-fate-worse-than-death/

  5. evanx says:

    Skype uses PostgreSQL – while not a website, it is quite a large deployment :)

  6. Did you check out CUBRID by any chance?

    http://www.cubrid.org/

    Worth checking out I think.

  7. JFM says:

    Which is the best? Probably none of them since the set of open source data bases is not limited to PostgreSql and MySql. There is Ingres and Firebird and there was EnterpriseDB formerly SapDB who was open sourced but desmpite having crucial features for mission critical applications who at thet time were not presnt in PostgreSql and MySql languished ignored while article after article pre’sented PostgreSql and MySql as the only open source game in town. It ended being transferred to the MySql people who scuttled it.

  8. JFM says:

    Correction: The alternative to the MySql/PostgresSql was not EnterpriseDb but MaxDb. Now MaxDb has been given back by the MySql people to SAP who has closed it. People passed from it when it was open sourced and that has been the result.

    Also in addition to Firebird and Ingres, Sybase is another formerly colsed source database who is now open source.

  9. Postgres is true “open” Database. so is Drizzle.
    so i am seeing very good future for both of them.
    Postgres uses Process based sessions. like Oracle does.
    while other one is thread based. which is more lighter and it matters for web and cloud deployments.

  10. [...] PostgreSQL vs. MySQL: Which Is the Best Open Source Database? | Wazi. [...]

  11. Alice Wonder says:

    I use to be a die hard MySQL fan. I’ve even met Michael Widenius (good guy). Then it came time to do some work with GIS spatial relations. Even though it was allegedly possible in MySQL I spent days trying to get my shape files into it and just kept getting insert error after insert error even though I was following the tutorials to a tee.

    Wondering if maybe there was something wrong with my shape files, I installed PostgreSQL with PostGIS. Worked the first time. Ported the rest of my web app to PostgreSQL (not too difficult, I use DB abstraction) and since then, have fallen in love with PostgreSQL in general.

    I don’t think I will ever go back. I still use MySQL on some web sites for the sphider search engine, but that is just until I finish a custom SE with features that benefit me most based on their built in search capabilities, which are very powerful.

    With respect to performance of one vs the other, that’s mostly a moot point for me as my apps lend themselves well to content caching, radically reducing the slamming of the DB. However, I don’t notice PostgreSQL being particularly slower as some claim on my dev machine when APC is disabled.

  12. Richard says:

    You need to re-check your fact on licensing. MySQL requires commercial licensing if you are going to even link against their client libraries with a commercial or closed source application whereas PostgreSQL is licensed under a BSD or MIT type license allowing it to be freely used with or as a part of a commercial software application.

  13. Matt Doar says:

    “immune to vendor follies” – that’s a great phrase!

  14. Nikhil says:

    I used to use mysql for our erp in our small company now since this company has grown and their requirement grown too, mysql is a utter fail. Main problem we face us data integrity even with inno db you still don’t have the features you need, eg mysql has triggers but no exception throwing. Ever since oracle took over mysql its been stuck in 5.x and its not hard to understand why

  15. nouri says:

    finally postgresql or mysql of firebird?

  16. Brandon says:

    It was a pleasure to read this comparison since you own a nice subjective point of view.
    The only reason I would turn my mind on PostgreSQL is because it seems not to have any limit! :)

  17. Muhammad says:

    I am searching for a database that can access live data as well as historical data concurrently. I understand postgresql can do that. I am in the investment banking field, I aquire 2GB of data a day which is summarized, the historical summaries are used along with the live data to make live trading decisons. I am a solo trader so I don’t need something like Orcle. Currently I am on sqlite which is not good for write and read transactions happening at the same time so I have work arounds.

  18. John Galt says:

    WE have used both and as long as you are not dealing with apps with over 10 mill records they will work great for just about anything.

  19. Siby says:

    Which will be the best database to store around 50 million records and Analyse around that ? Do we have any issues in performance of queries in postgress?

    please advice..Thanks

  20. Jason says:

    :) I hope no one hijacks your dog in an attempt to make you switch databases choices ;) Very good article, Very good read. Thanks so much for your time and opinion.

  21. [...] ecommerce site faultlessly for well over 5 years. For a comparison with Mysql see this article: PostgreSQL vs. MySQL: Which Is the Best Open Source Database? | Wazi There is plenty of free online documentation and a good free windows DB management tool 'Pgadmin'. [...]

  22. Postgres has been around for years. Its big opportunity came about when Oracle acquired SUN, but Postgres blew it. Postgres is a bait and switch scheme. I understood the game when I was advised to use EnterpriseDB, if I want hints. After all, one of the foremost Postgres architects, Bruce Momjian, works for EnterpriseDB.
    Partitioning is also extremely weak, it doesn’t have even the slightest parallelism and its steering committee is extremely hostile toward user requests. People have been requesting hints for years and have been rididuled for that. Here is an example:

    http://it.toolbox.com/blogs/database-soup/why-postgresql-doesnt-have-query-hints-44121?rss=1

    I gave up Postgres after that. Hints, of course, are a necessary evil and Postgres is the only major database which doesn’t provide them. Postgres is just a commercial for EnterpriseDB, VoltDB, Vertica, Netezza and the other commercial implementations. No wonder that, as far as the number of users is concerned, MySQL cleaned the floor with PostgreSQL, despite its apparent lack of features.

  23. [...] masing-masing tidak akan saya bahas disini, tapi anda bisa membaca artikel-artikel berikut. PostgreSQL vs. MySQL: Which Is the Best Open Source Database?, MySQL vs. PostgreSQL, atau PostgreSQL vs. MySQL: How to Select the Right Open-Source Database. Ok, [...]

Leave a Reply

© 2012 OpenLogic, Inc. | Licensing | Privacy Policy | Terms of Use

Bad Behavior has blocked 2290 access attempts in the last 7 days.