-- 首先创建一个用户 user01 test=# createuser user01 with password 'kingbase'; CREATE ROLE
-- 查看 user01 的用户权限 test=# \dg user01 List of roles Role name | Attributes |Memberof -----------+------------+----------- user01 || {}
-- 连接用户 user01 test=# \c test user01 Password foruser user01:
You are now connected to database "test" as userName "user01". test=>
-- 尝试创建数据库 scott 报错,没有创建数据库的权限,由此可见,必须要对普通用户授权创建数据库权限才可以创建数据库 scott test=>create database scott; ERROR: 创建数据库权限不够
-- 使用 system 用户进行授权 test=> \c test system Password forusersystem:
You are now connected to database "test" as userName "system". test=# alteruser user01 createdb; ALTER ROLE
-- 查看 user01 权限 test=# \dg user01 List of roles Role name | Attributes |Memberof -----------+------------+----------- user01 |Create DB | {}
-- 再次创建数据库 scott 成功 test=# \c test user01 Password foruser user01:
You are now connected to database "test" as userName "user01". test=>create database scott; CREATE DATABASE
由上可知,user01 具有 createdb 权限,才可以创建 scott 数据库,所以选项 1 是正确的。
2、用户 user01 是数据库 scott 的拥有者:
1 2 3 4 5
test=> \l scott List of databases Name | Owner | Encoding |Collate| Ctype | Access privileges -------+--------+----------+---------+-------+------------------- scott | user01 | GBK | C | C |
查看数据库 scott 的信息,拥有者确实是 user01。
3、超级用户 system 是否可以直接删除数据库 scott:
1 2 3 4 5 6
test=> \c test system Password forusersystem:
You are now connected to database "test" as userName "system". test=# drop database scott; DROP DATABASE
-- 第一种情况,数据库 scott 已被删除的情况,删除 user01 成功 test=> \c test system Password forusersystem:
You are now connected to database "test" as userName "system". test=# drop database scott; DROP DATABASE test=# dropuser user01; DROP ROLE
-- 第二种情况,数据库 scott 未被删除的情况,删除 user01 失败 test=# createuser user01 with password 'kingbase'; CREATE ROLE test=# alteruser user01 createdb; ALTER ROLE test=# \c test user01 Password foruser user01:
You are now connected to database "test" as userName "user01". test=>create database scott; CREATE DATABASE -- 使用 system 删除用户 user01 test=> \c test system Password forusersystem:
You are now connected to database "test" as userName "system". test=# dropuser user01; ERROR: 无法删除"user01"因为有其它对象倚赖它 DETAIL: 数据库 scott的属主
本题考察我们的应该是用户 user01 存在数据库 scott 时,使用 system 删除用户是否成功,所以明显是无法删除的。由此可知,Kingbase 数据库的用户如果有依赖的对象存在,则无法删除,必须要将依赖的对象删除或者移走才可以删除用户:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
-- 将 scott 数据库移动到 system 用户下 test=# alter database scott owner tosystem; ALTER DATABASE test=# test=# \l scott List of databases Name | Owner | Encoding |Collate| Ctype | Access privileges -------+--------+----------+---------+-------+------------------- scott |system| GBK | C | C | (1row)
-- 再次删除用户 user01 成功 test=# \conninfo You are connected to database "test" asuser "system" on host "localhost" (address "::1") at port "54321". test=# dropuser user01; DROP ROLE