005-创建用户并授权表访问权限

创建用户并授权表访问权限

创建用户 ttom,授权权限的数据库 factory。

  • 创建用户
    create user ttom with password 'aaa';

  • 授予用户数据库权限
    grant all privileges on database factory to ttom;

  • 授予用户表所有权限
    grant all privileges on all tables in schema public to ttom;

  • 授予用户表查看权限
    grant select on all tables in schema public to ttom;

  • 单独授予某个表查看权限
    grant select on table mytable to ttom;


  • 取消某个表的查看权限
    revoke select on mytable from ttom;

完整创建用户到授权

-- 创建用户
create user user1 with password '123';

-- 授予连接权限
grant connect on database factory to user1;

-- 取消新用户查看系统表的权限
revoke all on pg_class from public;
revoke all on pg_tablespace from public;
revoke all on pg_user from public;
revoke all on pg_roles from public;

-- 赋予 schema 使用权限
grant usage on schema public to user1;

-- 授予查看表权限
grant select on all tables in schema public to user1;

-- 重新赋予 schema 权限
grant all on pg_class to public;
grant all on pg_tablespace to public;
grant all on pg_user to public;
grant all on pg_roles to public;


-- 删除用户需先清空权限
revoke all on database schema_01 from user1;
revoke all on mytable from user1;
-- 将权限转移到其他用户
alter table mytable owner to userx;
drop user user1;
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值