我用这种方式创建了一个Postgres数据库:
createdb massive
然后我添加了一个角色:
sudo -iu postgres
psql -d massive
CREATE ROLE rob WITH SUPERUSER CREATEDB CREATEROLE LOGIN ENCRYPTED PASSWORD 'password';
我使用psql
,然后\q
用户exit
退出postgres
。
现在我尝试登录:
psql -U rob -d massive -h localhost -W
在密码提示下输入password
时,我明白了:
psql: FATAL: password authentication failed for user "rob"
更新
\l
中的 psql
会返回:
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+----------+----------+-------------+-------------+-----------------------
massive | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
postgres | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
template0 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
\du
会返回此信息:
List of roles
Role name | Attributes | Member of
-----------+------------------------------------------------+-----------
postgres | Superuser, Create role, Create DB, Replication | {}
rob | Superuser, Create role, Create DB | {}