Rails and PostgreSQL: Role postgres does not exist

前端 未结 13 2159
一整个雨季
一整个雨季 2020-12-07 07:51

I have installed PostgreSQL on my Mac OS Lion, and am working on a rails app. I use RVM to keep everything separate from my other Rails apps.

For some reason when I

相关标签:
13条回答
  • 2020-12-07 08:32

    My answer was much more simple. Just went to the db folder and deleted the id column, which I had tried to forcefully create, but which is actually created automagically. I also deleted the USERNAME in the database.yml file (under the config folder).

    0 讨论(0)
  • 2020-12-07 08:33

    I met this issue right on when I first install the Heroku's POSTGRES.app thing. After one morning trial and error i think this one line of code solved problem. As describe earlier, this is because postgresql does not have default role the first time it is set up. And we need to set that.

    sovanlandy=# CREATE ROLE postgres LOGIN;
    

    You must log in to your respective psql console to use this psql command.

    Also noted that, if you already created the role 'postgre' but still get permission errors, you need to alter with command:

    sovanlandy=# ALTER ROLE postgres LOGIN;
    

    Hope it helps!

    0 讨论(0)
  • 2020-12-07 08:36

    I ended up here after attempting to follow Ryan Bate's tutorial on deploying to AWS EC2 with rubber. Here is what happened for me: We created a new app using "

    rails new blog -d postgresql

    Obviosuly this creates a new app with pg as the database, but the database was not made yet. With sqlite, you just run rake db:migrate, however with pg you need to create the pg database first. Ryan did not do this step. The command is rake db:create:all, then we can run rake db:migrate

    The second part is changing the database.yml file. The default for the username when the file is generated is 'appname'. However, chances are your role for postgresql admin is something different (at least it was for me). I changed it to my name (see above advice about creating a role name) and I was good to go.

    Hope this helps.

    0 讨论(0)
  • 2020-12-07 08:42

    I was on OSX 10.8, and everything I tried would give me the FATAL: role "USER" does not exist. Like many people said here, run createuser -s USER, but that gave me the same error. This finally worked for me:

    $ sudo su
    # su postgres
    # createuser -s --username=postgres MYUSERNAME
    

    The createuser -s --username=postgres creates a superuser (-s flag) by connecting as postgres (--username=postgres flag).

    I see that your question has been answered, but I want to add this answer in for people using OSX trying to install PostgreSQL 9.2.4.

    0 讨论(0)
  • 2020-12-07 08:44

    In Ubuntu local user command prompt, but not root user, type

    sudo -u postgres createuser username

    username above should match the name indicated in the message "FATAL: role 'username' does not exist."

    Enter password for username.

    Then re-enter the command that generated role does not exist message.

    0 讨论(0)
  • 2020-12-07 08:44

    You might be able to workaround this by running initdb -U postgres -D /path/to/data or running it as user postgres, since it defaults to the current user. GL!

    0 讨论(0)
提交回复
热议问题