All threads / setup Postgres user fails

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

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.

Join the discussion

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

Join 33,665+ 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.

    Ruby on Rails tutorials, guides, and screencasts for web developers learning Ruby, Rails, Javascript, Turbolinks, Stimulus.js, Vue.js, and more. Icons by Icons8

    © 2020 GoRails, LLC. All rights reserved.