重庆思庄Oracle、、PostgreSQL、Redhat认证学习论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 306|回复: 0
打印 上一主题 下一主题

PG 的 AWR pg_profile

[复制链接]
跳转到指定楼层
楼主
发表于 7 天前 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 jiawang 于 2025-4-9 09:22 编辑

  一、什么是PG_PROFILE

在postgres中,当遇到问题时,可能需要回顾不止一件事情来分析数据库或者整个集群,包括索引,I/O,CPU等

pg_profile 扩展是基于postgres的标准统计视图。它类似于Oracle AWR架构,和Oracle一样,它在指定时间生成快照,并切提供html格式来解释快照之间的统计数据

二、配置postgresql.conf

数据库中需要plpgsql dblink 扩展,如果需要语句统计信息,则需要pg_stat_statements扩展。
dblink
pg_stat_statements属于系统自带插件
postgres=# \dx
                 List of installed extensions
Name   | Version |   Schema  |         Description         
---------+---------+------------+------------------------------
plpgsql | 1.0     | pg_catalog | PL/pgSQL procedurallanguage
(1 row)
postgres=# CREATEEXTENSION dblink;
CREATE EXTENSION
postgres=# CREATEEXTENSION pg_stat_statements;
CREATE EXTENSION
postgres=# \dx
                                           List of installed extensions
       Name        | Version |   Schema  |                             Description                              
--------------------+---------+------------+------------------------------------------------------------------------
dblink             | 1.2     | public     | connect to other PostgreSQL databasesfrom within a database
pg_stat_statements | 1.10    | public    | track planning and execution statistics of all SQL statements executed
plpgsql            | 1.0     | pg_catalog | PL/pgSQL procedurallanguage
(3 rows)


创建扩展profile
postgres=# CREATE SCHEMA profile;
CREATE SCHEMA
postgres=# CREATE EXTENSION pg_profileSCHEMA profile;
CREATE EXTENSION
postgres=# \dn
      List of schemas
Name   |       Owner      
---------+-------------------
profile | postgres
public | pg_database_owner
(2 rows)

postgres=# \dx
                                           List of installed extensions
        Name        | Version |   Schema  |                             Description                              
--------------------+---------+------------+------------------------------------------------------------------------
dblink             | 1.2     | public     | connect to other PostgreSQL databasesfrom within a database
pg_profile         | 4.8     | profile    | PostgreSQL load profile repository andreport builder
pg_stat_statements | 1.10    | public    | track planning and execution statistics of all SQL statements executed
plpgsql            | 1.0     | pg_catalog | PL/pgSQL procedurallanguage
(4rows)

[postgres@sztech data]$ psql
psql (16.3)
Type "help" for help.
postgres=# SELECT profile.snapshot() ;
       snapshot        
------------------------
(local,OK,00:00:00.36)
(1 row)
postgres=# select profile.show_samples();
          show_samples            
-----------------------------------
(1,"2025-04-08 17:06:25+08",t,,,)
(1 row)
postgres=#
postgres=# select profile.show_samples();
          show_samples            
-----------------------------------
(1,"2025-04-08 17:06:25+08",t,,,)
(1 row)
postgres=# SELECT profile.snapshot() ;
       snapshot        
------------------------
(local,OK,00:00:00.38)
(1 row)
postgres=# SELECT profile.snapshot() ;  
       snapshot        
------------------------
(local,OK,00:00:00.31)
(1 row)
postgres=# select profile.show_samples();
          show_samples            
-----------------------------------
(1,"2025-04-08 17:06:25+08",t,,,)
(2,"2025-04-08 17:06:58+08",t,,,)
(3,"2025-04-08 17:13:45+08",t,,,)
(4,"2025-04-08 17:13:54+08",t,,,)
(4 rows)

添加测试数据
postgres=# create table t1(id int);
CREATE TABLE
postgres =# insert into t1 values(generate_series(1,1000));
INSERT 0 1000

查询快照详情
postgres=# select * fromprofile.show_samples();
sample |     sample_time       |sizes_collected | dbstats_reset | clustats_reset | archstats_reset
--------+------------------------+-----------------+---------------+----------------+-----------------
     1 | 2025-04-08 17:06:25+08 | t               |               |                |
     2 | 2025-04-08 17:06:58+08 | t               |               |                |
     3 | 2025-04-08 17:13:45+08 | t               |               |                |
     4 | 2025-04-08 17:13:54+08 | t               |               |                |
     5 | 2025-04-08 17:41:24+08 | t               |               |                |
     6 | 2025-04-08 17:42:35+08 | t               |               |                |
(6 rows)

基于两个快照点的间隔生成
[postgres@sztech ~]$ psql -dpostgres-Upostgres -Aqtc "SELECT profile.get_report(3,6)" -oawr_report_postgres_3_6.html
[postgres@sztech ~]$ ll
总用量 518952
-rw-r--r-- 1 postgres postgres531027917  4月  8 17:38 awr_report_postgres_1_2.html
-rw-r--r-- 1 postgres postgres    375773 4月  817:45 awr_report_postgres_3_6.html

导出效果图如下:
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 支持支持 反对反对
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|手机版|小黑屋|重庆思庄Oracle、Redhat认证学习论坛 ( 渝ICP备12004239号-4 )

GMT+8, 2025-4-16 06:59 , Processed in 0.096810 second(s), 23 queries .

重庆思庄学习中心论坛-重庆思庄科技有限公司论坛

© 2001-2020

快速回复 返回顶部 返回列表