EDB xDB need pg_authid.rolcatupdate ?

本文涉及的产品
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
云原生数据库 PolarDB MySQL 版,Serverless 5000PCU 100GB
云原生数据库 PolarDB 分布式版,标准版 2核8GB
简介:

PostgreSQL 9.5以前的版本,pg_authid有个字段rolcatupdate,用来标记用户是否有更新catalog的权限。 如果rolcatupdate=false,即使是超级用户也不能更新catalog。
但是在9.5以后,这个字段被删掉了,如下commit:
http://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=bb8582abf3c4db18b508627a52effd43672f9410

Remove rolcatupdate

This role attribute is an ancient PostgreSQL feature, but could only be
set by directly updating the system catalogs, and it doesn't have any
clearly defined use.

Author: Adam Brightwell <adam.brightwell@crunchydatasolutions.com>

因此你在9.5的版本看不到pg_authid的字段rolcatupdate了。
然而EDB有个用来增量同步Oracle, PostgreSQL数据的工具xDB,这个工具需要用到这个权限,更新pg_class.relhastriggers字段来禁用触发器。
例子:

digoal=# create table tab(id int);
CREATE TABLE
digoal=# create or replace function tg() returns trigger as 
$$

digoal$# declare
digoal$# begin
digoal$#   raise notice 'trigged';
digoal$#   return null;
digoal$# end;
digoal$# 
$$
 language plpgsql strict;
CREATE FUNCTION
digoal=# create trigger tg after insert on tab for each row execute procedure tg();
CREATE TRIGGER
digoal=# insert into tab values (1);
NOTICE:  trigged
INSERT 0 1

更新pg_class.relhastriggers = false,就看不到这个触发器了。

digoal=# update pg_class set relhastriggers =false where relname='tab';
UPDATE 1
digoal=# insert into tab values (1);
INSERT 0 1
digoal=# insert into tab values (2);
INSERT 0 1
digoal=# insert into tab values (3);
INSERT 0 1
digoal=# \d+ tab
                         Table "public.tab"
 Column |  Type   | Modifiers | Storage | Stats target | Description 
--------+---------+-----------+---------+--------------+-------------
 id     | integer |           | plain   |              | 

digoal=# update pg_class set relhastriggers =true where relname='tab';
UPDATE 1
digoal=# \d+ tab
                         Table "public.tab"
 Column |  Type   | Modifiers | Storage | Stats target | Description 
--------+---------+-----------+---------+--------------+-------------
 id     | integer |           | plain   |              | 
Triggers:
    tg AFTER INSERT ON tab FOR EACH ROW EXECUTE PROCEDURE tg()

使用这种语法也可禁用触发器

digoal=# alter table tab disable trigger tg;
ALTER TABLE
digoal=# \d+ tab
                         Table "public.tab"
 Column |  Type   | Modifiers | Storage | Stats target | Description 
--------+---------+-----------+---------+--------------+-------------
 id     | integer |           | plain   |              | 
Disabled user triggers:
    tg AFTER INSERT ON tab FOR EACH ROW EXECUTE PROCEDURE tg()

这种方法禁用触发器实际上是改动pg_trigger.tgenabled

digoal=# \d pg_trigger
       Table "pg_catalog.pg_trigger"
     Column     |     Type     | Modifiers 
----------------+--------------+-----------
 tgrelid        | oid          | not null
 tgname         | name         | not null
 tgfoid         | oid          | not null
 tgtype         | smallint     | not null
 tgenabled      | "char"       | not null
 tgisinternal   | boolean      | not null
 tgconstrrelid  | oid          | not null
 tgconstrindid  | oid          | not null
 tgconstraint   | oid          | not null
 tgdeferrable   | boolean      | not null
 tginitdeferred | boolean      | not null
 tgnargs        | smallint     | not null
 tgattr         | int2vector   | not null
 tgargs         | bytea        | not null
 tgqual         | pg_node_tree | 
Indexes:
    "pg_trigger_oid_index" UNIQUE, btree (oid)
    "pg_trigger_tgrelid_tgname_index" UNIQUE, btree (tgrelid, tgname)
    "pg_trigger_tgconstraint_index" btree (tgconstraint)

digoal=# insert into tab values (2);
INSERT 0 1
digoal=# alter table tab enable trigger tg;
ALTER TABLE
digoal=# insert into tab values (2);
NOTICE:  trigged
INSERT 0 1

赋予普通用户alter table enable|disable trigger的权限

digoal=# grant trigger on table tab to digoal;
GRANT
digoal=# \c digoal digoal
digoal=# alter table tab disable trigger tg;
ALTER TABLE
相关实践学习
使用PolarDB和ECS搭建门户网站
本场景主要介绍基于PolarDB和ECS实现搭建门户网站。
阿里云数据库产品家族及特性
阿里云智能数据库产品团队一直致力于不断健全产品体系,提升产品性能,打磨产品功能,从而帮助客户实现更加极致的弹性能力、具备更强的扩展能力、并利用云设施进一步降低企业成本。以云原生+分布式为核心技术抓手,打造以自研的在线事务型(OLTP)数据库Polar DB和在线分析型(OLAP)数据库Analytic DB为代表的新一代企业级云原生数据库产品体系, 结合NoSQL数据库、数据库生态工具、云原生智能化数据库管控平台,为阿里巴巴经济体以及各个行业的企业客户和开发者提供从公共云到混合云再到私有云的完整解决方案,提供基于云基础设施进行数据从处理、到存储、再到计算与分析的一体化解决方案。本节课带你了解阿里云数据库产品家族及特性。
相关文章
|
4天前
|
SQL 关系型数据库 数据库连接
`pg_dump` 和 `pg_restore`
`pg_dump` 和 `pg_restore`
29 4
|
6月前
|
JSON 关系型数据库 数据安全/隐私保护
PG
MYSQL VS PG
257 0
|
10月前
|
关系型数据库
pg为什么...?
pg为什么...?
23 0
|
关系型数据库
备份工具pg_dump的使用《postgres》
备份工具pg_dump的使用《postgres》
294 0
|
SQL 安全 关系型数据库
pg_dump
备份PostgreSQL数据库的工具,它甚至可以在数据库正在并发使用时进行完整一致的备份,而不会阻塞其它用户对数据库的访问。该工具生成的转储格式可以分为两种,脚本和归档文件。
162 0
|
Oracle 关系型数据库 数据库
|
SQL 关系型数据库 Java
【DB吐槽大会】第5期 - PG local memory
大家好,这里是DB吐槽大会,第5期 - PG local memory
|
关系型数据库 API 数据库
PostgreSQL pg_start_backup
本文探讨 pg_start_backup命令的连续归档备份
1451 0
PostgreSQL pg_start_backup
|
关系型数据库 数据库 PostgreSQL
Postgresql pg_dump&pg_restore用法
PostgreSQL提供的一个工具pg_dump,逻辑导出数据,生成sql文件或其他格式文件,pg_dump是一个客户端工具,可以远程或本地导出逻辑数据,恢复数据至导出时间点。pg_dump 一次只转储一个数据库, 并且不会转储有关角色或表空间的信息 (因为那些是群集范围而不是每个数据库)。
11244 0