首页 > 数据库 >【GaussDB】分布式性能分析常用的SQL

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

时间:2024-08-30 20:25:38浏览次数:12  
标签:-- GaussDB SQL time sql query where select 分布式

--查看连接数
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,time,sql,query,where,select,分布式
From: https://www.cnblogs.com/DBA-Ivan/p/18389442

相关文章

  • 昇思AI框架实践2:基于T5的SQL语句生成模型推理
     MindSpore基于T5的SQL语句生成项目实施基于T5的SQL语句生成项目介绍本项目旨在开发一个基于T5-small模型的自然语言转SQL语句生成器。该生成器能够将用户以自然语言形式提出的查询请求转换为对应的SQL查询语句,从而使得即使是不熟悉SQL语言的用户也能够轻松地从数据库中检......
  • 怎么清除mysql磁盘mysql删除的数据
    在MySQL中,被删除的数据默认情况下是被放置在一个空间上被标记为可重用但实际并未立即释放的状态。这允许快速重用该空间,但如果需要彻底从磁盘上清除这些数据,可以使用OPTIMIZETABLE命令。请注意,OPTIMIZETABLE并不能保证彻底删除数据,因为它的目的是重新组织表并释放未使用的空间......
  • 设置 Nginx、MySQL 日志轮询
    title:设置Nginx、MySQL日志轮询tags:author:ChingeYangdate:2024-8-301.Nginx设置日志轮询机器直接安装的:/etc/logrotate.d/nginx/var/log/nginx/*.log{dailymissingokrotate30compressdelaycompressno......
  • 云计算:LNMP网站架构,前期准备,安装php,安装MySQL
    准备工作(初始化)1.关闭防火墙systemctl disablefirewalld --now    //直接永久关闭防火墙2.关闭SELINUX 查看SELINUX:getenforce永久关闭:[root@localhost~]#vim/etc/selinux/configSELINUX=enforcing|disabled或者[root@localhost~]#sed-i's/^S......
  • C#之中SqlConnection的Close和Dispose的区别和在使用using语句管理SqlConnection对象
    SqlConnection的Close和Dispose的区别在C#中,SqlConnection对象的Close和Dispose方法都可以用来释放数据库连接资源,但它们的作用和使用场景有所不同。Close方法SqlConnection.Close方法用于关闭与数据库的连接。当你调用这个方法时,它会关闭连接,但不会释放与连接关联的所有......
  • Java根据经纬度计算两个坐标之间的距离(含SQL计算)
    最近接到两个需求,一个是通过小程序扫码开门的,我这边主要就是根据用户定位判断用户离扫码店铺距离小于多少米的时候才可以调远程调开门接口,另外一个就是获取用户周围有哪些店铺。需求很简单,就是根据定位获取的经度维度计算两个点之间的球面距离,这里我们主要采用Haversine公......
  • 【MySQL 11】索引 (带思维导图)
    文章目录......
  • 【MySQL 12】事务管理 (带思维导图)
    文章目录......
  • 【MySQL 14】用户管理
    文章目录......
  • 【MySQL 13】视图 (带思维导图)
    文章目录......