Upgrading PostgreSQL on Ubuntu

I recently started using Ubuntu Linux on my main development machine. That means that my PostgreSQL database is running under Ubuntu, as well. I’ve written guides to upgrading PostgreSQL using Homebrew in the past, but the upgrade process under Ubuntu was much smoother.

These steps are assuming that you use Ubuntu 16.04 LTS, and PostgreSQL 9.6 is already installed via apt.

  1. Stop the postgresql service.
    $ sudo service postgresql stop
  2. Move the newly-created PostgreSQL 9.6 cluster elsewhere.
    $ sudo pg_renamecluster 9.6 main main_pristine
  3. Upgrade the 9.5 cluster.
    $ sudo pg_upgradecluster 9.5 main
  4. Start the postgresql service.
    $ sudo service postgresql start

Now, when running pg_lsclusters, you should see something like the following:

9.5 main          5434 online postgres /var/lib/postgresql/9.5/main          /var/log/postgresql/postgresql-9.5-main.log
9.6 main          5432 online postgres /var/lib/postgresql/9.6/main          /var/log/postgresql/postgresql-9.6-main.log
9.6 main_pristine 5433 online postgres /var/lib/postgresql/9.6/main_pristine /var/log/postgresql/postgresql-9.6-main_pristine.log

Verify everything is working as expected, then feel free to remove the 9.5/main and 9.6/main_pristine clusters (pg_dropcluster).

These cluster commands may be available in other distros, but I haven’t been able to check them. YMMV. Good luck!

Podcasts I’m Listening To (November 2015 Edition)

My wife Naoko wrote a reply to this post. It was fun comparing how different the podcasts we listen to are. 🙂

First, I’d like to plug a podcast that I’m a semi-regular guest on, techsTalking(5417), a podcast where technology people just talk about whatever is on our mind.

Here are some other podcasts that I’m currently subscribed to:

  • The Incomparable — a podcast about anything geeky. Star Wars? Check. Star Trek? Check. Silly drafts? Check. Crazy movies? Check.
  • The Incomparable Game Show — born from The Incomparable proper, regular panelists play crazy games for your entertainment. On the podcast.
  • Incomparable Radio Theater — The Incomparable podcast, once upon a time, liked to do funny things on April Fools. Like, say: release a full-length episode in the format of old-time radio drama. Including equally funny sponsors (some fake, some real). Now, they’ve spun it off in to a separate podcast.
  • Random Trek — Incomparable regular Scott McNulty hosts a podcast with non-random guests talking about random episodes of Star Trek.
  • Robot or Not? — Is it a robot? Or not?
  • Astronomy Cast — A weekly “facts-based journey through the cosmos”.
  • Reconcilable Differences — Two of my favorite podcasters, John Siracusa and Merlin Mann, get together on one podcast.

A few other podcasts I listen to occasionally:

And assorted programming-specific podcasts.

bundler gotcha

So, this is a thing:

bundle install --without development:test
Bundle complete! XX Gemfile dependencies, XX gems now installed.
Gems in the groups development and test were not installed.


bundle install
Bundle complete! XX Gemfile dependencies, XX gems now installed.
Gems in the groups development and test were not installed.

Basically — you run bundle install --without <group> once, and that’s saved in .bundle/config. So next time you run bundle install without any arguments, it won’t install gems in the groups you specify.

It looks like it is fixed in Bundler 2.0, though.

Homebrew and PostgreSQL 9.4

Edit 2016/1/9 I have updated these instructions for upgrading from PostgreSQL 9.4 to 9.5.

As you may know, I am a big PostgreSQL user and fan. I also use Homebrew to manage 3rd party software packages on my Mac. PostgreSQL 9.4 was just released a couple days ago with some really cool features — a binary-format JSON datatype for speed and flexibility (indexes on JSON keys? Of course.), and some really good performance improvements. Read the release blog post and release notes for more information.

However, if you’ve used PostgreSQL before, you know that upgrading can be a little difficult. Here’s what you have to do to upgrade your Homebrew-installed PostgreSQL 9.3 to 9.4. Keep in mind, these steps are for a standard Homebrew installation — as long as you haven’t configured custom data directory paths, it should work.

  1. Turn PostgreSQL off first, just in case:
    $ launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
  2. Update PostgreSQL itself:
    $ brew update && brew upgrade postgresql
  3. Make a new, pristine 9.4 database:
    $ initdb /usr/local/var/postgres9.4 -E utf8
  4. Migrate the data to the new 9.4 database:
    $ pg_upgrade \
      -d /usr/local/var/postgres \
      -D /usr/local/var/postgres9.4 \
      -b /usr/local/Cellar/postgresql/9.3.5_1/bin/ \
      -B /usr/local/Cellar/postgresql/9.4.0/bin/ \
  5. Move 9.4 data directory back to where PostgreSQL expects it to be:
    $ mv /usr/local/var/postgres /usr/local/var/postgres9.3
    $ mv /usr/local/var/postgres9.4 /usr/local/var/postgres
  6. Start PostgreSQL back up!
    $ launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist

Note: If you’re using the pg gem for Rails, you should recompile:

$ gem uninstall pg
$ gem install pg

Kerbal Space Program – Asteroid Redirect Mission

Kerbal Space Program — KSP for short — is an incredibly addictive game about… Space exploration! In the game, you are in charge of the space program on planet Kerbin. Kerbin is located in a solar system quite similar to our own solar system, with a few differences. I’ve been playing this game for a few months, and finally decided to write a blog post about my experiences and thoughts.

Jeb on Mün

Note that KSP is still being developed with regular updates. Consider it alpha software — feature set is incomplete, and there may be bugs along the way. Regardless, KSP has fostered a very strong community of fans, players, and even modders. I haven’t developed a mod / plugin for KSP myself, but it is architected to be easily extensible. My favorites are MechJeb – autopilot and maneuver assistant and Kethane – in-situ resource utilization, but there are many more to choose from.

As of version 0.23.5, there are two modes of play – “Sandbox” and “Career”. Career mode is relatively new to the game (since 0.22), and is still being heavily developed. The point of the game in Career mode is to build rockets, use those rockets to send Kerbals to space, and gather science! In return for these science points, you can unlock additional parts to make bigger and faster rockets.

Rocket Science

When I was a kid, I often enjoyed constructing and flying model rockets with my father and brothers. I never understood the phrase “it’s not rocket science” — I thought building rockets were relatively easy. Make an aerodynamic body, attach the motor, and light the fuse!

I was wrong. I can’t begin to start on how many ways I was wrong. KSP taught me not only where I was wrong, but how wrong I was.

New words, words I have never heard before, words like “periapsis” and “apoapsis”, became not only familiar, but required knowledge. I realized that rocket science is not only about building rockets, but also about controlling them.

Periapsis. Apoapsis. Hohmann transfer. Plane-change maneuver. Gravity assist. The Tsiolkovsky rocket equation. Specific impulse. ΔV.

These words all mean something in KSP. You can play the game without really knowing about them, but if you want to get good, you probably should.

I wish I had this game when I was a child, not only because it would’ve been great fun, but also because it would have taught me the importance of physics and mathematics from an early age. In elementary school, our teachers would always tell us that math was very important! But they didn’t have any concrete examples. KSP changes all of that. NASA has already seen the potential in this game — the latest version was actually a collaboration between the KSP developers and NASA. While entry into the classroom may be difficult, I believe that this game has incredible value for children. How many times have you heard “<insert product here> makes math fun!”? KSP is one of the few games that actually makes math fun.

And now, here are some photos of me “researching” and “preparing” for this blog post 🙂