Skip to main content

setup Postgres user fails

Databases • Asked by Anthony Candaele

Hi,

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,

Anthony


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
exit

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
psql
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.


yeah,

I found good documentation on the Digital Ocean Tutorials:

https://www.digitalocean.com/community/tutorials/how-to-use-roles-and-manage-grant-permissions-in-postgresql-on-a-vps--2

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

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


Login or Create An Account to join the conversation.

Subscribe to the newsletter

Join 27,623+ developers who get early access to new screencasts, articles, guides, updates, and more.

    By clicking this button, you agree to the GoRails Terms of Service and Privacy Policy.

    More of a social being? We're also on Twitter and YouTube.