A quick way to get Postgres to work with your existing Rails app
There are plenty of instructions for installing PSQL on OS X Mountain Lion such as this or this. The problem here is that as of Mountain Lion Postgres opens a socket in /var/pgsql_socket
, which is different from previous versions. As a result, when you try to start Postgres with psql
in the shell, you'll get an error message, similar to:
1 2 3 |
|
The links I mentioned above provide a possible solution to this problem. You could also try the varios suggestions in Stackoverflow. Alas, I had no luck with any of them, but this is what saved my day:
- Install the Postgress App:
- Download the latest version.
- Unarchive it.
- Drag-and-drop Postgres.app to your Applications folder
Amend your PATH by running this in the shell:
export PATH="/Applications/Postgres.app/Contents/MacOS/bin:$PATH"
Start the Postgres.app from your Applications folder. You should be seeing a black elephant in the menu bar.
Create a role with the same name as the one you have specified in your
database.yml
file with these commandspsql
to startthe psql.- Create the role with
CREATE ROLE <username> SUPERUSER LOGIN;
. \q
to quit the psql shell.
After that run these commands to recreate the development and environment databases of your app:
rake:db:create:all
rake:db:migrate
rake:db:migrate RAILS_ENV=test
You should be good to go.
P.S. Also check out this #342 Migrating to PostgreSQL Railscast for a full guide on migrating from SQLite to Postgres and this Stackoverflow question for similar instructions for Ubuntu.