2017-12-29 6 views
0

コード:のPostgres:役割を作成し、psqlでログイン-U役割

postgres=# create role hello; 
CREATE ROLE 
postgres=# \du 
          List of roles 
Role name |     Attributes     | Member of 
-----------+------------------------------------------------+----------- 
hello  | Cannot login         | {} 
postgres | Superuser, Create role, Create DB, Replication | {} 

postgres=# ALTER ROLE hello WITH LOGIN; 
ALTER ROLE 
postgres=# ALTER ROLE hello WITH CREATEDB; 
ALTER ROLE 
postgres=# \du 
          List of roles 
Role name |     Attributes     | Member of 
-----------+------------------------------------------------+----------- 
hello  | Create DB          | {} 
postgres | Superuser, Create role, Create DB, Replication | {} 

postgres=# ALTER ROLE hello WITH PASSWORD '123'; 
ALTER ROLE 
postgres=# \q 
-bash-4.2$ logout 
[[email protected] test_user]# psql -U hello 
Password for user hello: 
psql: FATAL: database "hello" does not exist 

私はCREATE ROLEでPostgresの中helloという名前のロールを作成しようと、それはログインするための権限です変更し、データベースを作成しています。しかし、私が-Uでログインしようとすると、それは私に上記を示しています。 -Uの私の理解は間違っていますか?デフォルトでは

+1

データベース 'hello'を作成していません – Mekicha

+0

ロールを作成すると、その名前のデータベースが必要ですか? – wonder

+0

はい。 Postgresはそれを期待しています – Mekicha

答えて