I'm following the Deploy Rails guide
I'm now a the part where Postgres gets installed. I successfully installed Postgres, but when I try to create a new Postgres user with:
, I'm getting this message:
creation of new role failed: ERROR: role "postgres" already exists
anyone knows what's going on?
thanks for your help,
I think that's because the
postgres user already exists. You can do the following to drop the user and create it from scratch:
sudo su postgres dropuser postgres createuser --pwprompt
when I switch to the postgres user and run
dropuser: removal of role "postgres" failed: ERROR: current user cannot be dropped
Did you install Postgres via homebrew on your development machine? Or is this in production?
If you installed it locally (especially in OSX) you can access the Postgres cli by simply typing
psql and it will use your current credentials to log you into the cli. From there you can create/delete/modify databases/roles/etc.
@James, I'm not installing Postgres on my development machine, I'm installing it on the production server. For the moment I'm deploying another Rails application, and I'm running in exactly the same problem as mentioned in this post, when I type:
createuser --pwprompt I'm still getting the error message: creation of new role failed: ERROR: role "postgres" already exists
now I'm finally getting it:
sudo su - postgres createuser --pwprompt exit
it was the line
that confuses me, I typed this litteraly in the command line, while I should specify the user I want to create, for instance:
create deploy --pwprompt
I think it would be clearer if it was specified in the deploy guide like this:
create [name of user] --pwprompt
I agree, the guide should be updated to it's more clear. There's also another way to create a database user manually.
sudo su - postgres
Once you're in Postgres issue this command:
create USER databaseuser with password 'yourpassword';
Where databaseuser is the name of the user you want to create and yourpassword is the password you'd like to assign.
That's how I usually do it when spinning up a new instance.
I found good documentation on the Digital Ocean Tutorials:
basically I fixed my problem with:
sudo su - postgres psql CREATE ROLE deploy WITH createdb;
then I was able to run
rake db:create on the production server
Join 30,005+ developers who get early access to new screencasts, articles, guides, updates, and more.