• This is as much a note to self as ment for sharing purposes

Since I normally prefer hosting Rails applications on Heroku these days, a Postgres DB is required as SQlite is not supported. Hence, I often need to create a new Postgres database and a user with permissions. If you need it too, you’ve probably seen this error message:

ActiveRecord::NoDatabaseError: FATAL: database “my_rails_blog” does not exist

Assuming you have Postgres installed, and your Mac/Linux user has privileges to run psql, here’s how I do it:

From the terminal, run

psql

Check what databases are available

\list

Create a new database

CREATE DATABASE my_rails_blog;

Grant access

GRANT ALL PRIVILEGES ON DATABASE my_rails_blog to _your mac username_; 

Exit psql by

\quit

You’re then ready to rake it and start creating migrations.