All threads / setup Postgres user fails
Ask A Question


You’re not receiving notifications from this thread.

setup Postgres user fails

Anthony Candaele asked in Databases


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:

createuser --pwprompt

, 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 postgres

I get

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

it was the line

createuser --pwprompt

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
CREATE ROLE deploy WITH createdb;

then I was able to run

rake db:create on the production server

Yeah, that's another way to do it. Glad you got it working.

Join the discussion

Want to stay up-to-date with Ruby on Rails?

Join 70,078+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.

    logo Created with Sketch.

    Screencast tutorials to help you learn Ruby on Rails, Javascript, Hotwire, Turbo, Stimulus.js, PostgreSQL, MySQL, Ubuntu, and more. Icons by Icons8

    © 2023 GoRails, LLC. All rights reserved.