PostgreSQL metrics with the OpenTelemetry Collector

Scrape PostgreSQL with the OpenTelemetry Collector postgresql receiver, using a least-privilege role, checked metric stability and export to the backend you already run.

On this page

When the OpenTelemetry Collector is the right way to collect PostgreSQL metrics

A team that already runs OpenTelemetry, or wants one collection path for databases, services and infrastructure, should consider the Collector's postgresql receiver before adding a separate exporter for each database. The receiver connects to a PostgreSQL instance, reads database statistics on a schedule and emits them as metrics through the same pipeline that carries application telemetry. The choice is worth making deliberately, because it changes who owns the collection configuration, which credentials sit in the Collector and where the data lands.

OpenTelemetry is an observability framework and toolkit for generating, exporting and collecting traces, metrics and logs, and it is vendor- and tool-agnostic. It is not an observability backend. Nothing in the pipeline stores PostgreSQL metrics for long or draws dashboards, so the client must choose and operate a backend such as a time-series database, a log platform or a commercial service that accepts OTLP. The Collector can run as an agent beside each database host or application, or as a gateway that receives data from many sources and forwards it onward. A small team with a few instances often starts with agents, while a larger estate may route all database metrics through one gateway that holds the export credentials.

Confirm three things before committing. First, whether your existing backend accepts the metrics the receiver produces and how it names them, since a mismatch will show up as empty dashboards rather than errors. Second, whether the Collector distribution you plan to run includes the postgresql receiver, which ships in the contrib distribution, and what stability level that receiver carries in its README. Third, who owns the monitoring role and the Collector configuration, because both need change control like any other production dependency. Compare this path with a dedicated exporter if the team already has one working well.

Agent or gateway: how the Collector fits your topology

In an agent model, a Collector runs on or next to each PostgreSQL server and scrapes only the local instance. The database credentials stay on the host that already holds the data directory, and the scrape traffic never crosses the network. Each agent forwards its telemetry to the backend, so the backend sees many senders that must each be configured and kept current.

  • Credential placement: The monitoring role's password lives in every agent's configuration, so every host becomes a place where that secret must be stored, rotated and audited.
  • Failure isolation: A crashed or misconfigured agent affects one database's metrics, not the whole fleet.
  • Network paths: Database connections stay local, but each host needs an outbound path to the backend, which can add firewall rules across many servers.
  • Configuration drift: Changes to receivers, processors or exporters must reach every host, so configuration management becomes part of the design.
  • Resource use: The Collector shares CPU and memory with the database on the same machine, so measure its overhead under load before you choose this model.

Before you commit, confirm how your configuration management will push changes and rotate the monitoring password across every host.

Receiver settings and when each fits

This table compares the postgresql receiver settings a team must decide before scraping, with the situation each choice suits. Read each row as a decision: the config key, what it controls and the setup where it fits best. Confirm exact key names, defaults and metric lists against the receiver README for your Collector version before you copy any value.

SettingWhat it controlsWhen it fits
endpointHost and port the receiver connects to, such as a database server reachable from the Collector hostOne primary or a known standby per receiver block; use a separate block per instance so each series stays labeled to its server
databasesList of database names to collect per-database metrics fromFits when only a few application databases matter; a long list raises query load and series count, so start narrow and widen deliberately
collection_intervalHow often the receiver scrapes the serverShorter intervals suit incident work on a busy primary; longer intervals reduce load and storage cost for steady-state capacity trends. Confirm the default in the README
username and passwordLogin the receiver uses to query statistics viewsUse a dedicated least-privilege monitoring role, not a superuser or the application account; confirm the grants the receiver needs in its README
tls blockCertificate and verification settings for the connection to PostgreSQLRequired where the database enforces TLS or sits across a network boundary; choose verification mode with your security team and confirm the supported keys for your version
metrics blockEnables or disables individual metrics by nameFits when you need a narrow set for cost control; check each metric's stability level in the README before building alerts on it
resource_attributes settingsWhich resource attributes, such as server or cluster identifiers, are attached to each metricFits multi-instance estates where dashboards must separate clusters; agree naming with the team that owns the backend

Giving the Collector a monitoring role without over-privileging it

The monitoring role the Collector uses should be read-only and limited to the statistics views the postgresql receiver queries, so a leaked credential cannot change data, alter schema or read application tables. Create a dedicated login role with no ownership of application objects, no superuser or replication attributes, and no membership in roles that grant write access. PostgreSQL's cumulative statistics views, such as pg_stat_database and pg_stat_activity, are readable by default for most purposes, but some columns hide query text and other session details from non-privileged users, so the reader should confirm exact grants against the receiver documentation for the Collector version they run. Grant only what that documentation lists, and test the role by running the receiver's queries under it before going live.

Network scope is set in pg_hba.conf, which decides which hosts, databases and users may connect and by which method. Add a narrow entry that matches only the Collector's host address and the monitoring role, and place it above broader rules, because PostgreSQL evaluates entries in order and uses the first match. Avoid entries that match all databases or all users from a subnet. Check the file after each change with a connection attempt from an address that should be refused. The PostgreSQL authentication methods documentation lists the methods available, including password, certificate and directory-based options.

The authentication method is a security decision, not a formality. Password authentication with SCRAM is a common choice, and PostgreSQL 18 deprecated MD5 password authentication in favor of SCRAM, so any older MD5 entry for the monitoring role should be replaced. Certificate authentication avoids a stored password entirely and suits Collectors running in a fixed location, but it requires certificate issuance, rotation and revocation processes that the team must own. Whichever method is chosen, store the credential in the Collector's secret handling rather than in plain configuration files, and plan rotation with a documented owner. Confirm with your security team how the monitoring credential fits your existing access review.

Checking metric stability levels before you build dashboards

Metric names and stability levels decide how much rework your dashboards and alerts will need later. The cards below cover what to check in the Collector and its PostgreSQL receiver before you build, and how to keep a tested version in place once you do.

Receiver metrics have mixed stability

Core Collector components carry mixed stability levels, and the PostgreSQL receiver's metrics may not all share the same level. Treat each metric as a separate decision. Before you write alert rules, list every metric your dashboards depend on and record its stability level from the receiver's documentation. Metrics still in development are the ones most likely to change shape in a later release.

OpenTelemetry status

Find each component's stability in its README

The stability level of each component is documented in its README in the Collector repository, not only on the status page. Open the README for the postgresql receiver and the processors in your pipeline, then note the level and any metric-specific caveats. Repeat this check for each Collector release you adopt, because levels can change between versions.

Collector on GitHub

Renamed metrics break dashboards silently

If a metric is renamed or its attributes change, panels and alert rules that query the old name stop returning data rather than failing loudly. An alert that never fires looks the same as a healthy database. Build a check that confirms each critical query returns data after every Collector upgrade, and test alert rules against a known condition, such as a stopped test replica, before relying on them.

Pin the Collector version

Set an explicit Collector version in your deployment rather than a floating tag such as latest, so a metric change arrives only when your team chooses it. Releases are published on a regular cadence, so plan a periodic review of the release notes and component changes. Record the pinned version in your change records so auditors and on-call engineers can see what produced each metric.

Verify release artifacts before deploying

Collector releases ship the contrib distribution with signed artifacts, SHA256 checksums and SBOM files. Verify the checksum and signature of the binary or image you intend to deploy, and keep the SBOM with your asset inventory so you can answer vulnerability questions quickly. Confirm the verification steps for your packaging method in the release notes, since they differ between binaries, packages and container images.

Collector releases

How to set up the postgresql receiver step by step

This sequence takes you from an OpenTelemetry Collector distribution with the PostgreSQL receiver to confirmed PostgreSQL metrics in your existing backend. Each step closes with a check, so a fault shows up at the stage where it was introduced.

  1. Choose a distribution that includes the receiver

    The platform engineer selects a Collector build that contains the PostgreSQL receiver. The Collector project publishes a core distribution and a contrib distribution, and the PostgreSQL receiver is a contrib component, so confirm it is in the build you deploy. Check the receiver's README for its stability level before you rely on it, because core components have mixed stability levels. Done means the Collector starts and lists the postgresql receiver in its component inventory, and you have recorded the version you deployed so upgrades can be tested against it.

  2. Create a least-privilege monitoring role

    The DBA creates a dedicated PostgreSQL login for the Collector, separate from application and administrative accounts. Grant only the read access the receiver needs to the statistics views, and confirm the exact grants against the receiver documentation for your PostgreSQL version. Restrict the login to the network path the Collector uses in your pg_hba.conf, and prefer certificate or SCRAM-based authentication over shared passwords. Done means you can connect with that role from the Collector host and the role cannot read application tables or change data.

  3. Configure the receiver and metrics pipeline

    The observability engineer adds a postgresql receiver block to the Collector configuration with the endpoint, the monitoring username, and the databases to scrape, and keeps the password in an environment variable or secret rather than in the file. Define a metrics pipeline that connects the receiver to a processor such as batch, then to an exporter. Enable only the metrics your team needs and review each metric's stability level. Done means the configuration validates with the Collector's validate command and the Collector starts without errors in its own logs.

  4. Set the exporter and authentication extensions

    The platform engineer configures the exporter that sends metrics to your backend, using the endpoint and credentials your backend requires. Where the receiving side needs tokens, add an authenticator extension such as oauth2client to attach credentials to outgoing requests, and add an authenticator on any receiver that accepts incoming connections. Use TLS for exporter traffic and confirm the Collector's configuration best practices for securing endpoints. Done means the Collector reports the exporter as started and a test request to the backend returns an accepted status.

  5. Validate the first scrape

    The DBA or engineer runs the Collector in the foreground with debug output enabled and watches the first scrape cycle. Confirm that the receiver connects, that no permission errors appear for the monitoring role, and that metric names match the set you enabled. If a scrape fails with a permission error, correct the grant in the database rather than widening the role's privileges. Done means one complete scrape cycle logs successfully and the expected metric names appear in the debug output.

  6. Confirm metrics arrive in the backend

    The engineer opens your existing backend and queries for the PostgreSQL metric names and the resource attributes that identify each instance. Check that values update across two or more scrape intervals and that the instance labels match the naming your dashboards and alerts use. Confirm retention and the owner of the backend for this data before handing it over. Done means the metrics are visible, current and labeled consistently, and the team can locate them from a dashboard or query.

  7. Correlate with application traces

    The engineer sets matching resource attributes for service name and environment in the Collector and in the application SDK, so a database metric and an application trace can be filtered by the same identifiers. Test with one slow request: find the trace, then check the PostgreSQL metrics for the same time window. Done means a trace and the database metrics for that window can be found from a shared attribute, and the team has written down which attributes they rely on.

How PostgreSQL metrics flow from the database to your backend

The flow starts at the PostgreSQL server, where the monitoring role is the only identity the Collector's postgresql receiver uses to read statistics. The receiver passes data through processors inside the Collector, which exports it to your existing backend across a boundary you control. Application traces take a separate path into the same Collector. Check that the monitoring role's network path and credentials stay inside the database boundary, and that the export path is encrypted and authenticated.

Metrics and traces passing through the Collector to an existing backend, with trust boundaries marked.

Correlating database metrics with application traces

Correlation starts from a simple division of labor: the PostgreSQL receiver in the OpenTelemetry Collector supplies database metrics, while application traces come from services that your own teams have instrumented. The Collector does not create spans for your queries on its own, so a trace shows a slow database call only if the calling service emitted a span for it. Before you build dashboards that jump between the two, confirm which services in your estate are instrumented, which database client libraries they use, and whether those libraries record the database calls as spans. That instrumentation sits in code you own, and its coverage will be uneven across services unless someone owns it.

Three conditions have to hold for the two signals to line up. First, both must carry consistent resource attributes, such as service.name, service.namespace and deployment.environment, with the same values for the same system, so the backend can group a database instance with the services that depend on it. Second, the hosts running the Collector, the PostgreSQL servers and the application hosts need synchronized clocks, because a metric sample and a span are only comparable when their timestamps come from a reliable source. Third, the backend must be able to query metrics and traces together, typically through shared labels or a common dashboard, and it must expose trace-to-metric or exemplar links if you want to move between them. Confirm each of these with your backend's documentation, since support for exemplars and cross-signal navigation varies by product and version.

Plan this work as a short design task before you tune the receiver. List the attribute names and values your teams will use, write them into the Collector's resource processing and your instrumentation standards, and test one slow query end to end: find the span in the calling service, find the matching database sample, and confirm both appear on the same timeline. Keep the receiver's connection details and monitoring role separate from application credentials, and agree in writing who maintains each instrumentation library, because correlation breaks silently when a service upgrade changes its attribute names.

Securing the Collector and its credentials

The Collector sits between your PostgreSQL servers and your backend, so it holds database credentials and accepts telemetry from other systems. The cards below cover where those credentials live, how connections are authenticated, which endpoints are exposed, and how to check the configuration before it runs in production.

Keep database credentials out of plain configuration

The postgresql receiver connects with a monitoring role, and that password would otherwise sit in the Collector's YAML file. Load it from an environment variable or a secret file managed by your platform, and restrict who can read the configuration directory. Confirm the receiver's current options for password and TLS settings in the component README for your Collector version, since they are documented per component.

Collector configuration

Use a read-only monitoring role

The Collector only needs statistics views, so the role it connects with should have no write or superuser rights. Give it the minimum grants the receiver needs and nothing else, and review them after each PostgreSQL upgrade. If a grant is missing, confirm the required privilege with the receiver documentation rather than widening the role to superuser.

Authenticate incoming telemetry

Receivers that accept data from applications or other agents can be protected with authenticator extensions, for example OIDC. Without one, any host that can reach the port may send telemetry that your backend then trusts. Decide which senders must authenticate, configure the extension on those receivers, and test that an unauthenticated request is rejected.

Authenticate outgoing exports

The oauth2client extension adds credentials to requests the Collector sends to your backend. This keeps backend tokens out of individual exporter blocks and lets you rotate them in one place. Confirm which exporters accept an authenticator reference in your Collector distribution, and confirm that the backend itself requires the credential you configure.

Restrict receiver endpoints

Bind receivers to the interface and port your design requires instead of all addresses, and limit reachability with network policy or host firewall rules. Pair this with TLS for traffic that leaves the host. Check each receiver's endpoint setting in its README, because defaults differ between components.

Check the configuration against best practices

Before rollout, review the configuration against the Collector's security best practices guide, and record the Collector version so the review applies to a known build. Pin the version, validate the file in a test environment, and repeat the review when you change receivers or exporters. Treat any component marked as in development as a risk to assess before using it for credentials.

Configuration best practices

What teams ask before bringing in outside help on PostgreSQL OpenTelemetry metrics

What drives the effort and cost of setting up OpenTelemetry Collector monitoring for PostgreSQL?

The main drivers are the number of PostgreSQL clusters and databases, how many environments need coverage, and how many existing backends the metrics must reach. Each Collector pipeline needs a receiver configuration, processors for filtering and resource attributes, and an exporter to your current backend, so more destinations and more clusters mean more configuration to write, test and review. Cost also depends on whether the Collector runs as an agent beside each database or as a gateway for many sources, because that choice changes deployment, access and upgrade work. Ask any provider to price these items separately and to state what is one-time (design, build, testing) and what recurs (upgrades, configuration changes, support retainers).

How long does a PostgreSQL metrics rollout with the Collector usually take?

Duration depends on the environment rather than on the Collector alone. The time is shaped by how quickly the database team can create a monitoring role with the privileges the receiver needs, how many clusters are in scope, whether network paths and TLS for the exporter are already in place, and how much your backend's dashboards and alert rules must be rebuilt. Environments with change control, separate staging and production approvals, or air-gapped package mirrors usually take longer to move through. No fixed duration applies to every estate, so ask for a timeline built from a written scope that lists these dependencies.

What must our team provide before an outside engineer starts?

Expect to supply access and decisions rather than code. The usual inputs are:

  • A list of PostgreSQL versions, cluster topology and hosting model, including any managed services that restrict built-in views.
  • An approved monitoring database role and a review of which statistics views it may read, following the permissions the receiver documents.
  • The name, endpoint and authentication method of your existing metrics backend, plus any token or OAuth settings required for export.
  • Decisions on which metric stability levels you accept in production, and who signs off on that choice.
  • Test environments or a change window where the Collector configuration can be validated before it reaches production.

Without these, the work stalls at discovery, so confirm the list during scoping.

Can an internal platform or database team set up PostgreSQL metrics with the Collector alone?

Often yes, if the team already runs the Collector, understands PostgreSQL statistics views and has a backend that accepts OpenTelemetry data. The receiver configuration is not the hardest part. The harder work is least-privilege role design, validating which metrics are stable enough to alert on, correlating database metrics with application traces, and keeping configuration under version control through Collector upgrades. Teams without any prior Collector experience usually need more time for these steps. A useful test is whether someone on the team can explain each pipeline stage and roll back a failed change without outside help.

Which parts of the Collector setup create security or compliance questions?

The Collector sits between your databases and your backend, so it handles credentials, network paths and telemetry that may contain sensitive identifiers. Review these points with your security team:

  • The monitoring role should be read-only and limited to the statistics it needs.
  • Credentials for the receiver and exporter should come from a secrets store, not plain text files.
  • Incoming and outgoing connections should use TLS and authenticator extensions where your policy requires them.
  • Query text and resource attributes should be filtered before export if they could expose data.

The Collector's configuration best practices guidance covers several of these items. Compliance evidence, such as audit logs or control mapping, is prepared by your team and reviewed by independent auditors, since DeployOpen prepares systems and evidence but does not issue audit reports.

How should we compare quotes for PostgreSQL metrics work on the Collector?

Compare quotes on the written scope, not the headline figure. Check that each quote names the PostgreSQL versions, clusters, environments and backends covered, and whether it includes discovery, role design, configuration, testing, handover and documentation. Ask whether the Collector build is pinned to a specific release and how upgrades are handled, since releases ship on a regular cadence. Confirm what is one-time and what recurs, whether retesting after changes is included, and what the client must provide. A quote that cannot tie its price to listed deliverables is hard to verify against the work actually done.

What should we verify about metric stability before relying on the data?

Verify stability per metric, not per project. OpenTelemetry documents that core Collector components have mixed stability levels, and each component's README states its status. The PostgreSQL receiver's metrics may differ in maturity, so alerts should only rely on metrics whose stability your team has accepted. Confirm the Collector distribution you deploy includes the receiver, check the release notes for changes between versions, and test dashboards after each upgrade. Keep a short register of which metrics feed alerts so a change in stability is caught before an incident.

How DeployOpen scopes and delivers PostgreSQL metrics collection

DeployOpen plans, builds and hands over PostgreSQL metrics collection with the OpenTelemetry Collector inside your own infrastructure. The work starts from a written scope that names the database hosts, the monitoring role, the pipelines and the backend that will receive the data.

How we scope

  • We inventory PostgreSQL versions, hosts, databases and the monitoring role each cluster will use before any configuration begins.
  • The written scope names the Collector deployment model, receiver settings, metric stability levels and the existing backend that receives data.
  • Engagements are fixed-scope, with deliverables and timelines agreed in writing before work starts; a quote follows from that scope.

How we build

  • We create a least-privilege monitoring role and verify which statistics views it can read on each PostgreSQL instance.
  • We configure the postgresql receiver, process and export pipelines, and check that the metric names your dashboards use are present.
  • We test trace and metric correlation with application services so that database spans and metrics line up in your existing tools.

How we hand over

  • You receive the Collector configuration, pipeline diagrams, role grants and a record of the Collector version and component stability levels used.
  • Documentation covers how to add a new PostgreSQL target, rotate the monitoring credential and upgrade the Collector distribution.
  • We walk your platform and database teams through the configuration and the verification steps so they can review the setup themselves.

How we support

  • Ongoing support, Collector upgrades and continuous testing are available as retainers, scoped in writing.
  • Upgrades are planned against Collector release notes, since component stability and configuration keys can change between releases.
  • Recurring tasks after handover include reviewing dropped metrics, updating receiver settings after PostgreSQL major upgrades and reviewing access.

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.