lightdb性能分析之PWR报告生成与解析
LightDB包含了一个性能诊断工具PWR。该工具采集和存储数据库运行时的性能指标以及系统状态信息,帮助我们更好地了解数据库的负载状况和性能水平。AWR报告可以概述在一定时间范围内数据库的活动情况,包括响应时间、CPU利用率、内存利用率、I/O活动等。我们可以使用AWR报告来识别哪些SQL语句是数据库的主要性能瓶颈,并根据报告中的指标推断系统的瓶颈在哪里。和oracle中的AWR类似。
在lightdb中,和oracle一样,默认开启了AWR(它是基于lt_stat_activity、lt_profile)快照的采样,可通过表函数cron.job j查询采样设置(默认保存30天)。如下:
select * from show_servers(); server_name|connstr |enabled|description| -----------+-------------------------+-------+-----------+ local |dbname=postgres port=5555|true | |
select * from cron.job j; jobid|schedule |command |nodename |nodeport|database|username|active|jobname | -----+-------------+---------------------------------+---------+--------+--------+--------+------+------------------------+ 1|*/5 * * * * |SELECT pg_show_plans() |localhost| 5555|postgres|lightdb |true |pg_show_plans | 2|*/1 * * * * *|SELECT collect_activity_history()|localhost| 5555|postgres|lightdb |true |collect_activity_history| 3|*/1 * * * * |SELECT collect_activity_profile()|localhost| 5555|postgres|lightdb |true |collect_activity_profile| 4|0 0 * * * |SELECT clean_activity_profile() |localhost| 5555|postgres|lightdb |true |clean_activity_profile | 5|*/10 * * * * |SELECT take_sample() |localhost| 5555|postgres|lightdb |true |take_sample |
collect_activity_history每秒钟采集一次内存中的统计信息(主要是lt_stat_activity中的等待事件,不过它统计的也是次数,因为并不是每次采集到就是等待了一秒钟,有可能刚刚出现),和oracle ash是一样的,然后通过sample_activity_history对外暴露。每分钟通过collect_activity_profile函数汇总到sample_activity_profile对外暴露。
要创建一个最新的快照,可人工调用函数take_sample(),它会采集所有启用状态服务器()的快照。如下:
select * from take_sample(); -- 成功节点 server|result|elapsed | ------+------+-----------+ local |OK |00:00:02.94| -- 失败节点 server|result |elapsed | ------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-----------+ local |could not establish connection¶SQL statement "SELECT dblink_connect('server_connection',server_connstr)"¶PL/pgSQL function take_sample(integer,boolean) line 154 at PERFORM¶PL/pgSQL function take_sample_subset(integer,integer) line 27 at assignment¶SQL fun|00:00:00.06|
不同于oracle,在lightdb中,可以集中式的为任意多个lightdb实例设置采样。
https://www.hs.net/lightdb/docs/html/pgprofile.html#id-1.11.7.47.9
生成pwr报告的使用,可参见https://www.cnblogs.com/lightdb/p/16608724.html
不同于开源PostgreSQL以及其他基于PG的数据库,在lightdb中,用户不需要在shared_preload_library中显示配置pg_wait_sampling(只统计进程等待次数,没有时间,也没有持久化,lightdb使用lt_stat_activity代替了它。lightdb 23.2开始全新实现了等待事件profile,非常准确)和pg_profile、dblink插件。虽然它底层也用到了这两个插件,但lightdb做了很多优化。
如果安装了lightdb em,可以直接通过管理平台创建快照和报告,如下:
也可以导出为离线模式。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 上周热点回顾(2.24-3.2)
2019-05-15 无法反序列化的java.util.ArrayList实例出来VALUE_STRING的(Can not deserialize instance of java.util.ArrayList out of VALUE_STRING)
2019-05-15 open jdk性能与稳定性测试比较(转载)
2019-05-15 java MVEL2/Spring EL表达式、直接调用、反射性能实测