【GaussDB】分布式性能分析常用的SQL

2024-08-31 14:36

本文主要是介绍【GaussDB】分布式性能分析常用的SQL,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

--查看连接数
select coorname,usename,application_name,substr(query,1,50) as query,state from pgxc_stat_activity where state='active' and usename='xxx';
select coorname,count() from pgxc_stat_activity where usename='cbsprd' group by coorname;
select coorname,client_addr,count(
) from pgxc_stat_activity where state='active' and usename='cbsprd';

--杀会话
execute direct on all 'select pg_terminate_session(pid,sessionid) from pg_stat_activity where usename='xxx';
execute direct on all 'select * from statement_history whee unique_query_id='1178397073' and query is not null;';

--清理statement
select reset_unique_sql('GLOBAL','ALL',0);

--查询TOP SQL
select n_calls,unique_sql_id,substr(query,1,50) as query,total_elapse_time/n_calls/1000 as avg_time,total_elapse_time/1000 as runtime from dbe_perf.statement where user_name='cbsprd' and n_calls>10 and avg_time>5 order by runtime desc;
select n_calls,unique_sql_id,substr(query,1,50) as query,total_elapse_time/n_calls/1000 as avg_time,total_elapse_time/1000 as runtime from dbe_perf.statement where user_name='cbsprd' and n_calls>10 and query like '%kapb% order by runtime desc;
select sum(total_elapse_time)/1000 as total_time from be_perf.statement where user_name='cbsprd' ;

--查询等待事件
select wait_status,wait_event,count() from pg_thread_wait_status group by 1,2 order by 3 desc;
select wait_status,event,count(
) from gs_asp where sample_time >'2024-06-26 17:20:00' and sample_time<'2024-06-26 17:50:00' and databaseid=685433 group by 1,2 order by 3 desc;
select wait_status,event,count(*) from dbe_perf.local_active session where sample_time >'2024-06-26 17:20:00' and sample_time<'2024-06-26 17:50:00' and databaseid=685433 group by 1,2 order by 3 desc;
select * from dbe_perf.local_active session where sample_time >'2024-06-26 17:20:00' and sample_time<'2024-06-26 17:50:00' and databaseid=685433 and unique_query_id;=3935832574;

--查询慢SQL
select unique_query_id,substr(query,1,100) as query,count(*) from be_perf.get_global_full_sql_by_timestamp('2024-06-12 10:30:00','2024-06-12 16:30:00') where user_name='cbsprd' group by 1,2 order by 3 desc;

--查询单条慢SQL记录
\x
select *,dbe_perf.get_global_full_sql_by_timestamp('2024-06-12 10:30:00','2024-06-12 16:30:00') where unique_query_id=xxxxx and query is not null;
select * from dbe_perf.statement_history where unique_query_id=xxxxx and query is not null;
select * from dbe_perf.statement where unique_sql_id=xxxxxx;

--查询列的统计信息
select * from pg_stats where tablename='kapb_jioyrz' and attname='jiluztai';

--SQLPATCH
select * from dbe_sql_util.drop_sql_patch('patch1');
select * from dbe_sql_util.create_hint_sql_patch('809780568','809780568','use_cplan');
select * from dbe_sql_util.create_hint_sql_patch('patch4','37772378082','set(enable_for_fqs_on)');
select * from dbe_sql_util.create_hint_sql_patch('3203049046','3203049046','set(enable_stream_operator off)');
select * from dbe_sql_util.create_hint_sql_patch('3203049046','3203049046','set(enable_stream_operator off)');
select * from dbe_sql_util.create_hint_sql_patch('1580322454','1580322454','set(query_dop 8) set(enable_seqscan on)');
select * from dbe_sql_util.create_hint_sql_patch('1580322453','1580322453','set(query_dop 8) set(enable_seqscan on) set(try_vector_engine_strategy force');
select * from dbe_sql_util.create_hint_sql_patch('1580322452','1580322452','no_expand(@"sel$2")');
select * from gs_sql_patch;

--汇总数据库消耗时间
select sum(total_elapse_time)/1000 as total_time from be_perf.statement where user_name='cbsprd' ;

--查看锁
select *,pg_catalog.statement_detail_decode(details,'plaintext',true) from statement_history where unique_query_id=3177795013 order by db_time desc;
select * from pg_catalog.statement_detail_decode(detail,'plaintext',true);--detail='\x5e......'十六进制码

--生成火焰图
perf record -e cpu-clock -g -p 946111 -- sleep 60

--抓full sql
select * from dynamic_func_control('LOCAL','STMT','TRACK','{"1178397073","L2"}');
select * from dynamic_func_control('LOCAL','STMT','TRACK','{"1178397073"}');

--内存消耗
select * from pg_total_memory_detail;

select contextname,sum(totalsize)/1024/1024 totalsize,sum(freesize)/1024/1024 freesize,count() sum from pv_thread_memory_context group by contextname order by sum desc limit 10;
select contextname,sum(totalsize)/1024/1024 totalsize,sum(freesize)/1024/1024 freesize,count(
) sum from pv_session_memory_context group by contextname order by sum desc limit 20;

--耗时统计
select a.ljhaoshi/1000/60/60,a.* from cbsprd.ksys_plrenw a where a.pljypich='hx_dayend_all_20240626_9999' order by a.dqjioayrq asc;

--内存不足问题
gs_guc set -Z coordinator -Z datanode -N all -I all -c "enable_global_plancache=on"
gs_guc set -Z coordinator -Z datanode -N all -I all -c "enable_stream_pbe=off"

这篇关于【GaussDB】分布式性能分析常用的SQL的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1124176

相关文章

MySQL 多表连接操作方法(INNER JOIN、LEFT JOIN、RIGHT JOIN、FULL OUTER JOIN)

《MySQL多表连接操作方法(INNERJOIN、LEFTJOIN、RIGHTJOIN、FULLOUTERJOIN)》多表连接是一种将两个或多个表中的数据组合在一起的SQL操作,通过连接,... 目录一、 什么是多表连接?二、 mysql 支持的连接类型三、 多表连接的语法四、实战示例 数据准备五、连接的性

MySQL中的分组和多表连接详解

《MySQL中的分组和多表连接详解》:本文主要介绍MySQL中的分组和多表连接的相关操作,本文通过实例代码给大家介绍的非常详细,感兴趣的朋友一起看看吧... 目录mysql中的分组和多表连接一、MySQL的分组(group javascriptby )二、多表连接(表连接会产生大量的数据垃圾)MySQL中的

Python中pywin32 常用窗口操作的实现

《Python中pywin32常用窗口操作的实现》本文主要介绍了Python中pywin32常用窗口操作的实现,pywin32主要的作用是供Python开发者快速调用WindowsAPI的一个... 目录获取窗口句柄获取最前端窗口句柄获取指定坐标处的窗口根据窗口的完整标题匹配获取句柄根据窗口的类别匹配获取句

Python中的Walrus运算符分析示例详解

《Python中的Walrus运算符分析示例详解》Python中的Walrus运算符(:=)是Python3.8引入的一个新特性,允许在表达式中同时赋值和返回值,它的核心作用是减少重复计算,提升代码简... 目录1. 在循环中避免重复计算2. 在条件判断中同时赋值变量3. 在列表推导式或字典推导式中简化逻辑

C#使用StackExchange.Redis实现分布式锁的两种方式介绍

《C#使用StackExchange.Redis实现分布式锁的两种方式介绍》分布式锁在集群的架构中发挥着重要的作用,:本文主要介绍C#使用StackExchange.Redis实现分布式锁的... 目录自定义分布式锁获取锁释放锁自动续期StackExchange.Redis分布式锁获取锁释放锁自动续期分布式

MySQL 中的 JSON 查询案例详解

《MySQL中的JSON查询案例详解》:本文主要介绍MySQL的JSON查询的相关知识,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下吧... 目录mysql 的 jsON 路径格式基本结构路径组件详解特殊语法元素实际示例简单路径复杂路径简写操作符注意MySQL 的 J

Python的time模块一些常用功能(各种与时间相关的函数)

《Python的time模块一些常用功能(各种与时间相关的函数)》Python的time模块提供了各种与时间相关的函数,包括获取当前时间、处理时间间隔、执行时间测量等,:本文主要介绍Python的... 目录1. 获取当前时间2. 时间格式化3. 延时执行4. 时间戳运算5. 计算代码执行时间6. 转换为指

Windows 上如果忘记了 MySQL 密码 重置密码的两种方法

《Windows上如果忘记了MySQL密码重置密码的两种方法》:本文主要介绍Windows上如果忘记了MySQL密码重置密码的两种方法,本文通过两种方法结合实例代码给大家介绍的非常详细,感... 目录方法 1:以跳过权限验证模式启动 mysql 并重置密码方法 2:使用 my.ini 文件的临时配置在 Wi

MySQL重复数据处理的七种高效方法

《MySQL重复数据处理的七种高效方法》你是不是也曾遇到过这样的烦恼:明明系统测试时一切正常,上线后却频频出现重复数据,大批量导数据时,总有那么几条不听话的记录导致整个事务莫名回滚,今天,我就跟大家分... 目录1. 重复数据插入问题分析1.1 问题本质1.2 常见场景图2. 基础解决方案:使用异常捕获3.

Python正则表达式语法及re模块中的常用函数详解

《Python正则表达式语法及re模块中的常用函数详解》这篇文章主要给大家介绍了关于Python正则表达式语法及re模块中常用函数的相关资料,正则表达式是一种强大的字符串处理工具,可以用于匹配、切分、... 目录概念、作用和步骤语法re模块中的常用函数总结 概念、作用和步骤概念: 本身也是一个字符串,其中