跳转到主要内容

pgfr_record

基于 pg_cron 的服务端 PostgreSQL 性能飞行记录器

pg_flight_recorder · 基于 pg_cron 的服务端 PostgreSQL 性能飞行记录器

概览

ID扩展软件包版本类别许可证编程语言
6060pgfr_recordpg_flight_recorder2.32.1STATApache-2.0SQL
属性可执行文件动态库需要预加载需要建扩展可迁移可信
----d--否否否是否否
关联
模式pgfr_record
依赖pg_cron
被依赖pgfr_analyze
相关扩展pg_stat_log pg_tracing pg_stat_backtrace logerrors pgelog
同包扩展pgfr_analyze
Enable with pgfr_record.enable().

软件包

类型仓库版本兼容的 PostgreSQL 大版本包名模式依赖
EXTPIGSTY2.32.119 18 17 16 15pg_flight_recorderpg_cron
RPMPIGSTY2.32.119 18 17 16 15pg_flight_recorder_$vpg_cron_$v
DEBPIGSTY2.32.119 18 17 16 15postgresql-$v-pg-flight-recorderpostgresql-$v-cron
Linux / PGPG19PG18PG17PG16PG15
el8.x86_64N/APIGSTY 2.32.1PIGSTY 2.32.1PIGSTY 2.32.1PIGSTY 2.32.1
el8.aarch64N/APIGSTY 2.32.1PIGSTY 2.32.1PIGSTY 2.32.1PIGSTY 2.32.1
el9.x86_64PIGSTY 2.32.1PIGSTY 2.32.1PIGSTY 2.32.1PIGSTY 2.32.1PIGSTY 2.32.1
el9.aarch64PIGSTY 2.32.1PIGSTY 2.32.1PIGSTY 2.32.1PIGSTY 2.32.1PIGSTY 2.32.1
el10.x86_64PIGSTY 2.32.1PIGSTY 2.32.1PIGSTY 2.32.1PIGSTY 2.32.1PIGSTY 2.32.1
el10.aarch64PIGSTY 2.32.1PIGSTY 2.32.1PIGSTY 2.32.1PIGSTY 2.32.1PIGSTY 2.32.1
d12.x86_64PIGSTY 2.32.1PIGSTY 2.32.1PIGSTY 2.32.1PIGSTY 2.32.1PIGSTY 2.32.1
d12.aarch64PIGSTY 2.32.1PIGSTY 2.32.1PIGSTY 2.32.1PIGSTY 2.32.1PIGSTY 2.32.1
d13.x86_64PIGSTY 2.32.1PIGSTY 2.32.1PIGSTY 2.32.1PIGSTY 2.32.1PIGSTY 2.32.1
d13.aarch64PIGSTY 2.32.1PIGSTY 2.32.1PIGSTY 2.32.1PIGSTY 2.32.1PIGSTY 2.32.1
u22.x86_64PIGSTY 2.32.1PIGSTY 2.32.1PIGSTY 2.32.1PIGSTY 2.32.1PIGSTY 2.32.1
u22.aarch64PIGSTY 2.32.1PIGSTY 2.32.1PIGSTY 2.32.1PIGSTY 2.32.1PIGSTY 2.32.1
u24.x86_64PIGSTY 2.32.1PIGSTY 2.32.1PIGSTY 2.32.1PIGSTY 2.32.1PIGSTY 2.32.1
u24.aarch64PIGSTY 2.32.1PIGSTY 2.32.1PIGSTY 2.32.1PIGSTY 2.32.1PIGSTY 2.32.1
u26.x86_64PIGSTY 2.32.1PIGSTY 2.32.1PIGSTY 2.32.1PIGSTY 2.32.1PIGSTY 2.32.1
u26.aarch64PIGSTY 2.32.1PIGSTY 2.32.1PIGSTY 2.32.1PIGSTY 2.32.1PIGSTY 2.32.1
软件包版本平台仓库大小下载
pg_flight_recorder_192.32.1el9.x86_64pigsty98.4 KiBpg_flight_recorder_19-2.32.1-1PGSTY.el9.noarch.rpm
pg_flight_recorder_192.32.1el9.aarch64pigsty98.4 KiBpg_flight_recorder_19-2.32.1-1PGSTY.el9.noarch.rpm
pg_flight_recorder_192.32.1el10.x86_64pigsty98.6 KiBpg_flight_recorder_19-2.32.1-1PGSTY.el10.noarch.rpm
pg_flight_recorder_192.32.1el10.aarch64pigsty98.6 KiBpg_flight_recorder_19-2.32.1-1PGSTY.el10.noarch.rpm
postgresql-19-pg-flight-recorder2.32.1d12.x86_64pigsty92.2 KiBpostgresql-19-pg-flight-recorder_2.32.1-1PGSTY~bookworm_all.deb
postgresql-19-pg-flight-recorder2.32.1d12.aarch64pigsty92.2 KiBpostgresql-19-pg-flight-recorder_2.32.1-1PGSTY~bookworm_all.deb
postgresql-19-pg-flight-recorder2.32.1d13.x86_64pigsty92.1 KiBpostgresql-19-pg-flight-recorder_2.32.1-1PGSTY~trixie_all.deb
postgresql-19-pg-flight-recorder2.32.1d13.aarch64pigsty92.1 KiBpostgresql-19-pg-flight-recorder_2.32.1-1PGSTY~trixie_all.deb
postgresql-19-pg-flight-recorder2.32.1u22.x86_64pigsty94.1 KiBpostgresql-19-pg-flight-recorder_2.32.1-1PGSTY~jammy_all.deb
postgresql-19-pg-flight-recorder2.32.1u22.aarch64pigsty94.1 KiBpostgresql-19-pg-flight-recorder_2.32.1-1PGSTY~jammy_all.deb
postgresql-19-pg-flight-recorder2.32.1u24.x86_64pigsty93.8 KiBpostgresql-19-pg-flight-recorder_2.32.1-1PGSTY~noble_all.deb
postgresql-19-pg-flight-recorder2.32.1u24.aarch64pigsty93.8 KiBpostgresql-19-pg-flight-recorder_2.32.1-1PGSTY~noble_all.deb
postgresql-19-pg-flight-recorder2.32.1u26.x86_64pigsty93.8 KiBpostgresql-19-pg-flight-recorder_2.32.1-1PGSTY~resolute_all.deb
postgresql-19-pg-flight-recorder2.32.1u26.aarch64pigsty93.8 KiBpostgresql-19-pg-flight-recorder_2.32.1-1PGSTY~resolute_all.deb
软件包版本平台仓库大小下载
pg_flight_recorder_182.32.1el8.x86_64pigsty104.5 KiBpg_flight_recorder_18-2.32.1-1PGSTY.el8.noarch.rpm
pg_flight_recorder_182.32.1el8.aarch64pigsty104.5 KiBpg_flight_recorder_18-2.32.1-1PGSTY.el8.noarch.rpm
pg_flight_recorder_182.32.1el9.x86_64pigsty98.4 KiBpg_flight_recorder_18-2.32.1-1PGSTY.el9.noarch.rpm
pg_flight_recorder_182.32.1el9.aarch64pigsty98.4 KiBpg_flight_recorder_18-2.32.1-1PGSTY.el9.noarch.rpm
pg_flight_recorder_182.32.1el10.x86_64pigsty98.6 KiBpg_flight_recorder_18-2.32.1-1PGSTY.el10.noarch.rpm
pg_flight_recorder_182.32.1el10.aarch64pigsty98.6 KiBpg_flight_recorder_18-2.32.1-1PGSTY.el10.noarch.rpm
postgresql-18-pg-flight-recorder2.32.1d12.x86_64pigsty92.2 KiBpostgresql-18-pg-flight-recorder_2.32.1-1PGSTY~bookworm_all.deb
postgresql-18-pg-flight-recorder2.32.1d12.aarch64pigsty92.2 KiBpostgresql-18-pg-flight-recorder_2.32.1-1PGSTY~bookworm_all.deb
postgresql-18-pg-flight-recorder2.32.1d13.x86_64pigsty92.2 KiBpostgresql-18-pg-flight-recorder_2.32.1-1PGSTY~trixie_all.deb
postgresql-18-pg-flight-recorder2.32.1d13.aarch64pigsty92.2 KiBpostgresql-18-pg-flight-recorder_2.32.1-1PGSTY~trixie_all.deb
postgresql-18-pg-flight-recorder2.32.1u22.x86_64pigsty94.1 KiBpostgresql-18-pg-flight-recorder_2.32.1-1PGSTY~jammy_all.deb
postgresql-18-pg-flight-recorder2.32.1u22.aarch64pigsty94.1 KiBpostgresql-18-pg-flight-recorder_2.32.1-1PGSTY~jammy_all.deb
postgresql-18-pg-flight-recorder2.32.1u24.x86_64pigsty93.7 KiBpostgresql-18-pg-flight-recorder_2.32.1-1PGSTY~noble_all.deb
postgresql-18-pg-flight-recorder2.32.1u24.aarch64pigsty93.7 KiBpostgresql-18-pg-flight-recorder_2.32.1-1PGSTY~noble_all.deb
postgresql-18-pg-flight-recorder2.32.1u26.x86_64pigsty93.8 KiBpostgresql-18-pg-flight-recorder_2.32.1-1PGSTY~resolute_all.deb
postgresql-18-pg-flight-recorder2.32.1u26.aarch64pigsty93.8 KiBpostgresql-18-pg-flight-recorder_2.32.1-1PGSTY~resolute_all.deb
软件包版本平台仓库大小下载
pg_flight_recorder_172.32.1el8.x86_64pigsty104.5 KiBpg_flight_recorder_17-2.32.1-1PGSTY.el8.noarch.rpm
pg_flight_recorder_172.32.1el8.aarch64pigsty104.5 KiBpg_flight_recorder_17-2.32.1-1PGSTY.el8.noarch.rpm
pg_flight_recorder_172.32.1el9.x86_64pigsty98.4 KiBpg_flight_recorder_17-2.32.1-1PGSTY.el9.noarch.rpm
pg_flight_recorder_172.32.1el9.aarch64pigsty98.4 KiBpg_flight_recorder_17-2.32.1-1PGSTY.el9.noarch.rpm
pg_flight_recorder_172.32.1el10.x86_64pigsty98.6 KiBpg_flight_recorder_17-2.32.1-1PGSTY.el10.noarch.rpm
pg_flight_recorder_172.32.1el10.aarch64pigsty98.6 KiBpg_flight_recorder_17-2.32.1-1PGSTY.el10.noarch.rpm
postgresql-17-pg-flight-recorder2.32.1d12.x86_64pigsty92.2 KiBpostgresql-17-pg-flight-recorder_2.32.1-1PGSTY~bookworm_all.deb
postgresql-17-pg-flight-recorder2.32.1d12.aarch64pigsty92.2 KiBpostgresql-17-pg-flight-recorder_2.32.1-1PGSTY~bookworm_all.deb
postgresql-17-pg-flight-recorder2.32.1d13.x86_64pigsty92.1 KiBpostgresql-17-pg-flight-recorder_2.32.1-1PGSTY~trixie_all.deb
postgresql-17-pg-flight-recorder2.32.1d13.aarch64pigsty92.1 KiBpostgresql-17-pg-flight-recorder_2.32.1-1PGSTY~trixie_all.deb
postgresql-17-pg-flight-recorder2.32.1u22.x86_64pigsty94.1 KiBpostgresql-17-pg-flight-recorder_2.32.1-1PGSTY~jammy_all.deb
postgresql-17-pg-flight-recorder2.32.1u22.aarch64pigsty94.1 KiBpostgresql-17-pg-flight-recorder_2.32.1-1PGSTY~jammy_all.deb
postgresql-17-pg-flight-recorder2.32.1u24.x86_64pigsty93.7 KiBpostgresql-17-pg-flight-recorder_2.32.1-1PGSTY~noble_all.deb
postgresql-17-pg-flight-recorder2.32.1u24.aarch64pigsty93.7 KiBpostgresql-17-pg-flight-recorder_2.32.1-1PGSTY~noble_all.deb
postgresql-17-pg-flight-recorder2.32.1u26.x86_64pigsty93.8 KiBpostgresql-17-pg-flight-recorder_2.32.1-1PGSTY~resolute_all.deb
postgresql-17-pg-flight-recorder2.32.1u26.aarch64pigsty93.8 KiBpostgresql-17-pg-flight-recorder_2.32.1-1PGSTY~resolute_all.deb
软件包版本平台仓库大小下载
pg_flight_recorder_162.32.1el8.x86_64pigsty104.5 KiBpg_flight_recorder_16-2.32.1-1PGSTY.el8.noarch.rpm
pg_flight_recorder_162.32.1el8.aarch64pigsty104.5 KiBpg_flight_recorder_16-2.32.1-1PGSTY.el8.noarch.rpm
pg_flight_recorder_162.32.1el9.x86_64pigsty98.4 KiBpg_flight_recorder_16-2.32.1-1PGSTY.el9.noarch.rpm
pg_flight_recorder_162.32.1el9.aarch64pigsty98.4 KiBpg_flight_recorder_16-2.32.1-1PGSTY.el9.noarch.rpm
pg_flight_recorder_162.32.1el10.x86_64pigsty98.6 KiBpg_flight_recorder_16-2.32.1-1PGSTY.el10.noarch.rpm
pg_flight_recorder_162.32.1el10.aarch64pigsty98.6 KiBpg_flight_recorder_16-2.32.1-1PGSTY.el10.noarch.rpm
postgresql-16-pg-flight-recorder2.32.1d12.x86_64pigsty92.2 KiBpostgresql-16-pg-flight-recorder_2.32.1-1PGSTY~bookworm_all.deb
postgresql-16-pg-flight-recorder2.32.1d12.aarch64pigsty92.2 KiBpostgresql-16-pg-flight-recorder_2.32.1-1PGSTY~bookworm_all.deb
postgresql-16-pg-flight-recorder2.32.1d13.x86_64pigsty92.1 KiBpostgresql-16-pg-flight-recorder_2.32.1-1PGSTY~trixie_all.deb
postgresql-16-pg-flight-recorder2.32.1d13.aarch64pigsty92.1 KiBpostgresql-16-pg-flight-recorder_2.32.1-1PGSTY~trixie_all.deb
postgresql-16-pg-flight-recorder2.32.1u22.x86_64pigsty94.1 KiBpostgresql-16-pg-flight-recorder_2.32.1-1PGSTY~jammy_all.deb
postgresql-16-pg-flight-recorder2.32.1u22.aarch64pigsty94.1 KiBpostgresql-16-pg-flight-recorder_2.32.1-1PGSTY~jammy_all.deb
postgresql-16-pg-flight-recorder2.32.1u24.x86_64pigsty93.7 KiBpostgresql-16-pg-flight-recorder_2.32.1-1PGSTY~noble_all.deb
postgresql-16-pg-flight-recorder2.32.1u24.aarch64pigsty93.7 KiBpostgresql-16-pg-flight-recorder_2.32.1-1PGSTY~noble_all.deb
postgresql-16-pg-flight-recorder2.32.1u26.x86_64pigsty93.8 KiBpostgresql-16-pg-flight-recorder_2.32.1-1PGSTY~resolute_all.deb
postgresql-16-pg-flight-recorder2.32.1u26.aarch64pigsty93.8 KiBpostgresql-16-pg-flight-recorder_2.32.1-1PGSTY~resolute_all.deb
软件包版本平台仓库大小下载
pg_flight_recorder_152.32.1el8.x86_64pigsty104.5 KiBpg_flight_recorder_15-2.32.1-1PGSTY.el8.noarch.rpm
pg_flight_recorder_152.32.1el8.aarch64pigsty104.5 KiBpg_flight_recorder_15-2.32.1-1PGSTY.el8.noarch.rpm
pg_flight_recorder_152.32.1el9.x86_64pigsty98.4 KiBpg_flight_recorder_15-2.32.1-1PGSTY.el9.noarch.rpm
pg_flight_recorder_152.32.1el9.aarch64pigsty98.4 KiBpg_flight_recorder_15-2.32.1-1PGSTY.el9.noarch.rpm
pg_flight_recorder_152.32.1el10.x86_64pigsty98.6 KiBpg_flight_recorder_15-2.32.1-1PGSTY.el10.noarch.rpm
pg_flight_recorder_152.32.1el10.aarch64pigsty98.6 KiBpg_flight_recorder_15-2.32.1-1PGSTY.el10.noarch.rpm
postgresql-15-pg-flight-recorder2.32.1d12.x86_64pigsty92.2 KiBpostgresql-15-pg-flight-recorder_2.32.1-1PGSTY~bookworm_all.deb
postgresql-15-pg-flight-recorder2.32.1d12.aarch64pigsty92.2 KiBpostgresql-15-pg-flight-recorder_2.32.1-1PGSTY~bookworm_all.deb
postgresql-15-pg-flight-recorder2.32.1d13.x86_64pigsty92.1 KiBpostgresql-15-pg-flight-recorder_2.32.1-1PGSTY~trixie_all.deb
postgresql-15-pg-flight-recorder2.32.1d13.aarch64pigsty92.1 KiBpostgresql-15-pg-flight-recorder_2.32.1-1PGSTY~trixie_all.deb
postgresql-15-pg-flight-recorder2.32.1u22.x86_64pigsty94.1 KiBpostgresql-15-pg-flight-recorder_2.32.1-1PGSTY~jammy_all.deb
postgresql-15-pg-flight-recorder2.32.1u22.aarch64pigsty94.1 KiBpostgresql-15-pg-flight-recorder_2.32.1-1PGSTY~jammy_all.deb
postgresql-15-pg-flight-recorder2.32.1u24.x86_64pigsty93.7 KiBpostgresql-15-pg-flight-recorder_2.32.1-1PGSTY~noble_all.deb
postgresql-15-pg-flight-recorder2.32.1u24.aarch64pigsty93.7 KiBpostgresql-15-pg-flight-recorder_2.32.1-1PGSTY~noble_all.deb
postgresql-15-pg-flight-recorder2.32.1u26.x86_64pigsty93.8 KiBpostgresql-15-pg-flight-recorder_2.32.1-1PGSTY~resolute_all.deb
postgresql-15-pg-flight-recorder2.32.1u26.aarch64pigsty93.8 KiBpostgresql-15-pg-flight-recorder_2.32.1-1PGSTY~resolute_all.deb

源码

github.com/neptunestation-com/pg_flight_recorder

pig build pkg pg_flight_recorder;		# build rpm/deb

安装

启用 PGDG 和 PIGSTY 仓库并更新缓存。

pig repo add pgsql -u   # add both repo and update cache

使用 pig 安装扩展。

pig install pg_flight_recorder;		# install by package name
pig install pgfr_record;		# install by extension name

pig install pgfr_record -v 19;   # install for PG 19
pig install pgfr_record -v 18;   # install for PG 18
pig install pgfr_record -v 17;   # install for PG 17
pig install pgfr_record -v 16;   # install for PG 16
pig install pgfr_record -v 15;   # install for PG 15

在数据库中创建扩展。

CREATE EXTENSION pgfr_record CASCADE; -- requires pg_cron

用法

来源:

pgfr_record 是 PostgreSQL Flight Recorder 的记录部分。它定期采样 PostgreSQL 活动、等待、锁、复制、真空及相关健康数据,并将其存储在数据库内的有界缓冲区中,然后保留快照以供事故分析使用。当需要短生命周期的数据库条件能够存活足够长的时间以便后续诊断时,请使用此功能。

安装和启用记录

pgfr_record 需要 pg_cron:

CREATE EXTENSION pg_cron;
CREATE EXTENSION pgfr_record;
SELECT pgfr_record.enable();

enable() 会安装并调度收集器任务。它还会报告配置警告;请务必查看这些警告,而不要将成功调用视为所有指标都被收集的证明。

检查记录器健康状况

SELECT * FROM pgfr_record.health_check();
SELECT * FROM pgfr_record.ring_buffer_health();
SELECT * FROM pgfr_record.list_profiles();

在发生事故前使用 set_mode 或 apply_profile 选择所需的采集配置文件:

SELECT pgfr_record.set_mode('normal');

可用的采集模式包括正常、轻量级、紧急和终止。配置文件名称和采样间隔可能会发生变化,因此请列出已安装的配置文件而不是硬编码未记录的名称。

记录数据索引

  • deltas:累积 PostgreSQL 计数器的时间间隔变化。
  • recent_activity 和 recent_waits:采样的会话和等待事件。
  • recent_locks 和 recent_idle:锁和空闲会话观察结果。
  • recent_replication 和 recent_vacuum:复制和维护状态。
  • archiver_status:WAL 归档健康状况。
  • snapshot 和 ring-buffer 表:用于 pgfr_analyze 的保留历史记录。

许多工作缓冲区是 UNLOGGED 的,以减少写入放大。它们在崩溃后不可用,并且不会像普通已记录的表那样进行复制;持久化的快照提供了更长生命周期的分析表面。

管理函数

  • pgfr_record.enable():创建或激活计划收集器。
  • pgfr_record.disable():停止计划采集。
  • pgfr_record.health_check():报告收集器和配置健康状况。
  • pgfr_record.set_mode(…):更改采集模式。
  • pgfr_record.apply_profile(…):应用预定义的配置文件。
  • pgfr_record.list_profiles():列出可用的配置文件。
  • pgfr_record.ring_buffer_health():检查容量和保留压力。
  • pgfr_record.cleanup(…):根据 API 删除保留的历史记录。

保留和开销

默认设计保持短周期环形缓冲区历史记录,并且更持久化的快照通常在安装的配置文件不同而有所变化,大约为7天到30天。请验证实际表大小、作业调度以及保留设置。

pgfr_record 创建约十个 pg_cron 任务。pg_cron.log_run 每天可能会生成数千行记录;当额外的审计跟踪不再需要时,请禁用该日志或清除 cron 历史记录。采样还会增加 SQL、存储和目录流量,因此请在目标工作负载上测量开销。

版本 2.29.2 处理无法更新 cron.job 的管理服务角色:任务仍然可以被调度,而可选的 nodename 正则化会在警告中跳过。

注意事项

  • pg_stat_statements 可丰富多种分析但为可选项;当需要时,请单独启用并调整其大小。
  • 采集无法重建从未采样的时间周期。在发生事故前请启用并验证记录器。
  • UNLOGGED 缓冲区可能在崩溃恢复后被截断。
  • 记录器表可以包含查询文本、角色名称、客户端数据和操作细节。请应用适当的权限和保留控制。

表格阅读器