用户创建
Categories:
创建用户:
CREATE USER june WITH ENCRYPTED PASSWORD 'June123';
创建数据库并授权用户所有权限:
CREATE DATABASE demo;
GRANT ALL PRIVILEGES ON DATABASE demo TO june;
变更数据库所有人:
ALTER DATABASE demo OWNER TO june;
我们也可以在创建数据库的同时,设置数据库所有者:
CREATE DATABASE demo OWNER june;
查看数据库所有者信息:
SELECT
d.datname as "Name",
pg_catalog.pg_get_userbyid(d.datdba) as "Owner"
FROM pg_catalog.pg_database d
WHERE
d.datname = 'demo'
ORDER BY 1;
查看所有数据库的所有者信息(p.s. 可以修改 current_user
变量为具体的用户名):
SELECT
datname,
datdba::regrole::text,
datdba::regrole::text = current_user as current_user_is_owner
from pg_database;
查看当前用户是否有指定 schema 的 xx 权限(p.s. 可以修改 current_user
变量为具体的用户名)
select has_schema_privilege(current_user, 'public', 'create');