Rails + Postgres Notes

some brief notes on getting Rails and the Postgres SQL database play nice :

1) Installing the rails application skeleton application install with Postgres as the development database, as opposed to sqlite3 (the default) or mysql (the “old” hotness) is done with the the command line param (in the current directory, hence the “.”)

$rails new . --database=postgresql

3) the username / db owner “postgres” is the superuser id for PostgresSQL. best practice would suggest NOT using that for your database in production, and probably not in dev or test.

2) if connecting to the database via command line works – for example for username “postgres” it would look like :

$psql -U postgres

– BUT, you get a error running the rails server with it not connecting to the db with a error message like:

could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/pgsql_socket/.s.PGSQL.5432"?

seems ruby/rails/rake is not finding the db where it expects to! The fix was :

$mkdir /var/pgsql_socket/
$ln -s /private/tmp/.s.PGSQL.5432 /var/pgsql_socket/

which creates a virtual link from where it is to where it’s expected. (you might need to run those commands under “sudo” for permission reasons)

if that doesn’t fix it there are a bunch of other possible solutions at this stack overflow posting Repairing Postgresql after upgrading to OSX 10.7 Lion

This should be a one time fix.

3) You might get a “fe_sendauth: no password supplied” the first time you run a new application, because the database.yml, under development, uses the application name as the username / db owner, rather that “postgres” which is the frequently the default username / db owner for that database when it was created (depending on your tool). So change the development username to “postgres” or (better) give it as new owner when you create the db.

Leave a Reply