3

I'm trying to get started with Postgres on Rails apps on Mac. I made a new rails app called "shawsome" and in the database.yml file it created this

development:
adapter: postgresql
  encoding: unicode
  database: shawsome_development
  pool: 5
  username: shawsome
  password:

But the server wouldn't run because there's no role for "shawsome." Rails just seemed to have inferred the username from the name of my app.

I looked at postgres documentation and it talks about CREATE USER command

CREATE USER jonathan;

However, when I tried to do CREATE USER, it said CREATE comment not found.

Can anyone tell me what I'm doing wrong?

Also, once it's in production (on Heroku) I'm assuming it will also need a username. Will that username remain the same? i.e. if it's configured on my machine, do I need to do anything extra on Heroku?

1
  • @TheDelChop Mac 10.6.8 (not Lion), I updated the OP. Commented Feb 29, 2012 at 3:41

2 Answers 2

3

To expand a bit on TheDelChop's answer After installation you can run the following in the terminal:

createuser -P

(The -P is to add a password)

It will ask you for name, password, whether they are a superuser, can create new roles, and can create new db's. You probably won't need any of those permissions for rails.

Then create the database to run with the following role you created:

createdb -O ROLE_NAME_FROM_PREVIOUS_STEP NEW_DATABASE_NAME

And viola, you should be good to go.

Sign up to request clarification or add additional context in comments.

Comments

0

Then you can use the pg binary command createuser in bash/zsh. Just answer the questions they will ask you, and don't setup the database.yml for production, Heroku will take care of that.

3 Comments

but when I create the Rails app for PG, it automatically sets some settings (a database name based on the name of the app, a role that I don't really have etc) for the production database. Should I delete those? or just leave them?
looks like you don't need to specify production details, devcenter.heroku.com/articles/database#database_urls
Yes, heroku rewrites the config/database.yml for you - see devcenter.heroku.com/articles/heroku-postgresql - @AlexMarchant link is no longer correct.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.