Skip to content

pg_tracing

Distributed Tracing for PostgreSQL

pg_tracing · Distributed Tracing for PostgreSQL

Overview

IDExtensionPackageVersionCategoryLicenseLanguage
6010pg_tracingpg_tracing0.1.3STATMITC
AttributeHas BinaryHas LibraryNeed LoadHas DDLRelocatableTrusted
--sLd-rNoYesYesYesyesno

Packages

TypeRepoVersionPG Major CompatibilityPackage PatternDependencies
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
PackageVersionOSORGSIZEFile URL
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
PackageVersionOSORGSIZEFile URL
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
PackageVersionOSORGSIZEFile URL
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
PackageVersionOSORGSIZEFile URL
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

Source

pig build pkg pg_tracing;		# build rpm/deb

Install

Make sure PGDG and PIGSTY repo available:

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

Install this extension with 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

Config this extension to shared_preload_libraries:

shared_preload_libraries = 'pg_tracing';

Create this extension with:

CREATE EXTENSION pg_tracing;

Usage

pg_tracing: distributed tracing for PostgreSQL

pg_tracing generates server-side spans for distributed tracing. It creates spans for planner, executor, plan nodes, nested queries, triggers, parallel workers, and transaction commits.

Trace Propagation via SQLCommenter

Pass trace context as a SQL comment. Queries with a sampled flag will generate spans:

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

Trace Propagation via GUC

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

Standalone Sampling

Randomly sample queries without external trace context:

SET pg_tracing.sample_rate = 1.0;  -- trace all queries
SELECT 1;

Viewing Spans

-- Consume spans (removes them from buffer)
SELECT trace_id, parent_id, span_id, span_start, span_end, span_type, span_operation
FROM pg_tracing_consume_spans ORDER BY span_start;

-- Peek at spans (non-destructive)
SELECT * FROM pg_tracing_peek_spans;

-- Export as OTLP JSON
SELECT pg_tracing_json_spans();

Statistics

SELECT * FROM pg_tracing_info;
SELECT pg_tracing_reset();

Sending Spans to OpenTelemetry Collector

Configure in postgresql.conf:

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

Key GUC Parameters

ParameterDefaultDescription
pg_tracing.max_span10000Maximum spans in shared memory
pg_tracing.trackallWhich statements to track
pg_tracing.sample_rate0Fraction of queries to sample randomly
pg_tracing.otel_endpoint(empty)OTLP HTTP endpoint for span export

Table reader