首页 > 数据库 >【数仓运维实践】关于GaussDB(DWS)单SQL磁盘空间管控

【数仓运维实践】关于GaussDB(DWS)单SQL磁盘空间管控

时间:2023-03-23 11:33:43浏览次数:65  
标签:DWS ACCOUNT CODE 运维 数仓 PL TYPE E100119 PROJ

摘要:本文主要讲解数仓运维中遇到单SQL磁盘空间管控问题的解析和方案。

本文分享自华为云社区《GaussDB(DWS)运维 -- 单SQL磁盘空间管控》,作者: 譡里个檔。

【问题描述】

执行部分SQL语句时出现如下报错信息(具体数值可能因为配置有差异),本文针对根因和场景触发场景,确定触发此类问题的根因

The space used on DN (209715224 kB) has exceeded the sql use space limit (209715200 kB)

【问题根因】

该报错表示用户执行的sql在单DN上所用空间超过了参数sql_use_spacelimit的限制。sql_use_spacelimit限制单个SQL在单个DN上,触发落盘操作时,落盘文件的空间大小,管控的空间包括普通表、临时表以及中间结果集落盘占用的空间

可以使用如下SQL查看所有实例上的配置参数sql_use_spacelimit的值

SELECT * FROM pgxc_settings WHERE name = 'sql_use_spacelimit';

【解决方案】

当前现网最常见的此类错误一般都是INERT语句触发的,我们以常见如下语句为例,说明这类问题的解决方案

INSERT INTO dwljaa.bif_col_edw_dut_257_t
(attribute1, attribute2, attribute3, attribute4, attribute5, column_name1, column_name2, 
column_name3, column_name4, column_name5, tag_code, tag_id, table_name, period, tbl_code, 
tag_grp_code, target_key_val, cycle_id, creation_date, target_key_num, priority)
SELECT 
 'SCN_SVC_3003', NULL, NULL, NULL, NULL, 'BIZ_SCR_CODE', NULL, NULL, NULL, NULL,
 'SCN_SVC_3003-02', 3026937, 'dwr_fin_hwip_man_je_f_tmp0', '202208', 'PL_E17360237',
 'SUB_PL_PUB_SCN', A.record_seq_num, 20230321000000, SYSDATE, A.record_seq_num, 53333
FROM (SELECT /*+PARALLEL(8) NO_EXPAND*/ T.record_seq_num
 FROM dwljaa.dwr_fin_hwip_man_je_f_tmp0 T
 INNER JOIN dwrdim.dwr_dim_department_d PL_E100134 ON T.COA_DEPT_KEY = PL_E100134.DEPT_KEY
 INNER JOIN dwrdim.dwr_dim_grp_acct_code_d PL_E100119 ON T.GROUP_ACCOUNT_CODE = PL_E100119.GROUP_ACCOUNT_CODE
 INNER JOIN dwrdim.dwr_dim_journal_category_d PL_E100147 ON T.JE_CATEGORY_ID = PL_E100147.JE_CATEGORY_ID
 INNER JOIN dwrdim.dwr_dim_product_d PL_E100121 ON T.MAJOR_PROD_KEY = PL_E100121.PROD_KEY
 INNER JOIN dwrdim.dwr_dim_product_d PL_E100122 ON T.MINOR_PROD_KEY = PL_E100122.PROD_KEY
 INNER JOIN dwrdim.dwr_dim_project_d PL_E100155 ON T.PROJ_KEY = PL_E100155.PROJ_KEY
 WHERE 1 = 1 AND ((((((((((PL_E100119.LVL1_ACCOUNT_CODE IN('501', '503', '506', '512')) OR(PL_E100119.GROUP_ACCOUNT_CODE = '5980406')) AND((PL_E100121.PROD_CLASS_FLAG = '0') OR(PL_E100122.PROD_CLASS_FLAG = '0'))) OR((PL_E100119.LVL1_ACCOUNT_CODE IN('504', 'SVC')) OR(PL_E100119.LVL2_ACCOUNT_CODE IN('55107', '57702', '57703', '58303')) OR(PL_E100119.GROUP_ACCOUNT_CODE IN('5980407', '5825107', '5827702', '5827703', 'C501'))) OR((PL_E100119.ACCOUNT_EXPENSE_CATG_CODE IN('E01', 'E03', 'E05', 'E06', 'E08', 'E09', 'E10', 'E11', 'E02', 'E04', 'E07', 'E12')) AND(PL_E100134.DEPT_EXPENSE_TYPE_CODE = 'Z4') AND((PL_E100155.PROJ_TYPE_CODE <> '02') OR(PL_E100155.PROJ_NUM IN('9000000')))) OR((PL_E100119.ACCOUNT_EXPENSE_CATG_CODE IN('E02', 'E04', 'E07', 'E12', 'E05', 'E09', 'E10')) AND(PL_E100134.DEPT_EXPENSE_TYPE_CODE IN('Z1', 'Z2', 'Z3')) AND(PL_E100155.PROJ_TYPE_CODE = '01'))) AND((PL_E100119.GROUP_ACCOUNT_CODE <> 'EXP5555')))) AND(PL_E100119.LVL2_ACCOUNT_CODE <> '58303') AND(PL_E100155.PROJ_TYPE_CODE = '01'))) AND((PL_E100119.LVL1_ACCOUNT_CODE = '504') AND(PL_E100147.CN_NAME IN('JV-PFC cooper cost', 'JV-ADJ PA Cooper/Constr', 'JV-Agent REV&COST Adj', 'JV-Agent totalvalue Adj')))) OR((PL_E100119.ACCOUNT_EXPENSE_CATG_CODE = 'E05') AND(PL_E100134.DEPT_EXPENSE_TYPE_CODE IN('Z1', 'Z2', 'Z3')) AND(PL_E100155.PROJ_TYPE_CODE = '01') AND(PL_E100147.CN_NAME <> 'JV-ADJ 557 WITH B CODE') AND((((((((PL_E100119.LVL1_ACCOUNT_CODE IN('501', '503', '506', '512')) OR(PL_E100119.GROUP_ACCOUNT_CODE = '5980406')) AND((PL_E100121.PROD_CLASS_FLAG = '0') OR(PL_E100122.PROD_CLASS_FLAG = '0'))) OR((PL_E100119.LVL1_ACCOUNT_CODE IN('504', 'SVC')) OR(PL_E100119.LVL2_ACCOUNT_CODE IN('55107', '57702', '57703', '58303')) OR(PL_E100119.GROUP_ACCOUNT_CODE IN('5980407', '5825107', '5827702', '5827703', 'C501'))) OR((PL_E100119.ACCOUNT_EXPENSE_CATG_CODE IN('E01', 'E03', 'E05', 'E06', 'E08', 'E09', 'E10', 'E11', 'E02', 'E04', 'E07', 'E12')) AND(PL_E100134.DEPT_EXPENSE_TYPE_CODE = 'Z4') AND((PL_E100155.PROJ_TYPE_CODE <> '02') OR(PL_E100155.PROJ_NUM IN('9000000')))) OR((PL_E100119.ACCOUNT_EXPENSE_CATG_CODE IN('E02', 'E04', 'E07', 'E12', 'E05', 'E09', 'E10')) AND(PL_E100134.DEPT_EXPENSE_TYPE_CODE IN('Z1', 'Z2', 'Z3')) AND(PL_E100155.PROJ_TYPE_CODE = '01'))) AND((PL_E100119.GROUP_ACCOUNT_CODE <> 'EXP5555')))) AND(PL_E100119.LVL2_ACCOUNT_CODE <> '58303') AND(PL_E100155.PROJ_TYPE_CODE = '01')))))
 AND T.PERIOD_ID >= 202208
 AND T.PERIOD_ID <= 202208 
) A

场景1

1)往目标表INSERT的数据量过大,导致INSERT的数据量在单DN上使用的存储空间超过sql_use_spacelimit阈值

这种场景一般是配置参数sql_use_spacelimit设置不合理,建议直接调大配置参数sql_use_spacelimit的值

2)INSERT的数据存在倾斜,导致某个DN上数据写入量特别大,在这个DN上触发了sql_use_spacelimit阈值

这类问题的解决一般分为以下几个步骤

a)使用如下SQL查找目标表分布列

SELECT pg_get_tabledef('dwljaa.bif_col_edw_dut_257_t'::regclass);

获取的表定义如下

SET search_path = dwljaa;
CREATE TABLE bif_col_edw_dut_257_t (
tag_grp_code character varying(100),
tag_code character varying(100),
tag_id numeric,
period character varying(20),
tbl_code character varying(100) NOT NULL,
table_name character varying(50),
target_key_val character varying(100),
target_key_num numeric,
cycle_id numeric,
creation_date timestamp(0) without time zone,
attribute1 character varying(100),
attribute2 character varying(100),
attribute3 character varying(100),
attribute4 character varying(100),
attribute5 character varying(100),
priority numeric,
column_name1 character varying(100),
column_name2 character varying(100),
column_name3 character varying(100),
column_name4 character varying(100),
column_name5 character varying(100),
carrying_dimension1 character varying(100),
carrying_dimension2 character varying(100),
carrying_dimension3 character varying(100)
)
WITH (orientation=column, compression=low, colversion=2.0, enable_delta=false)
DISTRIBUTE BY HASH(target_key_num)
TO GROUP group_version1;

b)根据表定义和INSERT语句,确认分布列在查询语句中的输出列位置

根据表定义(分布列为target_key_num)以及原始的INSERT语句描述,查询语句输出的导数第二列( A.record_seq_num)对应目标表的分布列target_key_num

c)构建如下查询语句,判断查询语句输出数据在字段A.record_seq_num是否存在严重

如果输出的第一条记录的cnt值非常大(比如上百万甚至更多),导致此值对应记录的存储空间可能触发sql_use_spacelimit阈值,那么就可以明确是数据倾斜导致的。 这种场景一般需要先排查数据倾斜产生的原因是否合理,如果数据缺失存在倾斜,那么建议修改表的分布列,具体修改方案参见GaussDB(DWS)性能调优系列实战篇三:十八般武艺之好味道表定义》

WITH t AS(-- 把原始语句中的查询部分封装为CTE,查询语句实处列只包含分布列
 SELECT 
 A.record_seq_num
 FROM (SELECT /*+PARALLEL(8) NO_EXPAND*/ T.record_seq_num
 FROM dwljaa.dwr_fin_hwip_man_je_f_tmp0 T
 INNER JOIN dwrdim.dwr_dim_department_d PL_E100134 ON T.COA_DEPT_KEY = PL_E100134.DEPT_KEY
 INNER JOIN dwrdim.dwr_dim_grp_acct_code_d PL_E100119 ON T.GROUP_ACCOUNT_CODE = PL_E100119.GROUP_ACCOUNT_CODE
 INNER JOIN dwrdim.dwr_dim_journal_category_d PL_E100147 ON T.JE_CATEGORY_ID = PL_E100147.JE_CATEGORY_ID
 INNER JOIN dwrdim.dwr_dim_product_d PL_E100121 ON T.MAJOR_PROD_KEY = PL_E100121.PROD_KEY
 INNER JOIN dwrdim.dwr_dim_product_d PL_E100122 ON T.MINOR_PROD_KEY = PL_E100122.PROD_KEY
 INNER JOIN dwrdim.dwr_dim_project_d PL_E100155 ON T.PROJ_KEY = PL_E100155.PROJ_KEY
 WHERE 1 = 1 AND ((((((((((PL_E100119.LVL1_ACCOUNT_CODE IN('501', '503', '506', '512')) OR(PL_E100119.GROUP_ACCOUNT_CODE = '5980406')) AND((PL_E100121.PROD_CLASS_FLAG = '0') OR(PL_E100122.PROD_CLASS_FLAG = '0'))) OR((PL_E100119.LVL1_ACCOUNT_CODE IN('504', 'SVC')) OR(PL_E100119.LVL2_ACCOUNT_CODE IN('55107', '57702', '57703', '58303')) OR(PL_E100119.GROUP_ACCOUNT_CODE IN('5980407', '5825107', '5827702', '5827703', 'C501'))) OR((PL_E100119.ACCOUNT_EXPENSE_CATG_CODE IN('E01', 'E03', 'E05', 'E06', 'E08', 'E09', 'E10', 'E11', 'E02', 'E04', 'E07', 'E12')) AND(PL_E100134.DEPT_EXPENSE_TYPE_CODE = 'Z4') AND((PL_E100155.PROJ_TYPE_CODE <> '02') OR(PL_E100155.PROJ_NUM IN('9000000')))) OR((PL_E100119.ACCOUNT_EXPENSE_CATG_CODE IN('E02', 'E04', 'E07', 'E12', 'E05', 'E09', 'E10')) AND(PL_E100134.DEPT_EXPENSE_TYPE_CODE IN('Z1', 'Z2', 'Z3')) AND(PL_E100155.PROJ_TYPE_CODE = '01'))) AND((PL_E100119.GROUP_ACCOUNT_CODE <> 'EXP5555')))) AND(PL_E100119.LVL2_ACCOUNT_CODE <> '58303') AND(PL_E100155.PROJ_TYPE_CODE = '01'))) AND((PL_E100119.LVL1_ACCOUNT_CODE = '504') AND(PL_E100147.CN_NAME IN('JV-PFC cooper cost', 'JV-ADJ PA Cooper/Constr', 'JV-Agent REV&COST Adj', 'JV-Agent totalvalue Adj')))) OR((PL_E100119.ACCOUNT_EXPENSE_CATG_CODE = 'E05') AND(PL_E100134.DEPT_EXPENSE_TYPE_CODE IN('Z1', 'Z2', 'Z3')) AND(PL_E100155.PROJ_TYPE_CODE = '01') AND(PL_E100147.CN_NAME <> 'JV-ADJ 557 WITH B CODE') AND((((((((PL_E100119.LVL1_ACCOUNT_CODE IN('501', '503', '506', '512')) OR(PL_E100119.GROUP_ACCOUNT_CODE = '5980406')) AND((PL_E100121.PROD_CLASS_FLAG = '0') OR(PL_E100122.PROD_CLASS_FLAG = '0'))) OR((PL_E100119.LVL1_ACCOUNT_CODE IN('504', 'SVC')) OR(PL_E100119.LVL2_ACCOUNT_CODE IN('55107', '57702', '57703', '58303')) OR(PL_E100119.GROUP_ACCOUNT_CODE IN('5980407', '5825107', '5827702', '5827703', 'C501'))) OR((PL_E100119.ACCOUNT_EXPENSE_CATG_CODE IN('E01', 'E03', 'E05', 'E06', 'E08', 'E09', 'E10', 'E11', 'E02', 'E04', 'E07', 'E12')) AND(PL_E100134.DEPT_EXPENSE_TYPE_CODE = 'Z4') AND((PL_E100155.PROJ_TYPE_CODE <> '02') OR(PL_E100155.PROJ_NUM IN('9000000')))) OR((PL_E100119.ACCOUNT_EXPENSE_CATG_CODE IN('E02', 'E04', 'E07', 'E12', 'E05', 'E09', 'E10')) AND(PL_E100134.DEPT_EXPENSE_TYPE_CODE IN('Z1', 'Z2', 'Z3')) AND(PL_E100155.PROJ_TYPE_CODE = '01'))) AND((PL_E100119.GROUP_ACCOUNT_CODE <> 'EXP5555')))) AND(PL_E100119.LVL2_ACCOUNT_CODE <> '58303') AND(PL_E100155.PROJ_TYPE_CODE = '01')))))
 AND T.PERIOD_ID >= 202208
 AND T.PERIOD_ID <= 202208 
    ) A
)
-- 对分布列做汇总求和,查找分布列值重复次数最多的值
SELECT 
 record_seq_num, cnt
FROM (
 SELECT record_seq_num, count(1) AS cnt 
 FROM t 
 GROUP BY record_seq_num HAVING count(1) > 10000
)
ORDER BY cnt
LIMIT 10

 

点击关注,第一时间了解华为云新鲜技术~

标签:DWS,ACCOUNT,CODE,运维,数仓,PL,TYPE,E100119,PROJ
From: https://www.cnblogs.com/huaweiyun/p/17246849.html

相关文章

  • 技术干货 从DBA视角看数据库运维管理平台
    GreatSQL社区原创内容未经授权不得随意使用,转载请联系小编并注明来源。GreatSQL是MySQL的国产分支版本,使用上与MySQL一致。作者:z文章来源:GreatSQL社区原创DBA岗位......
  • 关于微服务的自动化部署+运维,于企业发展的思考,技术性路线实践
    1、背景这段时间由于各人原因需要了解java系统部署方法。之前没有系统学习过,所以只能参考公司现有的系统部署架构。在这个学习的过程中有了个人的一些感悟+踩了一些坑。往下......
  • 工业锅炉设备远程监控运维
    ​我国是全球工业锅炉生产应用数量最大、应用范围最广泛的国家,规模以上锅炉生产企业有千余家。我国工业锅炉容量小、数量大、布点散、能耗高,无法做到集中管理和控制,对于锅炉......
  • TiDB运维命令
    查看TiDB参数查看configshowconfigwherenamelike'%%';查看参数showvariableslike'%%';#pd-ctl中configshow[all]Dumpling工具下载示例#dumpling导......
  • 运维工程师之日常巡检
    #情境最近面试过程当中,发现好多运维工程师日常工作内容中,有一项周而复始每天都要做的事巡检服务器资源信息(如:CPU,硬盘,内存...)作为一个技术人,起码的懒人意识应该要有,同样的......
  • GaussDB(DWS)运维:导致SQL执行不下推的改写方案
    摘要:本文就针对因USING子句的书写方式可能导致MERGEINTO语句的执行不下推的场景,对USING子句的SQL语句进行改写一遍,整个SQL语句可以下推。本文分享自华为云社区《​​GaussD......
  • 数据库运维---数据库备份策略
    数据库安装方式:通用二进制安装策略1:直接拷贝数据库文件步骤1:主服务器上停用数据库[root@node01~]#systemctlstopmysqld.service步骤2:进入数据目录,打包并压缩数据......
  • python-运维开发-入门上
    一、Python快速入门上1.1python基础知识01python介绍python是一种面向对象、解释型、多用途设计语言,具有很丰富和强大的库,语法简介,强制用空格作为语法缩进,能够完成快......
  • 不背锅运维:选择辅助容器还是另外拉起监控Pod?
    监控方案方案一对于一个Pod中只有一个业务容器的情况,可以考虑在该Pod中增加一个辅助容器,来完成对业务容器的监控。辅助容器可以使用各种监控工具的采集器,如Prometheu......
  • 信息运维
    信息的7大特性:可传输性时滞性可储存性再生与增值性可加工性共享性转化性系统的含义:为达到某种目的而相互联系的部件集合系统的4方面特性:整体性,目的性,关联性,......