PostgreSQL的AWR(PG_PROFILE)

PostgreSQL参数配置

如下配置为使用pg_profile最基本的配置

shared_preload_libraries = 'pg_stat_statements'
pg_stat_statements.max = 10000
pg_stat_statements.track = 'top'
pg_stat_statements.save = on

track_activities = on
track_counts = on
track_io_timing = on
track_functions = all

安装扩展文件

$ tar xzf pg_profile--0.3.4.tar.gz --directory $(pg_config --sharedir)/extension

创建扩展

为便于管理,建议创建单独的schema,本文创建了profile

postgres=# CREATE EXTENSION dblink;
postgres=# CREATE EXTENSION pg_stat_statements;
postgres=# CREATE SCHEMA profile;
postgres=# CREATE EXTENSION pg_profile SCHEMA profile;
postgres=# \dn
  List of schemas
  Name   |  Owner
---------+----------
 profile | postgres
 public  | postgres
(2 rows)

不想指定模式限定符,可以设置search_path

postgres=# set search_path="$user",public,profile;
SET
postgres=# show search_path;
-[ RECORD 1 ]-------------------------
search_path | "$user", public, profile

zjzf02=# alter user postgres set search_path to "$user", public,profile;
ALTER ROLE

pg_profile相关对象

postgres=# \d
                      List of relations
 Schema  |             Name             |   Type   |  Owner
---------+------------------------------+----------+----------
 profile | baselines                    | table    | postgres
 profile | baselines_bl_id_seq          | sequence | postgres
 profile | bl_samples                   | table    | postgres
 profile | funcs_list                   | table    | postgres
 profile | import_queries               | table    | postgres
 profile | import_queries_version_order | table    | postgres
 profile | indexes_list                 | table    | postgres
 profile | last_stat_archiver           | table    | postgres
 profile | last_stat_cluster            | table    | postgres
 profile | last_stat_database           | table    | postgres
 profile | last_stat_indexes            | table    | postgres
 profile | last_stat_tables             | table    | postgres
 profile | last_stat_tablespaces        | table    | postgres
 profile | last_stat_user_functions     | table    | postgres
 profile | last_stat_wal                | table    | postgres
 profile | roles_list                   | table    | postgres
 profile | sample_kcache                | table    | postgres
 profile | sample_kcache_total          | table    | postgres
 profile | sample_settings              | table    | postgres
 profile | sample_stat_archiver         | table    | postgres
 profile | sample_stat_cluster          | table    | postgres
 profile | sample_stat_database         | table    | postgres
 profile | sample_stat_indexes          | table    | postgres
 profile | sample_stat_indexes_total    | table    | postgres
 profile | sample_stat_tables           | table    | postgres
 profile | sample_stat_tables_total     | table    | postgres
 profile | sample_stat_tablespaces      | table    | postgres
 profile | sample_stat_user_func_total  | table    | postgres
 profile | sample_stat_user_functions   | table    | postgres
 profile | sample_stat_wal              | table    | postgres
 profile | sample_statements            | table    | postgres
 profile | sample_statements_total      | table    | postgres
 profile | sample_timings               | table    | postgres
 profile | samples                      | table    | postgres
 profile | servers                      | table    | postgres
 profile | servers_server_id_seq        | sequence | postgres
 profile | stmt_list                    | table    | postgres
 profile | tables_list                  | table    | postgres
 profile | tablespaces_list             | table    | postgres
 profile | v_sample_settings            | view     | postgres
 profile | v_sample_stat_indexes        | view     | postgres
 profile | v_sample_stat_tables         | view     | postgres
 profile | v_sample_stat_tablespaces    | view     | postgres
 profile | v_sample_stat_user_functions | view     | postgres
 profile | v_sample_timings             | view     | postgres
(45 rows)

创建快照


postgres=# select * from profile.take_sample();
 server | result |   elapsed
--------+--------+-------------
 local  | OK     | 00:00:00.52
(1 row)

postgres=# select show_samples();
           show_samples
-----------------------------------
 (1,"2022-04-23 22:11:58+08",t,,,)
 (2,"2022-04-23 22:13:33+08",t,,,)
 (3,"2022-04-23 22:19:55+08",t,,,)
 (4,"2022-04-23 22:19:57+08",t,,,)
 (5,"2022-04-23 22:19:58+08",t,,,)
 (6,"2022-04-23 22:19:59+08",t,,,)
 (7,"2022-04-23 22:20:00+08",t,,,)
 (8,"2022-04-23 22:29:27+08",t,,,)
 (9,"2022-04-23 22:44:52+08",t,,,)
(9 rows)

生成报告

$ psql -c "select show_samples()"

普通报告

仅需要两个快照的ID即可

$ psql -Aqtc "SELECT get_report(1,2)" -o report_pg_1_2.html

在这里插入图片描述

差异报告

需要输入四个快照ID,前两个为一组,后两个为一组

$ psql -Aqtc "SELECT get_diffreport(1,2,8,9)" -o diffreport_pg_1_2_8_9.html

在这里插入图片描述

创建快照加入定时任务
间隔为30分钟,时间越短准确定越高

$ crontab -e
*/30 * * * *   psql -c 'SELECT profile.take_sample()' > /dev/null 2>&1

彩蛋是普通报告及差异报告样例

链接:https://pan.baidu.com/s/1uzY7NXwQjV_6D6OT2V4IaA
提取码:v2rj

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
pg_class是postgresql中的一个系统表,用于存储数据库中的所有关系(表、视图、序列、索引等)的元数据信息。pg_class表的结构如下: 列名 | 数据类型 | 描述 --- | --- | --- relname | name | 关系的名称(表名、视图名、序列名等) relnamespace | oid | 关系所属的命名空间(pg_namespace表的oid) reltype | oid | 关系的类型(pg_type表的oid) reloftype | oid | 如果关系是一个复合类型的表,则为该类型的oid;否则为0 relowner | oid | 关系的所有者(pg_authid表的oid) relam | oid | 关系所用的存储引擎(pg_am表的oid) relfilenode | oid | 关系在磁盘上的文件节点号 reltablespace | oid | 关系所在的表空间(pg_tablespace表的oid) relpages | integer | 关系占用的磁盘页数 reltuples | float4 | 关系中的行数 relallvisible | integer | 用于热备的可见性信息 reltoastrelid | oid | 如果关系有TOAST表,则为TOAST表的oid;否则为0 relhasindex | boolean | 关系是否有索引 relisshared | boolean | 关系是否是共享的 relpersistence | "char" | 关系的持久性(p-永久,t-临时,u-未知) relkind | "char" | 关系的类型(r-普通表,i-索引,S-序列,v-视图,m-物化视图,c-复合类型,t-表函数,f-标量函数,p-过程) relnatts | smallint | 关系中的列数 relchecks | smallint | 关系中的CHECK约束数 relhasoids | boolean | 关系是否有OID列 relrowsecurity | boolean | 是否启用了行级别安全 relforcerowsecurity | boolean | 是否强制启用行级别安全 通过查询pg_class表,可以获取数据库中所有关系的元数据信息,包括关系的名称、类型、所有者、存储引擎、占用磁盘空间、行数等等。这些信息对于进行数据库优化、监控和管理非常有用。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值