From MySQL to Postgres
- November 28th, 2009
- Write comment
Slowly, I’m making the transition from MySQL to Postgres.
I’m not a database expert, but I’ve had quite a bit of experience working with them and designing them. For the first eight years or so of my experience working on the Web, my exposure was mostly limited to MySQL. But as I started playing around with Django, I decided to go with its authors’ recommendations and see what all this Postgres hoopla was all about. After a while, I noticed that it was faster and much less resource-hungry on my system.
Which is awesome. I’m on a VPS. I like to know that I’m running as lightweight a setup as possible. I’m a huge fan of efficiency.
So I got curious: could I port all my existing apps over to use Postgres instead? The problem is that MySQL and Postgres don’t exactly speak the same language. It’s similar in a lot of ways, but of course, computers are finicky contraptions that demand exact translations, with the exact characters it expects, in the exact format it wants.
For many of my old personal projects, this wasn’t terribly difficult. It was just a matter of writing a few scripts to export my relatively simple data into a format that Postgres would easily understand.
The first big challenge I came across, though, was in porting my MediaWiki installation over. My first instinct was to do as I had with my own projects: dump the SQL and transform it into Postgres-digestible code.
I googled and coded and googled some more, and after several hours of trying to get this to work, I realized it was a dead end. It then dawned on me that there was no reason to even attempt to do what I was doing. It made more sense to do an export of the data, to XML, and then import it into a fresh installation of the app with a fresh Postgres database.
There were a few gotchas, but it was basically very easy at that point. One hour worth of work vs six.
So the steps were pretty easy:
- Use the export script to export the data from the existing MySQL MediaWiki installation:
php-cgi /maintenance/dumpBackup.php wikidata.xml
- Initialize a new database in Postgres.
- Set up a fresh installation of MediaWiki on a new path. Follow the setup wizard, using your new Postgres database information.
- After installation is complete, delete the Main Page that MediaWiki sets up for you.
- Copy the wikidata.xml file to the /maintenance folder in your new MediaWiki installation.
- Run the MediaWiki script to import the data:
php-cgi /maintenance/importDump.php wikidata.xml
And that was it. Very easy.
I have a few more challenges ahead of me that I suspect will require a lot more hands-on work than what it took with MediaWiki. The main one will be a project I’ve intended to do for a while — converting a vBulletin installation to use a different forum platform altogether. There will be a lot of custom code. It should be fun.
I suspect that it will be complicated and may even be impossible to manage the various blogs I’ve created over the years. Half of them were built in Movable Type. Half are in WordPress. I’d like to make my life just a little easier and pick one or the other. Movable Type supports Postgres natively, whereas WordPress sports an unofficial plugin. It might work, but my coder-instincts are telling me not to get my hopes up too much. If the latest versions of Movable Type are comparable enough to WordPress, I might decide to go nuts and move everything over to Movable Type instead.
We’ll see. For now, I have a few more important things to take care of before I embark on any strictly-maintenance-and-upgrades kind of work. More to come.

