问题
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:
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.
回答2:
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.
来源:https://stackoverflow.com/questions/9493257/postgres-creating-a-username