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.
Coverage by deployment
| Self-hosted | Cloud-managed | |
|---|---|---|
| Server-side spans (query plan) | pg_tracing extension | Not available |
| Client spans (per query) | Backend SDK | Backend SDK |
| Query statistics | pg_stat_statements | pg_stat_statements |
| Database logs | Collected from files | Provider log channel |
| Configured in | Server arguments and collector | Application 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.
| Attribute | Server spans | Logs | Query statistics |
|---|---|---|---|
| Statement text | Yes | Yes | Normalized |
| Duration | Per plan node | Per statement | Total and mean |
| Plan nodes | Yes | No | No |
| Trace linkage | Direct parent/child | Joined by parsing the comment | No |
| Query ID | Yes | Yes | Yes |
| Database name | No | Yes | Per connection |
| Connecting user | No | Yes | Yes |
| Client address | No | Yes | No |
| Transaction ID | No | Yes | No |
| Backend type | No | Yes | No |
| Errors, locks, checkpoints | No | Yes | No |
| Unsampled queries | No | Yes | Yes |
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.
Related documentation
- Self-hosted PostgreSQL — building the
pg_tracingimage, server settings, verification - Cloud-managed PostgreSQL — SQLCommenter, query statistics, log channels