跳转到主要内容

pg_tracing

PostgreSQL分布式Tracing

pg_tracing · PostgreSQL分布式Tracing

概览

ID扩展软件包版本类别许可证编程语言
6010pg_tracingpg_tracing0.1.3STATMITC
属性可执行文件动态库需要预加载需要建扩展可迁移可信
--sLd-r否是是是是否

软件包

类型仓库版本兼容的 PostgreSQL 大版本包名模式依赖
EXTPIGSTY0.1.319 18 17 16 15pg_tracing-
RPMPIGSTY0.1.319 18 17 16 15pg_tracing_$v-
DEBPIGSTY0.1.319 18 17 16 15postgresql-$v-pg-tracing-
Linux / PGPG19PG18PG17PG16PG15
el8.x86_64N/APIGSTY 0.1.3PIGSTY 0.1.3PIGSTY 0.1.3PIGSTY 0.1.3
el8.aarch64N/APIGSTY 0.1.3PIGSTY 0.1.3PIGSTY 0.1.3PIGSTY 0.1.3
el9.x86_64N/APIGSTY 0.1.3PIGSTY 0.1.3PIGSTY 0.1.3PIGSTY 0.1.3
el9.aarch64N/APIGSTY 0.1.3PIGSTY 0.1.3PIGSTY 0.1.3PIGSTY 0.1.3
el10.x86_64N/APIGSTY 0.1.3PIGSTY 0.1.3PIGSTY 0.1.3PIGSTY 0.1.3
el10.aarch64N/APIGSTY 0.1.3PIGSTY 0.1.3PIGSTY 0.1.3PIGSTY 0.1.3
d12.x86_64N/APIGSTY 0.1.3PIGSTY 0.1.3PIGSTY 0.1.3PIGSTY 0.1.3
d12.aarch64N/APIGSTY 0.1.3PIGSTY 0.1.3PIGSTY 0.1.3PIGSTY 0.1.3
d13.x86_64N/APIGSTY 0.1.3PIGSTY 0.1.3PIGSTY 0.1.3PIGSTY 0.1.3
d13.aarch64N/APIGSTY 0.1.3PIGSTY 0.1.3PIGSTY 0.1.3PIGSTY 0.1.3
u22.x86_64N/APIGSTY 0.1.3PIGSTY 0.1.3PIGSTY 0.1.3PIGSTY 0.1.3
u22.aarch64N/APIGSTY 0.1.3PIGSTY 0.1.3PIGSTY 0.1.3PIGSTY 0.1.3
u24.x86_64N/APIGSTY 0.1.3PIGSTY 0.1.3PIGSTY 0.1.3PIGSTY 0.1.3
u24.aarch64N/APIGSTY 0.1.3PIGSTY 0.1.3PIGSTY 0.1.3PIGSTY 0.1.3
u26.x86_64N/APIGSTY 0.1.3PIGSTY 0.1.3PIGSTY 0.1.3PIGSTY 0.1.3
u26.aarch64N/APIGSTY 0.1.3PIGSTY 0.1.3PIGSTY 0.1.3PIGSTY 0.1.3
软件包版本平台仓库大小下载
pg_tracing_180.1.3el8.x86_64pigsty117.1 KiBpg_tracing_18-0.1.3-1PGSTY.el8.x86_64.rpm
pg_tracing_180.1.3el8.aarch64pigsty114.5 KiBpg_tracing_18-0.1.3-1PGSTY.el8.aarch64.rpm
pg_tracing_180.1.3el9.x86_64pigsty118.4 KiBpg_tracing_18-0.1.3-1PGSTY.el9.x86_64.rpm
pg_tracing_180.1.3el9.aarch64pigsty117.0 KiBpg_tracing_18-0.1.3-1PGSTY.el9.aarch64.rpm
pg_tracing_180.1.3el10.x86_64pigsty119.2 KiBpg_tracing_18-0.1.3-1PGSTY.el10.x86_64.rpm
pg_tracing_180.1.3el10.aarch64pigsty117.4 KiBpg_tracing_18-0.1.3-1PGSTY.el10.aarch64.rpm
postgresql-18-pg-tracing0.1.3d12.x86_64pigsty105.5 KiBpostgresql-18-pg-tracing_0.1.3-1PGSTY~bookworm_amd64.deb
postgresql-18-pg-tracing0.1.3d12.aarch64pigsty102.9 KiBpostgresql-18-pg-tracing_0.1.3-1PGSTY~bookworm_arm64.deb
postgresql-18-pg-tracing0.1.3d13.x86_64pigsty105.5 KiBpostgresql-18-pg-tracing_0.1.3-1PGSTY~trixie_amd64.deb
postgresql-18-pg-tracing0.1.3d13.aarch64pigsty103.5 KiBpostgresql-18-pg-tracing_0.1.3-1PGSTY~trixie_arm64.deb
postgresql-18-pg-tracing0.1.3u22.x86_64pigsty114.7 KiBpostgresql-18-pg-tracing_0.1.3-1PGSTY~jammy_amd64.deb
postgresql-18-pg-tracing0.1.3u22.aarch64pigsty113.8 KiBpostgresql-18-pg-tracing_0.1.3-1PGSTY~jammy_arm64.deb
postgresql-18-pg-tracing0.1.3u24.x86_64pigsty110.2 KiBpostgresql-18-pg-tracing_0.1.3-1PGSTY~noble_amd64.deb
postgresql-18-pg-tracing0.1.3u24.aarch64pigsty109.2 KiBpostgresql-18-pg-tracing_0.1.3-1PGSTY~noble_arm64.deb
postgresql-18-pg-tracing0.1.3u26.x86_64pigsty109.6 KiBpostgresql-18-pg-tracing_0.1.3-1PGSTY~resolute_amd64.deb
postgresql-18-pg-tracing0.1.3u26.aarch64pigsty108.1 KiBpostgresql-18-pg-tracing_0.1.3-1PGSTY~resolute_arm64.deb
软件包版本平台仓库大小下载
pg_tracing_170.1.3el8.x86_64pigsty117.2 KiBpg_tracing_17-0.1.3-1PGSTY.el8.x86_64.rpm
pg_tracing_170.1.3el8.aarch64pigsty114.5 KiBpg_tracing_17-0.1.3-1PGSTY.el8.aarch64.rpm
pg_tracing_170.1.3el9.x86_64pigsty118.3 KiBpg_tracing_17-0.1.3-1PGSTY.el9.x86_64.rpm
pg_tracing_170.1.3el9.aarch64pigsty117.0 KiBpg_tracing_17-0.1.3-1PGSTY.el9.aarch64.rpm
pg_tracing_170.1.3el10.x86_64pigsty119.3 KiBpg_tracing_17-0.1.3-1PGSTY.el10.x86_64.rpm
pg_tracing_170.1.3el10.aarch64pigsty117.4 KiBpg_tracing_17-0.1.3-1PGSTY.el10.aarch64.rpm
postgresql-17-pg-tracing0.1.3d12.x86_64pigsty105.4 KiBpostgresql-17-pg-tracing_0.1.3-1PGSTY~bookworm_amd64.deb
postgresql-17-pg-tracing0.1.3d12.aarch64pigsty103.1 KiBpostgresql-17-pg-tracing_0.1.3-1PGSTY~bookworm_arm64.deb
postgresql-17-pg-tracing0.1.3d13.x86_64pigsty105.6 KiBpostgresql-17-pg-tracing_0.1.3-1PGSTY~trixie_amd64.deb
postgresql-17-pg-tracing0.1.3d13.aarch64pigsty103.8 KiBpostgresql-17-pg-tracing_0.1.3-1PGSTY~trixie_arm64.deb
postgresql-17-pg-tracing0.1.3u22.x86_64pigsty129.4 KiBpostgresql-17-pg-tracing_0.1.3-1PGSTY~jammy_amd64.deb
postgresql-17-pg-tracing0.1.3u22.aarch64pigsty128.2 KiBpostgresql-17-pg-tracing_0.1.3-1PGSTY~jammy_arm64.deb
postgresql-17-pg-tracing0.1.3u24.x86_64pigsty110.3 KiBpostgresql-17-pg-tracing_0.1.3-1PGSTY~noble_amd64.deb
postgresql-17-pg-tracing0.1.3u24.aarch64pigsty109.3 KiBpostgresql-17-pg-tracing_0.1.3-1PGSTY~noble_arm64.deb
postgresql-17-pg-tracing0.1.3u26.x86_64pigsty109.7 KiBpostgresql-17-pg-tracing_0.1.3-1PGSTY~resolute_amd64.deb
postgresql-17-pg-tracing0.1.3u26.aarch64pigsty108.1 KiBpostgresql-17-pg-tracing_0.1.3-1PGSTY~resolute_arm64.deb
软件包版本平台仓库大小下载
pg_tracing_160.1.3el8.x86_64pigsty117.2 KiBpg_tracing_16-0.1.3-1PGSTY.el8.x86_64.rpm
pg_tracing_160.1.3el8.aarch64pigsty114.4 KiBpg_tracing_16-0.1.3-1PGSTY.el8.aarch64.rpm
pg_tracing_160.1.3el9.x86_64pigsty118.3 KiBpg_tracing_16-0.1.3-1PGSTY.el9.x86_64.rpm
pg_tracing_160.1.3el9.aarch64pigsty116.9 KiBpg_tracing_16-0.1.3-1PGSTY.el9.aarch64.rpm
pg_tracing_160.1.3el10.x86_64pigsty119.3 KiBpg_tracing_16-0.1.3-1PGSTY.el10.x86_64.rpm
pg_tracing_160.1.3el10.aarch64pigsty117.3 KiBpg_tracing_16-0.1.3-1PGSTY.el10.aarch64.rpm
postgresql-16-pg-tracing0.1.3d12.x86_64pigsty105.5 KiBpostgresql-16-pg-tracing_0.1.3-1PGSTY~bookworm_amd64.deb
postgresql-16-pg-tracing0.1.3d12.aarch64pigsty103.0 KiBpostgresql-16-pg-tracing_0.1.3-1PGSTY~bookworm_arm64.deb
postgresql-16-pg-tracing0.1.3d13.x86_64pigsty105.7 KiBpostgresql-16-pg-tracing_0.1.3-1PGSTY~trixie_amd64.deb
postgresql-16-pg-tracing0.1.3d13.aarch64pigsty103.6 KiBpostgresql-16-pg-tracing_0.1.3-1PGSTY~trixie_arm64.deb
postgresql-16-pg-tracing0.1.3u22.x86_64pigsty128.8 KiBpostgresql-16-pg-tracing_0.1.3-1PGSTY~jammy_amd64.deb
postgresql-16-pg-tracing0.1.3u22.aarch64pigsty127.7 KiBpostgresql-16-pg-tracing_0.1.3-1PGSTY~jammy_arm64.deb
postgresql-16-pg-tracing0.1.3u24.x86_64pigsty110.3 KiBpostgresql-16-pg-tracing_0.1.3-1PGSTY~noble_amd64.deb
postgresql-16-pg-tracing0.1.3u24.aarch64pigsty109.2 KiBpostgresql-16-pg-tracing_0.1.3-1PGSTY~noble_arm64.deb
postgresql-16-pg-tracing0.1.3u26.x86_64pigsty109.7 KiBpostgresql-16-pg-tracing_0.1.3-1PGSTY~resolute_amd64.deb
postgresql-16-pg-tracing0.1.3u26.aarch64pigsty108.0 KiBpostgresql-16-pg-tracing_0.1.3-1PGSTY~resolute_arm64.deb
软件包版本平台仓库大小下载
pg_tracing_150.1.3el8.x86_64pigsty119.7 KiBpg_tracing_15-0.1.3-1PGSTY.el8.x86_64.rpm
pg_tracing_150.1.3el8.aarch64pigsty116.7 KiBpg_tracing_15-0.1.3-1PGSTY.el8.aarch64.rpm
pg_tracing_150.1.3el9.x86_64pigsty121.3 KiBpg_tracing_15-0.1.3-1PGSTY.el9.x86_64.rpm
pg_tracing_150.1.3el9.aarch64pigsty120.1 KiBpg_tracing_15-0.1.3-1PGSTY.el9.aarch64.rpm
pg_tracing_150.1.3el10.x86_64pigsty122.3 KiBpg_tracing_15-0.1.3-1PGSTY.el10.x86_64.rpm
pg_tracing_150.1.3el10.aarch64pigsty120.8 KiBpg_tracing_15-0.1.3-1PGSTY.el10.aarch64.rpm
postgresql-15-pg-tracing0.1.3d12.x86_64pigsty108.1 KiBpostgresql-15-pg-tracing_0.1.3-1PGSTY~bookworm_amd64.deb
postgresql-15-pg-tracing0.1.3d12.aarch64pigsty105.4 KiBpostgresql-15-pg-tracing_0.1.3-1PGSTY~bookworm_arm64.deb
postgresql-15-pg-tracing0.1.3d13.x86_64pigsty108.2 KiBpostgresql-15-pg-tracing_0.1.3-1PGSTY~trixie_amd64.deb
postgresql-15-pg-tracing0.1.3d13.aarch64pigsty106.0 KiBpostgresql-15-pg-tracing_0.1.3-1PGSTY~trixie_arm64.deb
postgresql-15-pg-tracing0.1.3u22.x86_64pigsty132.1 KiBpostgresql-15-pg-tracing_0.1.3-1PGSTY~jammy_amd64.deb
postgresql-15-pg-tracing0.1.3u22.aarch64pigsty130.9 KiBpostgresql-15-pg-tracing_0.1.3-1PGSTY~jammy_arm64.deb
postgresql-15-pg-tracing0.1.3u24.x86_64pigsty113.3 KiBpostgresql-15-pg-tracing_0.1.3-1PGSTY~noble_amd64.deb
postgresql-15-pg-tracing0.1.3u24.aarch64pigsty112.5 KiBpostgresql-15-pg-tracing_0.1.3-1PGSTY~noble_arm64.deb
postgresql-15-pg-tracing0.1.3u26.x86_64pigsty112.2 KiBpostgresql-15-pg-tracing_0.1.3-1PGSTY~resolute_amd64.deb
postgresql-15-pg-tracing0.1.3u26.aarch64pigsty111.1 KiBpostgresql-15-pg-tracing_0.1.3-1PGSTY~resolute_arm64.deb

源码

pig build pkg pg_tracing;		# build rpm/deb

安装

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

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

使用 pig 安装扩展。

pig install pg_tracing;		# install by package name

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

将扩展加入 shared_preload_libraries,详见配置说明。

shared_preload_libraries = 'pg_tracing';

在数据库中创建扩展。

CREATE EXTENSION pg_tracing;

用法

pg_tracing: PostgreSQL 分布式追踪

pg_tracing 生成服务端 Span 用于分布式追踪。它为规划器、执行器、计划节点、嵌套查询、触发器、并行工作进程和事务提交创建 Span。

通过 SQLCommenter 传播追踪上下文

将追踪上下文作为 SQL 注释传递。带有采样标志的查询将生成 Span:

/*traceparent='00-00000000000000000000000000000123-0000000000000123-01'*/ SELECT 1;

通过 GUC 传播追踪上下文

BEGIN;
SET LOCAL pg_tracing.trace_context='traceparent=''00-00000000000000000000000000000005-0000000000000005-01''';
UPDATE pgbench_accounts SET abalance=1 WHERE aid=1;
COMMIT;

独立采样

无需外部追踪上下文,随机采样查询:

SET pg_tracing.sample_rate = 1.0;  -- 追踪所有查询
SELECT 1;

查看 Span

-- 消费 Span(从缓冲区移除)
SELECT trace_id, parent_id, span_id, span_start, span_end, span_type, span_operation
FROM pg_tracing_consume_spans ORDER BY span_start;

-- 查看 Span(非破坏性)
SELECT * FROM pg_tracing_peek_spans;

-- 导出为 OTLP JSON
SELECT pg_tracing_json_spans();

统计信息

SELECT * FROM pg_tracing_info;
SELECT pg_tracing_reset();

发送 Span 到 OpenTelemetry Collector

在 postgresql.conf 中配置:

pg_tracing.otel_endpoint = http://127.0.0.1:4318/v1/traces
pg_tracing.otel_naptime = 2000

关键 GUC 参数

参数默认值描述
pg_tracing.max_span10000共享内存中的最大 Span 数
pg_tracing.trackall追踪哪些语句
pg_tracing.sample_rate0随机采样查询的比例
pg_tracing.otel_endpoint(空)用于 Span 导出的 OTLP HTTP 端点

表格阅读器