Apr 14, 2014

Setting up postgres for local development on Ubuntu 14.04



I'm starting to do some ruby development on my trusty (so far) Dell XPS 13. Time to get my stack set up. First order of business is Postgresql. Then Ruby, then rails, then it's go time. Let's get started!


For postgres, first update and get the packages you'll need:


sudo apt-get update
sudo apt-get dist-upgrade
sudo apt-get install postgresql postgresql-contrib pgadmin3


I don't know about you, but for local development on my laptop I don't like to set up a password for postgres. Let's set that up.


sudo -u postgres psql
ALTER USER postgres PASSWORD 'newpassword';

If you chose '' in the above you'll have no password so there's one more step to take in order to connect locally. Pop open your editor of choice and modify the pg_hba.conf file. (For me that was located in /etc/postgresql/9.3/main/pg_hba.conf)

You'll want to make sure you entries look similar to this:


local all postgres trust


Here's the part of the file you need to alter:

 84 # Database administrative login by Unix domain socket
 85 local   all             postgres                                trust
 86 
 87 # TYPE  DATABASE        USER            ADDRESS                 METHOD
 88 
 89 # "local" is for Unix domain socket connections only
 90 local   all             all                                     peer
 91 # IPv4 local connections:
 92 host    all             all             127.0.0.1/32            trust
 93 # IPv6 local connections:
 94 host    all             all             ::1/128                 trust


One last thing you'll optionally want to do is uncomment the line in /etc/postgresql/9.3/main/postgresql.conf where postgres listens. This might not be necessary but let's get it done anyway:

listen_addresses = 'localhost'    # what IP address(es) to listen on;

With that out of the way let's give postgres as restart

sudo /etc/init.d/postgresql restart

And now you should be able to connect to postgres via the command line or pgadmin3.

Last thing. If you're going to eventually install the pg gem on ubuntu, you'll need to install the postgresql dev packages. Might as well do that now:

sudo apt-get install libpq-dev


With that all done you should be set. Give it a try from pgadmin3, your client of choice, or the command line

1 comment: