Ask A Question

Notifications

You’re not receiving notifications from this thread.

setup Postgres user fails

Anthony Candaele asked in Databases

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

Reply

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
Reply

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
Reply

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.

Reply

@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
Reply

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
Reply

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.

Reply

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
Reply

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

Reply
Join the discussion
Create an account Log in

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

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

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