CREATE RESOURCE POOL respool1 WITH(except_rule="cpu_percent_except");
资源池支持最多关联63个异常规则集,每个异常规则集间独立生效,互不影响。
4. 创建业务用户usr1,关联资源池respool1:
CREATE USER usr1 RESOURCE POOL "respool1" PASSWORD "XXXXXX";
5. 用户usr1运行作业,作业运行时间超过2000秒且CPU使用率达到30%时触发“cpu_percent_except”异常规则,作业触发异常规则后资源管理对作业进行以下处理:
6. 查询作业黑名单和异常信息:
SELECT * FROM dbms_om.gs_blocklist_query; unique_sql_id | block_list | except_num | except_time---------------+------------+------------+---------------------------- 4066836196 | t | 1 | 2022-08-08 18:00:00.596269(1 row)
7. 用户usr1再次运行作业触发异常熔断,GaussDB(DWS)的异常熔断机制禁止该作业执行。
ERROR: The query is in the blocklist and cannot be run, unique_sql_id(4066836196).HINT: If you want to run the query later, confirm the reason why the query is blocklisted and remove the query from the blocklist after resolving the problem.
8. 优化用户usr1所运行ID为4066836196的SQL后,将ID为4066836196的SQL从黑名单移除。
确认SQL异常原因,如果异常规则配置不合理,修改异常规则;如果异常规则合理,对SQL进行优化后重新运行。确认问题解决后将SQL移除黑名单。
select gs_remove_blocklist(4066836196); gs_remove_blocklist--------------------- t(1 row)
查询过滤器使用作业Unique SQL ID识别和保存黑名单信息,为有效运用查询过滤器紧急拦截功能,建议TopSQL开启,在作业引发CORE、报错、性能下降等问题时可以快速获取作业Unique SQL ID。
获取作业Unique SQL ID的几种方法:
1. 作业引发报错/性能下降
CN日志中获取作业query_id,执行以下命令查询作业Unique SQL ID。
select queryid,unique_sql_id,query from pgxc_wlm_session_info where queryid=query_id;
2. 作业引发CN示例CORE
解析CORE打印内存中保存的Unique SQL ID对应的变量参数值。
3. 作业引发DN实例CORE
作业引发DN实例CORE时,CN侧体现为作业报错,Unique SQL ID获取方式可以参考作业报错时Unique SQL ID获取方式。
4. EXPLAIN VERBOSE获取Unique SQL ID(通用方法,但是仅821及以上版本支持)
EXPLAIN VERBOSE不会实际执行SQL,因此一般不会导致问题发生,使用EXPLAIN VERBOSE XXX;可以打印得到作业Unique SQL ID。示例:
postgres=# explain verbose select count(1) from pg_class; QUERY PLAN------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- id | operation | E-rows | E-distinct | E-width | E-costs ----+----------------------------------------+--------+------------+---------+--------- 1 | -> Aggregate | 2 | | 8 | 52.94 2 | -> Seq Scan on pg_catalog.pg_class | 1034 | | 0 | 50.34 Targetlist Information (identified by plan id) ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 1 --Aggregate Output: count(1) 2 --Seq Scan on pg_catalog.pg_class Output: relname, relnamespace, reltype, reloftype, relowner, relam, relfilenode, reltablespace, relpages, reltuples, relallvisible, reltoastrelid, reltoastidxid, reldeltarelid, reldeltaidx, relcudescrelid, relcudescidx, relhasindex, relisshared, relpersistence, relkind, relnatts, relchecks, relhasoids, relhaspkey, relhasrules, relhastriggers, relhassubclass, relcmprs, relhasclusterkey, relrowmovement, parttype, relfrozenxid, relacl, reloptions, relreplident, relfrozenxid64 ====== Query Summary ===== -------------------------- Parser runtime: 0.027 ms Planner runtime: 0.561 ms Unique SQL Id: 2307078791(17 rows)
获取到作业Unique SQL ID后,调用内置函数gs_append_blocklist(unique_sql_id int8)将作业加入黑名单:
广告
X 关闭
广告
X 关闭