Few days ago my company computer was upgraded. I waved goodbye to ~3,5 years old 5400rpm HDD and said hello to the brand new SSD.
Because replacing hard drive in my case signifies system installation I decided to migrate from (not so fresh..) Snow Leopard to the latest OS X release.
In this post I’ll show you how to install & run PostgreSQL 9.x on the fresh OS X 10.9 Mavericks instance.
If you don’t have fresh installation (but upgraded one and you experienced any issues related to existing postgres installation) you could try uninstall pg and follow steps #0 and #1.
It may work, but doesn’t have to..
I didn’t have opportunity to test it in a such case so regardless of the outcome any feedback will be welcome.
Step #0 – Install homebrew
Homebrew is a missing package manager for OSX that enables you to install 3rd party software (with satisfying their dependencies) using one command.
Installation is pretty easy and comes down to run a single command in the terminal:
Step #1 – Install PostgreSQL
You can install the latest version of PostgreSQL by typing:
However, if you want to install a specific version (let’s assume latest 9.2.x instead of 9.3.x) then you should use ‘brew versions':
Step #2 – Initialize database cluster
You have to create a database cluster. It’s not so complicated as it sounds:
This command creates all the necessary directories in which the database data will live. For more information see the initdb manual.
Step #3 – Run postgres
It’s time to run installed postgres instance:
The path given as an argument must match path used with initdb in Step #2
If you want to start PostgreSQL automatically after log-in run the following command:
It will create symbolic link to /usr/local/opt/postgresql/homebrew.mxcl.postgresql.plist inside ~/Library/LaunchAgents/ directory.
Step #4 – Create a role
Last but not least – you have to create some user which will be able to create databases:
For more informations visit createuser documentation.
Step #5 – Do the victory dance, install additional tools
That’s all! From now you have full-fledged postgres instance running on your Mac :)
Please help me improve this guide and share you suggestions in comments below.