PostgreSQL instrumentation

The telemetry available from PostgreSQL depends on whether the database is self-operated or a cloud-managed service. This page compares the collection paths and the attributes each one provides.

SDK instrumentation observes the database from outside. The application's pg client records only that a query took 12ms; the processing within that interval is not captured. Capturing it requires the database to emit its own telemetry, and whether that is possible depends on who operates the database.

postgres-telemetry

Coverage by deployment

Self-hostedCloud-managed
Server-side spans (query plan)pg_tracing extensionNot available
Client spans (per query)Backend SDKBackend SDK
Query statisticspg_stat_statementspg_stat_statements
Database logsCollected from filesProvider log channel
Configured inServer arguments and collectorApplication and collector

Server-side spans are unavailable on managed services because of provider policy. pg_tracing is a C extension that must be registered in shared_preload_libraries, and AWS RDS and Aurora, Google Cloud SQL, and Azure Database all restrict preloading to a provider-vetted list that does not include it. There is no workaround.

Client spans and query statistics remain available on managed services. For identifying slow queries and detecting performance regressions, these two are often sufficient. What is not available is plan-level information on why a given query is slow.

Attributes by signal

The three paths do not provide the same data in different forms. Each provides different information.

AttributeServer spansLogsQuery statistics
Statement textYesYesNormalized
DurationPer plan nodePer statementTotal and mean
Plan nodesYesNoNo
Trace linkageDirect parent/childJoined by parsing the commentNo
Query IDYesYesYes
Database nameNoYesPer connection
Connecting userNoYesYes
Client addressNoYesNo
Transaction IDNoYesNo
Backend typeNoYesNo
Errors, locks, checkpointsNoYesNo
Unsampled queriesNoYesYes

Server spans are the only path that includes the database in the trace waterfall. Logs provide the widest set of attributes and record every statement regardless of sampling. Query statistics do not explain an individual request; they show change over time.

The paths are not exclusive. Enabling server spans alongside query statistics is the standard self-hosted configuration.

NOTE — The caller determines sampling

Server spans record only queries that arrived with a sampled traceparent. An idle database or a batch job producing no spans is expected behaviour. Where complete coverage is required, use logs or query statistics.