Skip to content

Instantly share code, notes, and snippets.

@aokolish
Created November 27, 2011 23:26
Show Gist options
  • Save aokolish/1398431 to your computer and use it in GitHub Desktop.
Save aokolish/1398431 to your computer and use it in GitHub Desktop.
how to get postgresql working locally with rails
development:
adapter: postgresql
database: <db_name>
encoding: utf8
username: <username>
password:
host: localhost
# ...

Installing postgresql

This is based off of the following sites:

NOTE: If you have OSX Lion, you probably already have postgres; you may need to edit your $PATH if which psql returns /usr/bin/psql. Otherwise, you have to add -h localhost to some commands to get them to work.


  1. Install homebrew (popular package manager): http://mxcl.github.com/homebrew/

  2. Install postgres (may take a while): $ brew install postgresql

  3. After the installation completes, there will be instructions on how to create a database, start the server, start the server at login, and install the pg gem. Do all of this (copy and paste each command)

  4. Start the PostgreSQL interactive terminal: $ psql postgres -h localhost NOTE: since I'm on lion, I had to add the -h localhost argument to all psql commands.

  5. Create a user and a database: CREATE USER <username> SUPERUSER; CREATE DATABASE <database_name> OWNER <username>;

  6. In your rails app, modify the database.yml as shown (replacing the db name and username), run dm migrations (if needed), and restart your server.

Helpful stuff

How to list all postgres databases:

$ psql postgres -h localhost -l

How to drop a database:

$ dropdb <mydb> -h localhost

Start postgres:

$ pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start

Stop postgres:

$ pg_ctl -D /usr/local/var/postgres stop -s -m fast

Postres admin (GUI admin for postgres):

http://www.pgadmin.org/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment