7D7W: Working with PostgreSQL on Mac OS X Mavericks

As discussed, I’m going through the 7 Databases in 7 Weeks book. This week is PostgreSQL.

The first few paragraphs of Day 1 in the book talk about calling:

$ createdb book

As a convention, when I see a dollar sign, I think that means run it at the command-line shell. I did try to run it within PSQL too (and got an error). I opened up a shell and it doesn’t know that command. I need to find out the directory where this was installed.

So, I set off to find where PostgreSQL was installed on a Mac. I um… wasn’t really paying attention during the installer, so I had no idea. I tried looking around on the file system and then with some Googling on Bing, I ended up finding it. It gets installed here:


And here’s how I navigated to that folder and list the contents of that folder (ls –la):

$ cd /Library/PostgreSQL/9.3/bin/
$ ls -la

Yes, the dollar signs mean you run those as commands at the command-line prompt!


To run on a program on Linux/Unix you have to tell it, it’s in the current directory – you do that with a “./”. So I ran “./createdb book”


It was assuming my “rseder” username. During the install, it only set up a username named “postgres”. So I looked in the help (by running:

$ ./createdb –help

to find the syntax. I specified the username:

$ ./createdb book –username postgres

I put in the password I set during the install and voila, it looks like it worked!

Bottom line here, if you need to run command-line utilities for PostgreSQL – the executables are in /Library/PostgreSQL/9.3/bin – if you want to actually work in the database, launch PSQL from Finder, or from here:

$ ./psql –username postgres

And then have at it!

UPDATE: one more thing. The book wants us to install some add-ons. To do that, I started psql in this new “book” database, like this:

$ ./psql book –username postgres

then, I just ran each of these at the “book=#” prompt in psql:

CREATE EXTENSION fuzzystrmatch;

After each one of these, it just returned a “CREATE EXTENSION” on it’s own line, so I didn’t know if that meant it worked.


However, when I went back out to the command and ran the example from the book:

$ psql book –username postgres –c “SELECT ‘1’::cube;”

That now worked:


So, I’m assuming the above is correct!

Posted in 7D7W, Professional Development, Uncategorized

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s


Enter your email address to follow this blog and receive notifications of new posts by email.

Join 7 other followers

%d bloggers like this: