postgres用户管理及权限控制--赋予某账号只读权限

一、 创建一个不带有权限的基本用户    pg_client

点击(此处)折叠或打开

  1. [postgres@v_22 bin]$ ./createuser --interactive pg_client;
    Shall the new role be a superuser? (y/n) n
    Shall the new role be allowed to create databases? (y/n) n
    Shall the new role be allowed to create more new roles? (y/n) n
  2. [postgres@v_22 bin]$ ./psql
    psql (9.3.6)
    Type "help" for help.
  3. postgres=# \du
                                     List of roles
        Role name     |                   Attributes                   | Member of 
    ------------------+------------------------------------------------+-----------
     ctsi_lbs         | Superuser, No inheritance                      | {}
     ctsi_lbs_loc     | Superuser, No inheritance                      | {}
     ctsi_lbs_monitor |                                                | {}
     ctsi_lbs_sms     | Superuser, No inheritance                      | {}
     ispyufabu        | Superuser, No inheritance                      | {}
     newisp           | Superuser, No inheritance                      | {}
     pg_client        |                                                | {}
     postgres         | Superuser, Create role, Create DB, Replication | {}
二、登录账号并赋予pg_client查询表的权限 ,但是在list of roles attributes 并未出现select信息

点击(此处)折叠或打开

  1. [postgres@v_22 bin]$ ./psql 
    psql (9.3.6)
    Type "help" for help.

    postgres=# \l
                                               List of databases
            Name         |      Owner       | Encoding |   Collate   |    Ctype    |   Access privileges   
    ---------------------+------------------+----------+-------------+-------------+-----------------------
     ctsi_lbs_db         | ctsi_lbs         | UTF8     | zh_CN.UTF-8 | zh_CN.UTF-8 | 
     ctsi_lbs_geo_db     | ctsi_lbs         | UTF8     | zh_CN.UTF-8 | zh_CN.UTF-8 | 
     ctsi_lbs_gis_db     | ctsi_lbs         | UTF8     | zh_CN.UTF-8 | zh_CN.UTF-8 | 
     ctsi_lbs_loc_db     | ctsi_lbs_loc     | UTF8     | zh_CN.UTF-8 | zh_CN.UTF-8 | 
     ctsi_lbs_monitor_db | ctsi_lbs_monitor | UTF8     | zh_CN.UTF-8 | zh_CN.UTF-8 | 
     ctsi_lbs_sms_db     | ctsi_lbs_sms     | UTF8     | zh_CN.UTF-8 | zh_CN.UTF-8 | 
     isptest             | ispyufabu        | UTF8     | zh_CN.UTF-8 | zh_CN.UTF-8 | 
     newisp              | newisp           | UTF8     | zh_CN.UTF-8 | zh_CN.UTF-8 | 
     postgres            | postgres         | UTF8     | zh_CN.UTF-8 | zh_CN.UTF-8 | 
     template0           | postgres         | UTF8     | zh_CN.UTF-8 | zh_CN.UTF-8 | =c/postgres          +
                         |                  |          |             |             | postgres=CTc/postgres
     template1           | postgres         | UTF8     | zh_CN.UTF-8 | zh_CN.UTF-8 | =c/postgres          +
                         |                  |          |             |             | postgres=CTc/postgres

  2. [postgres@v_22 bin]$ ./psql -U ctsi_lbs -d ctsi_lbs_db
  3. ctsi_lbs_db=#  grant select  on all tables in schema public to pg_client;
    GRANT
  4. ctsi_lbs_db=> \du
                                     List of roles
        Role name     |                   Attributes                   | Member of 
    ------------------+------------------------------------------------+-----------
     ctsi_lbs         | Superuser, No inheritance                      | {}
     ctsi_lbs_loc     | Superuser, No inheritance                      | {}
     ctsi_lbs_monitor |                                                | {}
     ctsi_lbs_sms     | Superuser, No inheritance                      | {}
     ispyufabu        | Superuser, No inheritance                      | {}
     newisp           | Superuser, No inheritance                      | {}
     pg_client        |                                                | {}
     postgres         | Superuser, Create role, Create DB, Replication | {}

三、登录pg_client账号,验证权限是否成功

点击(此处)折叠或打开

  1. [postgres@v_22 bin]$ ./psql -U pg_client -d ctsi_lbs_db 
  2. psql (9.3.6)
    Type "help" for help.


    ctsi_lbs_db=> \dt
                   List of relations
     Schema |        Name        | Type  |  Owner   
    --------+--------------------+-------+----------
     public | auto_loc_mdn       | table | postgres
     public | auto_location      | table | postgres
     public | ent_billing_file   | table | postgres
     public | last_location      | table | postgres
     public | loc_db_config      | table | postgres
     public | loc_status         | table | postgres
     public | location_navigator | table | postgres
    (7 rows)


    ctsi_lbs_db=> select * from loc_status;
     loc_code |                           definition                           | scene | remark 
    ----------+----------------------------------------------------------------+-------+--------
            0 | 成功                                                           |       | 
            1 | 基础定位平台异常                                               |       | 
            2 | 基础定位平台繁忙或超出定位请求上限                             |       | 
            3 | 核心网忙而无法处理请求                                         |       | 
            4 | SPID鉴权失败(SPID不存在或IP地址不存在或状态错误)             |       | 
            5 | SPID密码错误                                                   |       | 
            6 | 请求包中号码超过限制                                           |       | 
            7 | 请求包格式有问题                                               |       | 
            8 | 请求包的语法不对                                               |       | 
            9 | 定位时超出定位请求上限                                         |       | 
           10 | 取消周期定位消息时reqid不存在                                  |       | 
           11 | 未知的MSID                                                     |       | 
           12 | 回叫号码未知                                                   |       | 
           13 | 无效的请求信息                                                 |       | 
           14 | 返回的是手机的信道信息                                         |       | 
           15 | 未检测到信号                                                   |       | 
           16 | PDE超时                                                        |       | 
           17 | 位置未确定                                                     |       | 
           18 | 返回的是TDMA MAHO信息                                          |       | 
           19 | TDMA MAHO信息不可得达                                          |       | 
  3. ctsi_lbs_db=> update loc_status set loc_code = 300 where loc_code= 0;
    ERROR:  permission denied for relation loc_status
    ctsi_lbs_db=> insert into loc_status  values ( 300,'hello',null ,null);
    ERROR:  permission denied for relation loc_status
    ctsi_lbs_db=> 


四、验证pg_client 用户属性

点击(此处)折叠或打开

  1. ctsi_lbs_db=> SELECT * from pg_roles;
         rolname      | rolsuper | rolinherit | rolcreaterole | rolcreatedb | rolcatupdate | rolcanlogin | rolreplication | rolconnlimit | rolpassword | rolvaliduntil | rolconfig |  oid  
    ------------------+----------+------------+---------------+-------------+--------------+-------------+----------------+--------------+-------------+---------------+-----------+-------
     postgres         | t        | t          | t             | t           | t            | t           | t              |           -1 | ********    |               |           |    10
     ctsi_lbs         | t        | f          | f             | f           | t            | t           | f              |           -1 | ********    |               |           | 16389
     ctsi_lbs_loc     | t        | f          | f             | f           | t            | t           | f              |           -1 | ********    |               |           | 16390
     ispyufabu        | t        | f          | f             | f           | t            | t           | f              |           -1 | ********    |               |           | 16428
     ctsi_lbs_sms     | t        | f          | f             | f           | t            | t           | f              |           -1 | ********    |               |           | 17220
     ctsi_lbs_monitor | f        | t          | f             | f           | f            | t           | f              |           -1 | ********    |               |           | 36755
     newisp           | t        | f          | f             | f           | t            | t           | f              |           -1 | ********    |               |           | 36944
     pg_client        | f        | t          | f             | f           | f            | t           | f              |           -1 | ********    |               |           | 38510
    (8 rows)


    ctsi_lbs_db=> 






来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/27039319/viewspace-2079613/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/27039319/viewspace-2079613/

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值