WordPress and PostgreSQL

I decided that I need to start posting again, it’s been a while since I’ve taken the time to write. Now I’m using WordPress, instead of Serendipity, because of the overall quality and because of the import/export capabilities (caveat: WP isn’t perfect here, either… more on this later). This decision took some consideration because, as a PostgreSQL advocate, I naturally would want to choose software that works with PostgreSQL (Serendipity does; WordPress is MySQL-only).

It got me thinking a little bit about why I like PostgreSQL, when it matters, and when it doesn’t.

Let me start out by saying that, so far, I am quite impressed with the quality of WordPress. A lot goes into publishing software that has little or nothing to do with the database system chosen, and I think that they got most of those things right. One could go as far as to say that publishing software (for a single publication) has little use for a relational system at all:

  • It’s a single application with its own data.
  • It mostly just needs to fetch pages with words on them, it doesn’t need to draw sophisticated inferences from complex relationships.
  • The data is largely independent. It’s unlikely that, for example, one article you post conflicts with another article in a way that a machine can hope to understand.
  • Most importantly, the ultimate data is meant to be consumed by humans. Relational theory is largely based on the ability of machines to give you useful answers from data that is greater in volume than the consumer would prefer to read. If humans are reading it manually, what’s the point?

I won’t discuss here the benefits of using an established SQL system in general as opposed to flat files or some other non-SQL system  — I think those are apparent. However, I do think that there are some areas PostgreSQL specifically might offer a benefit over MySQL for this kind of publishing application:

  • Full-text search over crash-safe tables.
  • Languages like PL/Perl are indispensable when you have little text processing tasks and it’s easier to just do it before it gets back to the application.
  • Triggers and functions in postgresql are very flexible (which can use the NOTIFY mechanism, or even open sockets to make a request), which allows virtually any kind of cache invalidation you can imagine. That might be convenient for high-traffic sites to refresh static content.
  • Transactional DDL is ideal for no-downtime schema upgrades.
  • Features like WITH RECURSIVE (Common Table Expressions, new in 8.4) might make it easier to do interesting things, like query based on a tree structure (like comments), or find interesting transitive relationships (for instance, following tags from one article to the next, as a big graph structure).

[ Disclaimer: I don't really follow MySQL development. Maybe they implemented some of these things and I didn't notice. Also, I don't know much about WordPress, so this post should not be interpreted to mean that the WP developers chose their database system poorly. ]

It would be nice if WordPress did support PostgreSQL. It’s just another application that’s getting a lot of attention, and it’s another opportunity where postgres is just sitting on the sidelines, because MySQL is good enough to get the job done. If postgresql were in the mix, developers would see those features in action and think: “Wow, that was easy. I didn’t know you could do that!”.

I think it’s a myth that the database system only matters if you are doing a 10-way join every other query. Postgres offers a lot of features that just make things easier: easier to administer, easier to write queries, easier to catch bugs in the application, easier to do simple manipulations (such as on dates or strings), etc. A DBMS doesn’t get much credit for working well on a small system, but I think it should — sometimes a small system stores very important data (especially when “small” for a modern computer is so large and getting larger).

It would also be nice if it supported FirebirdSQL — by all accounts a good database system with a lot to offer, but hasn’t quite caught on for these types of applications. FirebirdSQL is designed to work well as an embedded system (as well as a server), which sounds useful for an application where the user doesn’t want to know much about the database system behind it.

I’ll get back to the import and export capabilities in my next post.

8 thoughts on “WordPress and PostgreSQL

  1. Another benefit to PostgreSQL support would be TOAST…

    I think TOAST would be *enormously* helpful for a “large text field”-oriented application like WordPress, from three perspectives:

    a) Compressing the large text columns should diminish I/O considerably

    b) Compression reduces the overall footprint of the database, and should reduce memory usage, too

    c) By separating the “big text” bits into TOAST tables, queries that don’t actually access those bits will fit *wildly* more tuples into each page (of disk/memory), and be spectacularly more efficient

  2. Pingback: How to Bring Import and Export Back « Experimental Thoughts

  3. Howdy,

    I think you are oversimplifying what people expect from publishing systems. Consider “Tags” and site analytics which are generally quite relational in implementation.

    Full text search on myisam is very much out of favor by power users as it is fairly slow and not particularly tunable. Sphinix is a popular alternative and there is a MySQL interface with Sphinix which allows to MySQL to make use of its far superior implementation.

    From the work I had done with WordPress I get the feeling that the developers don’t want to think all that much about relational theory. Turning on the general query log while installing WordPress make some of the ugliness of the system visible.



  4. Wow ! How strange :)

    I’ve just noticed this post which you published just one month after I published the first release of my “plugin” to allow using WordPress with a PostgreSQL.

    Maybe you’d like to give it a try ?

    You can find it in the WordPress plugins directory :


    Just a note : for now the development version is the only one to support WordPress 2.9.1 until I have enough feedback about it working in different setups.

    • Oh, great!

      I’ll give it a shot. I may start hosting it myself soon, which would be a good opportunity to try it.