数据仓库服务 GAUSSDB(DWS)-ALTER DEFAULT PRIVILEGES:示例

时间:2024-01-26 16:15:18

示例

  • 将创建在模式tpcds里的所有表(和视图)的SELECT权限授予每一个用户:
    1
    ALTER DEFAULT PRIVILEGES IN SCHEMA tpcds GRANT SELECT ON TABLES TO PUBLIC;
    
  • 将tpcds下的所有表的插入权限授予用户jack:
    1
    ALTER DEFAULT PRIVILEGES IN SCHEMA tpcds GRANT INSERT ON TABLES TO jack;
    
  • 撤销上述权限:
    1
    2
    ALTER DEFAULT PRIVILEGES IN SCHEMA tpcds REVOKE SELECT ON TABLES FROM PUBLIC; 
    ALTER DEFAULT PRIVILEGES IN SCHEMA tpcds REVOKE INSERT ON TABLES FROM jack;
    
  • 假设有两个用户test1、test2,如果想要test2用户对test1用户未来创建的表都有查询权限可以用如下操作:
    • 首先,把test1的schema的权限赋权给test2用户:
      1
      grant usage, create on schema test1 to test2;
      
    • 其次,把test1用户下的表的查询权限赋值给test2用户:
      1
      ALTER DEFAULT PRIVILEGES FOR USER test1 IN SCHEMA test1 GRANT SELECT ON tables TO test2;
      
    • 然后,test1用户创建表:
      1
      2
      set role test1 password '{password}';
      create table test3( a int, b int);
      
    • 最后,用test2用户去查询:
      1
      2
      3
      4
      5
      set role test2 password '{password}';
      select * from test1.test3;
       a | b
      ---+---
      (0 rows)
      
support.huaweicloud.com/sqlreference-820-dws/dws_06_0244.html