【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虚拟列的使用场景

《Mysql虚拟列的使用场景》MySQL虚拟列是一种在查询时动态生成的特殊列,它不占用存储空间,可以提高查询效率和数据处理便利性,本文给大家介绍Mysql虚拟列的相关知识,感兴趣的朋友一起看看吧... 目录1. 介绍mysql虚拟列1.1 定义和作用1.2 虚拟列与普通列的区别2. MySQL虚拟列的类型2

mysql数据库分区的使用

《mysql数据库分区的使用》MySQL分区技术通过将大表分割成多个较小片段,提高查询性能、管理效率和数据存储效率,本文就来介绍一下mysql数据库分区的使用,感兴趣的可以了解一下... 目录【一】分区的基本概念【1】物理存储与逻辑分割【2】查询性能提升【3】数据管理与维护【4】扩展性与并行处理【二】分区的

MySQL中时区参数time_zone解读

《MySQL中时区参数time_zone解读》MySQL时区参数time_zone用于控制系统函数和字段的DEFAULTCURRENT_TIMESTAMP属性,修改时区可能会影响timestamp类型... 目录前言1.时区参数影响2.如何设置3.字段类型选择总结前言mysql 时区参数 time_zon

Python MySQL如何通过Binlog获取变更记录恢复数据

《PythonMySQL如何通过Binlog获取变更记录恢复数据》本文介绍了如何使用Python和pymysqlreplication库通过MySQL的二进制日志(Binlog)获取数据库的变更记录... 目录python mysql通过Binlog获取变更记录恢复数据1.安装pymysqlreplicat

Java 字符数组转字符串的常用方法

《Java字符数组转字符串的常用方法》文章总结了在Java中将字符数组转换为字符串的几种常用方法,包括使用String构造函数、String.valueOf()方法、StringBuilder以及A... 目录1. 使用String构造函数1.1 基本转换方法1.2 注意事项2. 使用String.valu

C#使用yield关键字实现提升迭代性能与效率

《C#使用yield关键字实现提升迭代性能与效率》yield关键字在C#中简化了数据迭代的方式,实现了按需生成数据,自动维护迭代状态,本文主要来聊聊如何使用yield关键字实现提升迭代性能与效率,感兴... 目录前言传统迭代和yield迭代方式对比yield延迟加载按需获取数据yield break显式示迭

使用SQL语言查询多个Excel表格的操作方法

《使用SQL语言查询多个Excel表格的操作方法》本文介绍了如何使用SQL语言查询多个Excel表格,通过将所有Excel表格放入一个.xlsx文件中,并使用pandas和pandasql库进行读取和... 目录如何用SQL语言查询多个Excel表格如何使用sql查询excel内容1. 简介2. 实现思路3

Redis主从/哨兵机制原理分析

《Redis主从/哨兵机制原理分析》本文介绍了Redis的主从复制和哨兵机制,主从复制实现了数据的热备份和负载均衡,而哨兵机制可以监控Redis集群,实现自动故障转移,哨兵机制通过监控、下线、选举和故... 目录一、主从复制1.1 什么是主从复制1.2 主从复制的作用1.3 主从复制原理1.3.1 全量复制

Mysql DATETIME 毫秒坑的解决

《MysqlDATETIME毫秒坑的解决》本文主要介绍了MysqlDATETIME毫秒坑的解决,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着... 今天写代码突发一个诡异的 bug,代码逻辑大概如下。1. 新增退款单记录boolean save = s

mysql-8.0.30压缩包版安装和配置MySQL环境过程

《mysql-8.0.30压缩包版安装和配置MySQL环境过程》该文章介绍了如何在Windows系统中下载、安装和配置MySQL数据库,包括下载地址、解压文件、创建和配置my.ini文件、设置环境变量... 目录压缩包安装配置下载配置环境变量下载和初始化总结压缩包安装配置下载下载地址:https://d