Jamie's Blog

Lessons from a life of startups, coding, countryside, and kids

Connecting Navicat to Postgresql on Vagrant

I’m falling in love with Postgres as a database but it comes fairly well locked down (good for production, not so good for development). I do all my development in a Vagrant box so a) the environment matches production and b) I don’t pollute my Mac with various conflicting versions of things. Mostly I’ve been using the psql command which is actually pretty good if you can remember all the commands. But sometimes you really want a decent UI for the database, and that’s where Navicat comes in (actually, I use the cheaper Navicat Essentials).

First, you’ll need to to add this line to your Vagrantfile to forward your local

  config.vm.forward_port 5432, 5432                 # postgres
This forwards the local port of 5432 to the Vagrant instance port 5432.

But you’ll still get connection errors because Postgres isn’t configured to allow connections from a non-local address. Add the highlighted line to /etc/postgresql/9.1/main/pg_hba.conf

# "local" is for Unix domain socket connections only
local   all             all                                     md5

IPv4 local connections:

host all all 127.0.0.1/32 md5 host all all 10.0.2.2/32 md5

You might also need to add this line to /etc/postgresql/9.1/main/postgresql.conf
listen_addresses = '*'
You can then connect to Postgresql with Navicat using the following options

Navicat configuration