Programing

Rails 및 PostgreSQL : 역할 postgres가 존재하지 않습니다.

lottogame 2020. 8. 12. 22:09
반응형

Rails 및 PostgreSQL : 역할 postgres가 존재하지 않습니다.


Mac OS Lion에 PostgreSQL을 설치했으며 Rails 앱에서 작업 중입니다. RVM을 사용하여 모든 것을 다른 Rails 앱과 별도로 유지합니다.

어떤 이유로 처음으로 db를 마이그레이션하려고 할 때 rake가 postgres 사용자를 찾을 수 없습니다. 오류가 발생합니다

 FATAL:  role "postgres" does not exist

pgAdmin이 있으므로 DB에 postgres 사용자 (사실 관리자 계정)가 있음을 분명히 알 수 있으므로 다른 작업을 수행해야할지 모르겠습니다.

PostgreSQL이 설치된 경로로 인해 PostgreSQL에 문제가있는 사람들에 대해 어딘가에서 읽었지만 db를 찾을 수 없다면 그렇게 멀리 가지 않았을 것이라고 생각합니다.


이 메시지는 데이터베이스 사용자가 존재하지 않을 때 나타납니다. 여기 에서 설명서를 비교 하십시오 .
여러 로컬 데이터베이스 설명이 될 수 없습니다 . 역할은 클러스터 전체에서 유효합니다. 설명서를 다시 :

역할은 데이터베이스 클러스터 수준에서 정의되므로 클러스터의 모든 데이터베이스에서 유효합니다.

다른 데이터베이스 클러스터 에 있어야 합니다 . 이는 동일한 시스템에서 실행되는 다른 서버이며 다른 포트를 수신합니다. 또는 다른 컴퓨터에서 가능합니다.

메시지가 실제로 원격 서버에서 오는 것일 수 있습니까?


사실 알 수없는 이유로 postgresql 역할이 생성되지 않았기 때문에 문제가 발생했습니다.

다음을 실행 해보십시오.

createuser -s -r postgres

역할은 PostgreSQL이 데이터베이스 권한을 유지 하는 방식입니다 . postgres 사용자에 대한 역할이 없으면 아무 것도 액세스 할 수 없습니다. createuser 명령은 CREATE USER, CREATE ROLE 등의 명령을 둘러싼 얇은 래퍼입니다 .


최근에 postgres를 설치 한 직후이 문제가 발생했습니다. 설치 직후에 오는 경우 기본 사용자 인 postgres가 누락되었을 수 있습니다. 이 경우 아래 명령을 사용하여 기본 사용자 postgres를 만들 수 있습니다.

createuser -s -U $ USER

Ex: createuser -s -U $USER
enter your required role name: postgres
enter password for your the user: 

필요한 데이터베이스 역할 이름과 암호를 입력하라는 메시지가 표시됩니다. 프로세스를 완료하면 아래 명령을 사용하여 postgres 콘솔에 로그인 할 수 있습니다.

psql -U 'your_database_name'

예 : psql -U postgres
여기에서 사용자를 생성하는 동안 암호를 입력 한 경우 암호를 입력해야합니다.

도움이되기를 바랍니다 :)


나는 OSX 10.8을 사용했고 내가 시도한 모든 것이 나에게 FATAL: role "USER" does not exist. 많은 사람들이 여기에서 말했듯이 실행 createuser -s USER하지만 동일한 오류가 발생했습니다. 이것은 마침내 나를 위해 일했습니다.

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

createuser -s --username=postgres포스트 그레스로 (--username = POSTGRES 플래그)를 연결하여 유저 (-s 플래그)를 생성한다.

귀하의 질문에 대한 답변이 확인되었지만 PostgreSQL 9.2.4를 설치하려는 OSX 사용자를 위해이 답변을 추가하고 싶습니다.


Heroku의 POSTGRES.app을 처음 설치할 때 바로이 문제를 만났습니다. 어느 날 아침 시행 착오 후에 나는이 한 줄의 코드가 문제를 해결했다고 생각합니다. 앞에서 설명한 것처럼 postgresql을 처음 설정할 때 기본 역할이 없기 때문입니다. 그리고 우리는 그것을 설정해야합니다.

sovanlandy=# CREATE ROLE postgres LOGIN;

이 psql 명령을 사용하려면 각 psql 콘솔에 로그인해야합니다.

또한 이미 'postgre'역할을 생성했지만 여전히 권한 오류가 발생하는 경우 다음 명령으로 변경해야합니다.

sovanlandy=# ALTER ROLE postgres LOGIN;

도움이 되었기를 바랍니다.


Heroku 문서에서; 시작하기 whit rails 4는 다음과 같이 말합니다.

사용자 이름 필드가있는 경우 database.yml에서 제거해야합니다. config / database.yml 파일에서 제거 : 사용자 이름 : myapp

그런 다음 "development :"에서 해당 줄을 삭제합니다. pg가 "myapp"역할에서 작동하는 데이터베이스에 알리지 않으면

이 줄은 myapp_development 데이터베이스가 myapp의 역할로 실행되어야 함을 rails에 알려줍니다. 데이터베이스에이 역할이 없을 가능성이 높으므로 제거합니다. 줄을 제거하면 Rails는 현재 컴퓨터에 로그인 한 사용자로 데이터베이스에 액세스하려고합니다.

또한 개발 용 데이터베이스를 만들어야합니다.

$createdb myapp_development

Repleace "myapp" for your app name


Could you have multiple local databases? Check your database.yml and make sure you are hitting the pg db that you want. Use rails console to confirm.


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


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.


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.


After a bunch of installing and uninstalling of Postgres, here's what now seems to work consistently for me with Os X Mavericks, Rails 4 and Ruby 2.

  1. In the database.yml file, I change the default usernames to my computer's username which for me is just "admin".

  2. In the command line I run rake db:create:all

  3. Then I run rake db:migrate

  4. When I run the rails server and check the local host it says "Welcome aboard".


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!


The installation procedure creates a user account called postgres that is associated with the default Postgres role. In order to use Postgres, you can log into that account. But the rails app looks for a different role, more particularly the role having your unix username which might not be created in the postgres roles.

To overcome that, you can create a new role, first by switching over to the default role postgres which was created during installation

sudo -i -u postgres

After you are logged in to the postgres account, you can create a new user by typing:

createuser --interactive

This will prompt you with some choices and, based on your responses, execute the correct Postgres commands to create a user.

Pass over a role name and some permissions and the role is created, you can then migrate your db

참고URL : https://stackoverflow.com/questions/7863770/rails-and-postgresql-role-postgres-does-not-exist

반응형