postgresql-otel
by Helm
A Helm chart to monitor PostgreSQL with New Relic's OpenTelemetry distribution (NRDOT)
About this chart
postgresql-otel
Deploys New Relic's NRDOT OpenTelemetry collector configured with the
nrpostgresql receiver (currently Preview) to monitor PostgreSQL and
export the results to New Relic over OTLP. One release runs one collector
pod, monitoring either a single PostgreSQL instance (postgresql:) or
multiple instances (postgresqlMulti:) — see "Which mode do I need?"
below.
Which mode do I need?
| Your situation | Use | Schema |
|---|---|---|
| One PostgreSQL instance (one or more databases on it) | Single-instance mode | postgresql: |
| Multiple instances, one release | Multi-instance mode | postgresqlMulti: |
Important naming distinction, unrelated to which mode you pick:
"databases" always means individual database names on one PostgreSQL
server — PostgreSQL has no "monitor every database" mode, so both modes
require you to list them explicitly. "Instance" means a separate
PostgreSQL server. postgresqlMulti.instances is a list of instances,
and each instance entry has its own databases list — so multi-instance
mode is instances × databases-per-instance, not a rename of the existing
postgresql.databases concept.
The two modes are mutually exclusive within a single release — setting
both postgresql.server and postgresqlMulti.enabled: true fails the
render. Aside from that schema choice, everything below through "Automated
setup" applies to both modes: server-level prerequisites, networking, and
the setup Job all work the same way, just applied per instance (and per
database within each instance) in the multi case.
What this chart does not do
- Configure TLS. This chart does not expose or render any
tlsblock for the receiver; it connects with whatever thenrpostgresqlreceiver's own defaults are. - Support
db_authcredential providers (e.g. AWS IAM authentication instead of a static password). The receiver supports adb_authblock, mutually exclusive withpassword, but this chart always configures a username/password credential. Reachable viaadditionalReceiverConfigif you need it, though you'd also need to work around this chart always rendering apassword. - Automate the server-level prerequisites. See the next section — they require a database restart, which nothing running inside your Kubernetes cluster can perform.
- Mix topologies within one release —
postgresqlMultirequires every instance to share one topology, and a single-instance release only ever has one topology by definition. - Report host/infrastructure metrics for the machine(s) PostgreSQL runs
on. New Relic's docs show a "Full-feature configuration" adding a
host_metricsreceiver and split host/db/traces pipelines — that only makes sense for a collector running directly on the PostgreSQL host's own OS. This chart implements only the standalone "Standard configuration" shape.
Server-level prerequisites — do this first
PostgreSQL 14 or newer is required. Before installing this chart (or
enabling setupJob), the following server parameters must be in place, on
every instance you plan to monitor. pg_stat_statements cannot be
created at all without shared_preload_libraries, and that parameter
requires a restart — so this cannot be automated from inside the
cluster.
| Parameter | Value |
|---|---|
shared_preload_libraries | pg_stat_statements |
pg_stat_statements.track | ALL |
pg_stat_statements.max | 10000 |
pg_stat_statements.save | on |
track_activity_query_size | 4096 |
track_functions | all |
- Self-hosted: set these in
postgresql.conf, then restart PostgreSQL. Some distributions need thepostgresql-contribpackage installed forpg_stat_statementsto be available. - Amazon RDS / Aurora: set these in the DB parameter group, not a
config file.
track_activity_query_sizeandpg_stat_statements.maxare static parameters — apply them withapply_method: pending-rebootand then reboot the instance. Applying them immediately fails withInvalidParameterCombination. For Aurora, the parameter-group family name must match your engine's major version exactly (e.g.aurora-postgresql16).
Choosing the topology
| Your setup | Topology value |
|---|---|
| Amazon RDS for PostgreSQL | rds |
| Self-hosted PostgreSQL (reached over the network) | self-hosted |
This is postgresql.topology in single-instance mode, or
postgresqlMulti.topology in multi-instance mode — always required either
way, but it does not currently change any rendered output. It exists for
documentation clarity and as a validated, forward-compatible schema slot,
the same precedent as mssql-otel's and mysql-otel's topology.
Choosing the config profile
postgresql.configProfile (single-instance) or
postgresqlMulti.configProfile (multi-instance, applies to every instance)
selects how many metrics the receiver collects. Both default to basic.
| Profile | Metrics collected |
|---|---|
basic | The 7 core metrics (locks, deadlocks, function calls, query conflicts, sequential scans, temp I/O, temp files) |
advanced | New Relic's full PostgreSQL metric catalog: 21 metrics, adding block hits/reads, tuple counters, query execution time, WAL delay and the pgvector metrics |
The Advanced catalog is the same for self-hosted and rds. Only the
receiver's metrics block differs; events, query collection, resource
attributes, the exporter and the setup job are identical. Start with basic
and move to advanced once collection is verified.
additionalReceiverConfig still overrides either profile.
postgresql:
topology: "rds"
configProfile: "advanced"
databases and excludeDatabases
In single-instance mode, postgresql.databases is a required,
non-empty list:
postgresql:
databases:
- appdb
- reporting
In multi-instance mode, each entry in postgresqlMulti.instances has its
own required, non-empty databases list, with the same meaning — see
"Which mode do I need?" above for why this isn't the same thing as the
list of instances itself.
excludeDatabases (a shared, hardcoded default of [rdsadmin] in both
modes — not a values.yaml field) exists because top-query and
query-sample collection scan cluster-wide regardless of the databases
list, and on RDS the monitoring user can never reach rdsadmin. It's only
applied when the topology is rds — on self-hosted PostgreSQL that
database doesn't exist, so it's omitted there.
Networking prerequisites
- Self-hosted: the collector Pod needs a routed path to each
instance's
server:port(VPN, peering, or shared network), DNS resolution if it's a hostname, and the PostgreSQL-sidepg_hba.conf/firewall must allow the connection's actual source IP (which may be a NAT gateway, not the Pod IP itself). - RDS: your cluster needs VPC peering, a transit gateway, or shared-VPC placement with each RDS instance, and each RDS security group must allow the PostgreSQL port (5432 by default) from the cluster's egress source.
In multi-instance mode, these requirements apply per instance — one pod reaching N instances still needs a valid network path to all N of them.
Automated setup (setupJob.enabled: true)
If enabled, a Helm hook Job creates the monitoring role and, for every
database in scope, creates the otel schema, grants the monitoring user
USAGE/SELECT/pg_monitor, and creates the pg_stat_statements
extension:
- Single-instance: one Job, looping over every entry in
postgresql.databases, usingpostgresql.username/postgresql.existingSecretfor the monitoring role andsetupJob.postgresAdmin.existingSecretfor the admin credential. - Multi-instance: one Job per instance (named
<release>-setup-<name>), each looping over that instance's owndatabaseslist, using that instance's ownexistingSecretandpostgresAdmin.existingSecret— separate PostgreSQL instances normally have independent admin passwords, so there's no shared admin credential option.
Every admin credential must be a superuser (self-hosted) or an
rds_superuser-equivalent (RDS), since it needs CREATE USER,
CREATE SCHEMA, and CREATE EXTENSION.
This requires a psql-capable image (shared across every instance's Job
in multi-instance mode — one image, not one per instance), and this
chart ships no default one — unlike mysql-otel, no free,
actively-maintained PostgreSQL-client image has been verified for this
purpose yet. The official postgres image bundles psql and is a
reasonable choice:
--set setupJob.image.repository=postgres --set setupJob.image.tag=16
Two extras, applied to every database in every instance identically (single shared toggle, not per-instance or per-database):
setupJob.enablePgvector: true(defaultfalse, opt-in) also runsCREATE EXTENSION IF NOT EXISTS vectorin each database, for vector metrics (thel1/hamming/jaccarddistance functions need pgvector 0.7.0+).setupJob.enableExplainPermissions(defaulttrue, opt-out) also creates theotel.explain_statementSECURITY DEFINERfunction and grantsEXECUTEon it, letting the receiver runEXPLAINagainst locking/write queries without holding write grants. Set tofalseto skip creating it.
You usually don't need to set explain_function_name
The receiver's own default for top_query_collection. explain_function_name is already otel.explain_statement — the exact
function setupJob.enableExplainPermissions creates. This isn't a
values.yaml field in either single- or multi-instance mode — it's a
fixed default the receiver already applies with no extra configuration.
Use additionalReceiverConfig.top_query_collection.explain_function_name
if you need a non-default function name.
The receiver probes for the function's availability per database and
re-checks periodically (the receiver's own default caching behavior;
this chart doesn't expose a value to override it), falling back to
inline EXPLAIN when it isn't there — so setting
enableExplainPermissions: false is safe and simply means write and
locking statements don't get query plans.
Credential handling in the setup Job
Unlike this chart family's other setup Jobs, credentials are not
shell-expanded into SQL text. The admin credential reaches psql through
its own PGUSER/PGPASSWORD environment variables (never as CLI flags,
so it stays out of any in-Pod process listing), and the monitoring
credentials are passed as psql variables interpolated by psql itself
as a quoted identifier (:"monitor_user") or quoted literal
(:'monitor_password'). Every heredoc is single-quoted, so the shell
performs no expansion inside them. A password containing quotes or
dollar signs is handled correctly.
If you'd rather not grant admin access
Leave setupJob.enabled: false and run the equivalent SQL yourself as a
superuser, on every instance you plan to monitor. Cluster-level, once:
CREATE USER nr_monitor WITH LOGIN PASSWORD '<password>';
ALTER ROLE nr_monitor INHERIT; -- required on PG15+, a no-op on PG14
Then in every database you're monitoring on that instance:
CREATE SCHEMA IF NOT EXISTS otel;
GRANT USAGE ON SCHEMA otel TO nr_monitor;
GRANT USAGE ON SCHEMA public TO nr_monitor;
GRANT SELECT ON ALL TABLES IN SCHEMA public TO nr_monitor;
GRANT pg_monitor TO nr_monitor;
CREATE EXTENSION IF NOT EXISTS pg_stat_statements;
Single-instance schema (postgresql:)
The default mode — one release, one PostgreSQL instance, one or more databases on it:
postgresql:
topology: "self-hosted"
server: "postgresql.example.internal"
port: 5432
existingSecret: "db-monitor-creds" # or username/password as plain values
databases:
- appdb
- reporting
otlpEndpoint: "otlp.nr-data.net:4317"
licenseKey: "<your New Relic license key>"
Unlike multi-instance mode, plain-value credentials are allowed here
(postgresql.username/postgresql.password) if you don't want to create
a Secret yourself — mainly useful for quick local testing, not recommended
for production. postgresql.existingSecret wins over the plain values if
both are set.
Multi-instance schema (postgresqlMulti:)
Setting postgresqlMulti.enabled: true switches to an alternative, fully
opt-in mode: one release, one collector pod, monitoring every entry in
postgresqlMulti.instances. This is additive: postgresqlMulti is a
separate values block from postgresql:, and the two are mutually
exclusive in a single release.
Without the setup Job (setupJob.enabled: false, the default — you create the monitoring role/grants yourself per "If you'd rather not grant admin access" above, once per instance):
postgresqlMulti:
enabled: true
topology: "self-hosted"
instances:
- name: db1
server: "postgresql-db-1.example.internal"
existingSecret: "db1-monitor-creds"
databases:
- appdb1
- name: db2
server: "postgresql-db-2.example.internal"
existingSecret: "db2-monitor-creds"
databases:
- appdb2
otlpEndpoint: "otlp.nr-data.net:4317"
licenseKey: "<your New Relic license key>"
With the setup Job (setupJob.enabled: true — a top-level field, shared with single-instance mode, not nested under postgresqlMulti; each instance additionally needs its own postgresAdmin.existingSecret):
postgresqlMulti:
enabled: true
topology: "self-hosted"
instances:
- name: db1
server: "postgresql-db-1.example.internal"
existingSecret: "db1-monitor-creds"
databases:
- appdb1
postgresAdmin:
existingSecret: "db1-admin-creds"
- name: db2
se
Deploy postgresql-otel with OpenTenant
Each tenant gets its own release of this chart, with its own namespace, secrets and domain. The builder below already has postgresql-otel on a Hetzner server. Change the host, add apps from the marketplace, then copy the generated files. Providers and prices are samples, and nothing here is sent anywhere.
- Pick a serverConnect Hetzner, OVHcloud or AWS. The builder starts on Hetzner, the cheapest sample rate.
- Place the chartpostgresql-otel is pinned at v0.3.0 in opentenant.yaml. Drag more apps from the marketplace onto a rack.
- ApplySave opentenant.yaml and main.tf from the console, then run the commands below.
# opentenant.yaml, main.tf and dns.tf come from the builder below opentenant validate opentenant.yaml terraform init && terraform apply