A slow query holds locks, connections pile up and the application service ends in timeouts. OneAgent sees the SQL call from the application side, but not what happens inside the engine. A Dynatrace database extension fills that gap: it queries PostgreSQL or Oracle remotely and reports activity, waits and the most expensive statements.
For an SRE, that is the difference between « the database is slow » and « session 4127 has held a lock for nine minutes ». Diagnosis moves from hunch to evidence, and MTTR follows.
The goal of this tutorial: prepare a PostgreSQL monitoring user, install the extension from the Hub, create a monitoring configuration run by an ActiveGate group, then check the metrics. The approach applies to Dynatrace SaaS and Dynatrace Managed (Extensions 2.0, version 1.255 or later according to the PostgreSQL extension documentation); Oracle is covered at the end.
How a Dynatrace database extension works
Database extensions in the Extensions 2.0 framework are remote extensions: nothing is installed on the database server. An ActiveGate connects to the engine with a dedicated account, runs monitoring queries at a fixed interval and sends the results as metrics and logs.
- ActiveGate group: the configuration targets a group, and a single ActiveGate in the group runs it. Every member must reach the database.
- Endpoint: host, port, database and credentials. One configuration can carry many endpoints.
- Feature sets: groups of metrics you switch on or off. Fewer feature sets mean fewer queries on the database and lower consumption.
Prerequisites
- An ActiveGate with the extensions module enabled, placed in a group (for example
db-paris), that reaches the database port (5432 by default for PostgreSQL). - Administrator access to the database to create the monitoring account.
- Permission to install extensions and create configurations in the Dynatrace environment.
- For PostgreSQL: the additional supplied modules (contrib) installed if the database is self-hosted.
Step 1: create the PostgreSQL monitoring user
Create a dedicated account, never a shared application account. The built-in pg_monitor role grants read access to the statistics views without write access to data.
CREATE USER dynatrace WITH PASSWORD '<password>' INHERIT;
GRANT pg_monitor TO dynatrace;
Then enable pg_stat_statements, required for per-query statistics. On a self-hosted server, in postgresql.conf:
shared_preload_libraries = 'pg_stat_statements'
This setting requires a restart: schedule it in a maintenance window. On AWS RDS, Azure Database for PostgreSQL or Cloud SQL, change the parameter group, server parameter or matching flag.
In each database you want to monitor, create the extension’s working schema:
CREATE EXTENSION IF NOT EXISTS pg_stat_statements;
CREATE SCHEMA IF NOT EXISTS dynatrace;
GRANT USAGE ON SCHEMA dynatrace TO dynatrace;
The documentation also provides a helper function that produces execution plans for expensive queries. It is optional but valuable; copy it as is from the extension page, without changes.
Step 2: install the extension from the Hub
Open your environment’s Hub, search for the PostgreSQL extension published by Dynatrace and install it. On SaaS, the Databases app offers an add-instance wizard that generates SQL scripts suited to the hosting type; on Managed, go through the extensions screen. Both paths lead to the same object: a monitoring configuration.
Step 3: create the monitoring configuration
In the extension, add a configuration. Pick the ActiveGate group, then declare the endpoint: host, port, main database name (usually postgres) and credentials. Prefer the credential vault over typing them in: password rotation then happens in one place.
To automate, the same configuration can be pushed through the API. The scope fragment that targets the ActiveGate group looks like this:
"scope": "ag_group-db-paris"
Next, set the intervals. The default query interval is one minute; the long interval, which collects the most expensive queries, is five minutes. Shortening it increases database monitoring consumption: only do so temporarily, during an investigation.
Finally, add metadata (team, cost centre, security context): it will drive alert routing and access rights.
How to check it works
In the extension screen, the configuration should reach the OK status within minutes. An error status shows the connection message: password rejected, port filtered or pg_stat_statements missing.
On SaaS, open a notebook and run:
timeseries active = avg(postgres.activity.active),
idle_tx = avg(postgres.activity.idle_in_transaction)
A rising idle_in_transaction curve is often the first sign of a transaction left open by the application. On Managed, chart the same metric keys in the data explorer. Next, our DQL query examples for operations show how to cross these metrics with logs.
On the ActiveGate, if nothing arrives, check that the host actually reaches the database:
nc -zv db-orders.internal 5432
What about Oracle?
The approach is the same: Oracle Database extension installed from the Hub, a dedicated monitoring account, and a configuration run by an ActiveGate group that reaches the listener (1521 by default). Only the privileges differ: the account must read the dictionary’s dynamic performance views. The exact privilege list depends on the extension version and architecture (CDB or not): take it from the Oracle extension page in the documentation rather than granting a broad role such as SELECT ANY DICTIONARY for convenience.
Good practices
- At least two ActiveGates per group: if one fails, the other picks up the configuration.
- Place the group close to the databases (same network, same region); see Environment ActiveGate or Cluster ActiveGate.
- Only enable the feature sets you need: every monitoring query runs on a production database.
- Alert on symptoms (saturated connections, deadlocks), not on every metric; our guide to reducing Davis alert noise explains the method.
- Rotate the account password through the credential vault, never inside the configuration itself.
Frequently asked questions
Does the extension replace OneAgent for databases?
No. OneAgent sees SQL calls from the application, with the distributed trace. The extension sees the engine from the inside: sessions, waits, locks, plans. The two views complement each other during an investigation.
What is the difference between SaaS and Managed?
The Extensions 2.0 engine and execution by ActiveGate are shared. On SaaS, the Databases app adds a wizard and dedicated views, and metrics are queried in DQL on Grail. On Managed, configuration goes through the extensions screen and metrics are charted in the data explorer.
Why does the configuration stay in error when the password is right?
Check in order: the network from every ActiveGate in the group (not only from your laptop), the pg_hba.conf rule that must allow the ActiveGate address, then whether pg_stat_statements is in shared_preload_libraries.
Conclusion
A pg_monitor account, an extension installed from the Hub and an ActiveGate group are enough to lift the bonnet on PostgreSQL. Start with one critical database, keep default intervals, watch for a week, then widen. The reference page is on docs.dynatrace.com.
span.observer is an independent community blog, not affiliated with Dynatrace LLC. Dynatrace is a trademark of its owner. Screen names and procedures change: always check the official documentation before a production change.
Originally published on span.observer. French version: https://span.observer/fr/extension-dynatrace-base-de-donnees-postgresql/.
Top comments (0)