3 min read
|
Saved February 14, 2026
|
Copied!
Do you care about this?
pg_tracing is a PostgreSQL extension that creates server-side spans for tracking query performance and execution. It supports various PostgreSQL events and allows trace context propagation through SQL comments or GUC parameters. The extension is currently in early development and works with PostgreSQL versions 14 to 16.
If you do, here's more
pg_tracing is a PostgreSQL extension designed for generating server-side spans to facilitate distributed tracing. When activated, it creates spans for sampled queries, allowing users to analyze performance and behavior. Accessing these spans can be done through the views pg_tracing_consume_spans and pg_tracing_peek_spans, or by using the pg_tracing_json_spans function, which outputs spans in OTLP JSON format. The extension also includes utility functions like pg_tracing_reset and pg_tracing_info, which help manage and view extension statistics, though these must be enabled on a per-database basis.
Trace context propagation can occur in two ways: via SQL comments with SQLCommenter or through the GUC parameter pg_tracing.trace_context. The extension currently supports PostgreSQL versions 14, 15, and 16. It tracks multiple events including internal PostgreSQL functions, various SQL statements (SELECT, INSERT, DELETE), execution plans, nested queries, triggers, parallel workers, and transaction commits. Each of these events generates a span, providing detailed insights into query execution.
To install pg_tracing, users need to compile it against PostgreSQL using PGXS. Installation steps involve cloning the repository, navigating to the pg_tracing directory, and running the make install command. Configuration involves updating the postgresql.conf file to include pg_tracing in the shared_preload_libraries, followed by a server restart. Users can also control the tracing behavior using the pg_tracing.sample_rate parameter, which can be set to 1 to trace all queries. For automated span submission, the extension can send spans to an OTLP collector by defining an endpoint in the configuration.
The extension is still in early development, so users should approach it with caution, as stability isn't guaranteed. The additional memory requirements for pg_tracing depend on the max span setting, which is critical for understanding resource consumption when the extension is enabled.
Questions about this article
No questions yet.