1. 问题(故障)描述

ERROR:  permission denied for schema zcbus
LINE 1: insert into zcbus.ddl_event_tbl(event, tag, objid, object_ty...
                    ^
QUERY:  insert into zcbus.ddl_event_tbl(event, tag, objid, object_type, schema_name, object_identity, query)  
        values(TG_EVENT, TG_TAG, r.objid, r.object_type, r.schema_name, r.object_identity, v1)
CONTEXT:  PL/pgSQL function zcbus.zcbus_func_ddl_command() line 11 at SQL statement

2. 问题(故障)原因

  • 发布账号,需要建立触发器捕获DDL,并记录DDL到对应ZCBUS的ddl_event_tbl中,,其他业务用户没有对这个表的操作权限。需要将此表写权限付给所有的其他业务账号

3. 解决

  • 需给业务用户赋予如下权限
 GRANT USAGE ON SCHEMA zcbus TO <业务用户>;
 GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA zcbus TO <业务用户>;

4. 参考

  • 建议在创建事件触发器后通过以下SQL查询数据库里所有的用户,给其赋予以上两个权限。
 SELECT
    r.rolname,
    r.rolsuper,
    r.rolcreaterole,
    r.rolcreatedb,
    r.rolcanlogin,
    r.rolreplication,
    r.rolinherit,
    r.rolconnlimit,
    ARRAY(SELECT b.rolname
          FROM pg_catalog.pg_auth_members m
          JOIN pg_catalog.pg_roles b ON (m.roleid = b.oid)
          WHERE m.member = r.oid) as memberof
FROM pg_catalog.pg_roles r
ORDER BY 1;
文档更新时间: 2025-01-02 14:23   作者:阿力