Nice programing

Createuser : 데이터베이스 postgres에 연결할 수 없음 : 치명적 : "tom"역할이 없습니다.

nicepro 2020. 10. 13. 19:21
반응형

Createuser : 데이터베이스 postgres에 연결할 수 없음 : 치명적 : "tom"역할이 없습니다.


처음으로 Postgres를 설정하려고하는데 데이터베이스를 읽고 만들 수있는 권한이있는 사용자를 만들어야합니다. 그러나 터미널에서 "createuser username"을 사용하면 다음 메시지가 표시됩니다.

createuser : 데이터베이스 postgres에 연결할 수 없습니다. 치명적 : 역할 "tom"이 없습니다.

Tom은 내가 지금 로그인 한 Ubuntu 사용자 계정입니다. "postgres"라는 사용자 이름을 만든 다음 "psql -U psql template1"을 수행하여 데이터베이스를 만들고 Rails 앱에 대한 소유자를 할당하려고합니다.

도움이 필요하세요?


Ubuntu에 대해 언급 했으므로 Ubuntu에서 apt를 통해 PostgreSQL 패키지를 설치 한 것으로 추측합니다.

그렇다면 postgresPostgreSQL 사용자 계정이 이미 존재하며 peer.NET Framework에서 유닉스 소켓에 대한 인증을 통해 액세스 할 수 있도록 구성되어 있습니다 pg_hba.conf. postgresunix 사용자 로 명령을 실행하면됩니다 . 예 :

sudo -u postgres createuser owning_user
sudo -u postgres createdb -O owning_user dbname

이것은 모두 "Ubuntu PostgreSQL"에 대한 Google의 첫 히트작 인 Ubuntu PostgreSQL 문서에 있으며 수많은 스택 오버플로 질문에서 다룹니다.

(사용중인 OS 및 버전, PostgreSQL 설치 방법 등과 같은 세부 정보를 생략하여이 질문에 답하기가 훨씬 더 어려워졌습니다.)


여기에서 지침과 함께 git gist를 참조하십시오.

이것을 실행하십시오 :

 sudo -u postgres psql

또는

psql -U postgres

Postgres에 들어가기 위해 터미널에서

postgres=#

운영

CREATE USER new_username;

참고 : new_username을 만들려는 사용자로 바꾸십시오 (귀하의 경우 tom이 될 사용자).

postgres=# CREATE USER new_username;
CREATE ROLE

해당 사용자가 DB를 생성 할 수 있도록하려면 역할을 수퍼 유저로 변경해야합니다.

postgres=# ALTER USER new_username SUPERUSER CREATEDB;
ALTER ROLE

확인하기 위해 모든 것이 성공적이었습니다.

postgres=# \du
                         List of roles
 Role name |                   Attributes                   | Member of 
-----------+------------------------------------------------+-----------
new_username     | Superuser, Create DB                           | {}
postgres         | Superuser, Create role, Create DB, Replication | {}
root             | Superuser, Create role, Create DB              | {}

postgres=# 

업데이트 / 수정 (Mac 용) :

최근에 Mac에서 비슷한 오류가 발생했습니다.

psql: FATAL: role "postgres" does not exist

이것은 내 설치가 역할 이름이 로그인 (짧은) 이름과 동일한 데이터베이스 수퍼 유저로 설정 되었기 때문입니다.

그러나 일부 Linux 스크립트는 수퍼 유저가 다음과 같은 기존 역할 이름을 가지고 있다고 가정합니다. postgres

이 문제를 어떻게 해결 했습니까?

다음을 homebrew실행 하여 설치 한 경우 :

/usr/local/Cellar/postgresql/10.5/bin/createuser -s postgres

또는:

/usr/local/Cellar/postgresql/10.5/bin/createuser -s new_username

postgres.appMac 용으로 설치 한 경우 다음을 실행하십시오.

/Applications/Postgres.app/Contents/Versions/10.5/bin/createuser -s postgres

추신 : 10.5를 PostgreSQL 버전으로 교체하십시오.


sudo -u postgres createuser -s tom 

이것은 관리자가 PostgreSQL 사용자 계정을 생성하지 않은 경우 발생하므로 도움이 될 것입니다. 운영 체제 사용자 이름과 다른 PostgreSQL 사용자 이름이 할당되었을 수도 있습니다.이 경우 -U 스위치를 사용해야합니다.


Your error is posted in the official documentation. You can read this article.

I have copied the reason for you (and hyperlinked the URLs) from that article:

This will happen if the administrator has not created a PostgreSQL user account for you. (PostgreSQL user accounts are distinct from operating system user accounts.) If you are the administrator, see Chapter 20 for help creating accounts. You will need to become the operating system user under which PostgreSQL was installed (usually postgres) to create the first user account. It could also be that you were assigned a PostgreSQL user name that is different from your operating system user name; in that case you need to use the -U switch or set the PGUSER environment variable to specify your PostgreSQL user name

For your purposes, you can do:

1) Create a PostgreSQL user account:

sudo -u postgres createuser tom -d -P

(the -P option to set a password; the -d option for allowing the creation of database for your username 'tom'. Note that 'tom' is your operating system username. That way, you can execute PostgreSQL commands without sudoing.)

2) Now you should be able to execute createdb and other PostgreSQL commands.


1- Login as default PostgreSQL user (postgres)

sudo -u postgres -i

2- As postgres user. Add a new database user using the createuser command

[postgres]$ createuser --interactive

3-exit

[postgres]$ exit

I had the same issue, i just do this

sudo su - postgres

createuser odoo -U postgres -dRSP #P for password (odoo or user name that you want o give the postgres access)


On Windows use:

C:\PostgreSQL\pg10\bin>createuser -U postgres --pwprompt <USER>

Add --superuser or --createdb as appropriate.

See https://www.postgresql.org/docs/current/static/app-createuser.html for further options.


You need to first run initdb. It will create the database cluster and the initial setup

See How to configure postgresql for the first time? and http://www.postgresql.org/docs/8.4/static/app-initdb.html

참고URL : https://stackoverflow.com/questions/16973018/createuser-could-not-connect-to-database-postgres-fatal-role-tom-does-not-e

반응형