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,可以直接通过管理平台创建快照和报告,如下:

 

   

 

   

 

   也可以导出为离线模式。

posted @ 2023-05-15 09:39  zhjh256  阅读(89)  评论(0编辑  收藏  举报