解决“psycopg2.errors.InsufficientPrivilege: permission denied for table”问题

42 篇文章 3 订阅
34 篇文章 2 订阅

    今天在写入PostgreSQL的dapp_namemap表格时,报"psycopg2.errors.InsufficientPrivilege: permission denied for table"错误,如图(1)所示。

    问题原因:当前用户hello对表格没有读写权限,如表格(1)所示。
    解决方法:使用超级用户,进入表格所在的数据库,然后对当前用户授予读写权限。
    详细如下:

名称类型权限
postgres超级用户全部权限
hello普通用户仅有登录权限,没有读写权限
hellodb数据库
dapp_namemap表格
表(1) helloy用户没有读写权限

    这里是以超级用户postgres授予hello用户,拥有对hellodb数据库下所有表格的读写权限为例进行说明。

1 超级用户登录指定数据库

    使用超级用户postgres,登录指定的数据库(根据自己的情况按需指定),本案例的DB是hellodb,注意,不要登录默认的数据库PG,否则就缘木求鱼了。如果登录了默认的数据库,就是默认数据库PG对hello用户的授权,而不是hellodb数据库对hello用户的授权。

psql -U postgres -d hellodb

2 授予hello用户读写权限

grant usage on schema public to hello;
grant all privileges on all tables in schema public to hello;
grant all privileges on all sequences in schema public to hello;
grant select,insert,update,delete on all tables in schema public to hello;
grant all on schema public to hello;

    如图(2)所示:

图(2) 登录指定的数据库,并授权

3 查询权限

    使用命令,查询hello的权限

select * from information_schema.table_privileges where grantee='hello';

    效果如下:

图(3) 授权成功

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值