Cloud-managed PostgreSQL
Client spans, query statistics, and logs — the three paths available where extensions cannot be installed, as on RDS, Aurora, Cloud SQL, and Azure Database.
Managed services do not permit third-party extensions in shared_preload_libraries. pg_tracing cannot be installed, and the database log files are not accessible. Three paths remain: spans produced by the application, query statistics read over a standard client connection, and logs the provider exports through its own channel.
Why the extension is unavailable
pg_tracing is a C extension that must be preloaded at server start. AWS RDS and Aurora, Google Cloud SQL, and Azure Database for PostgreSQL all restrict preloading to a provider-vetted list, and pg_tracing appears on none of them. This is not a restriction that a parameter group or database flag can work around.
Database logs are unavailable for the same reason. The file system is not exposed, so collecting log files directly is not possible.
1. Client spans
This is the first path to establish, and it requires no additional infrastructure. The Sophonz backend SDK instruments the database client and creates a span per query, carrying the statement, the target database, the connection target, and the duration. The span joins the same trace as the API request that issued it, together with the screen and user session associated with that request.
Enabling SQLCommenter also sends traceparent down as a comment on the query text. It is off by default, so it has to be configured. On a managed service there is no extension to read it and create spans, but the comment itself is recorded in the provider's logs. If those logs are collected later, that value is what joins them to the trace.
NOTE — Information not available on managed services
Client spans report precisely which query took how long. What is not available is which plan node consumed that time. Identifying a slow query is unaffected; only the final step of explaining the cause is missing.
2. Query statistics
pg_stat_statements is a provider-supported extension, and the collector connects as a standard client, so this path works unchanged on managed services. It reads per-query call counts, total execution time, mean, and rows returned on an interval, and converts them into metrics.
This path does not explain an individual request. It shows which queries' mean execution time increased across a deployment, and which queries' call counts rose sharply. For regression detection it is the more suitable signal.
Enabling it
All three providers support the extension, but it is enabled in different places.
| Provider | How it is enabled |
|---|---|
| AWS RDS and Aurora | Add to shared_preload_libraries in the parameter group, then reboot |
| Google Cloud SQL | Add as a database flag, then restart |
| Azure Database for PostgreSQL | Add as a server parameter, then restart |
Then create the extension in the target database.
CREATE EXTENSION IF NOT EXISTS pg_stat_statements;Collector configuration
The sqlquery receiver connects with a read-only account and polls on an interval.
receivers:
sqlquery/postgres:
driver: postgres
datasource: "host=${env:PG_HOST} port=5432 user=${env:PG_USER} password=${env:PG_PASSWORD} dbname=postgres sslmode=require"
collection_interval: 60s
queries:
- sql: >
SELECT queryid::text AS queryid,
calls,
mean_exec_time
FROM pg_stat_statements
ORDER BY total_exec_time DESC
LIMIT 200
metrics:
- metric_name: postgresql.query.calls
value_column: calls
attribute_columns: [queryid]
value_type: int
data_type: sum
monotonic: true
aggregation: cumulative
- metric_name: postgresql.query.mean_time
value_column: mean_exec_time
attribute_columns: [queryid]
value_type: double
data_type: gauge
unit: msThe limit is present because of cardinality. pg_stat_statements can hold thousands of entries, and converting all of them into metrics creates one time series per query.
queryid can also be attached to application spans, which provides a path back: locate the query in the metrics, then follow the same ID into the traces.
CAUTION — Check the collector build
The sqlquery receiver is not part of the standard Sophonz collector distribution. Contact us to enable it in a self-hosted deployment or to use it on a managed one.
3. Database logs
This path provides the widest set of attributes but requires the most pipeline configuration. Managed services export logs to their own channel rather than to a file.
| Provider | Log destination |
|---|---|
| AWS RDS and Aurora | CloudWatch Logs |
| Google Cloud SQL | Cloud Logging |
| Azure Database for PostgreSQL | Azure Monitor |
First enable structured logging in the database. JSON output is required for stable parsing.
log_destination = jsonlog
log_min_duration_statement = 500
log_line_prefix = ''log_min_duration_statement is the logging threshold. Setting it to 0 logs every statement, which produces an impractical volume of logs on a database carrying production traffic.
The collector then collects from the provider's channel. On AWS, the awscloudwatch receiver subscribes to the log group. The attributes obtained on this path are the database name, connecting user, client address, transaction ID, and backend type, along with events that are not represented as spans, such as errors, locks, and checkpoints.
CAUTION — Check the collector build
The receivers and parsing processors this path requires are also absent from the standard distribution. They are configured during onboarding.
Recommended order
There is no need to enable all three at once. The following order is recommended.
- Client spans — available as soon as the SDK is applied. Most slow queries are identified at this stage.
- Query statistics — requires only the extension and a read-only account. Where regression detection is the objective, this stage provides the greatest benefit relative to effort.
- Logs — add where there is an audit requirement, or where errors and locks must be visible alongside the other signals.
Where plan-level information is a firm requirement, the remaining option is to operate the database directly. See Self-hosted PostgreSQL.