ObserveNow
...
Integrations
Infrastructure

PostgreSQL

OpsVerse's Kubernetes agent can be used to collect metrics from PostgreSQL databases.

In order to collect metrics from PostgreSQL, you must first enable the pg_stat_statements extension which generates PostgreSQL metrics.

Verify pg_stat_statements is installed

Run the following command in your database to check if pg_stat_statements is enabled

Pgsql


If you do not see an entry for pg_stat_statements, you can install it using the next step. Otherwise, skip to the Enable on your database section

Install pg_stat_statements

Add the following snippet into your postgresql.conf file:

Text


Restart your PostgreSQL server and verify you have pg_stat_statements enabled

instances running PostgreSQL 11+ and should have pg_stat_statements enabled by default. But if not, you can follow their respective documentation on enabling pg_stat_statements in your PostgreSQL server.

Enable pg_stat_statements on your database

Connect to the PostgreSQL database you want to collect metrics from and install pg_stat_statements using the following commands:

Pgsql


Configure OpsVerse Agent to Collect Metrics from PostgreSQL

Add the following YAML snippets to the agent's values.yaml and run the agent based on these instructions.

First enable the postgres exporter by adding the following YAML snippet in the agent values.

YAML


Once the postgres exporter in configured, add the extraScrapeConfigs under victoria-metrics-agent (must be already present in the agent values) as below.

YAML


Reinstall the helm chart with the updated values.yaml file and you should see the postgres-exporter pod come up and postgres metrics should have started flowing into your ObserveNow instance

You may need to use sslmode: require in the config above with Amazon RDS PostgreSQL instances since Amazon RDS forces SSL connections since PostgreSQL 15+

Alternatively, you can disable the force ssl behaviour on Amazon RDS by following these instructions (Requires a server restart).

Single Machine

Alternatively, you can install the Prometheus Postgres exporter on a single machine.

Prerequisite(s):

Run this command to install the Postgres exporter as a systemd unit:

Shell

  • First you need to update Postgres user and password info, after you install, you may edit /etc/opsverse/exporters/postgres/postgres_exporter.env and then restart the service:
  • The agent will begin scraping the metrics automatically; the script will drop the scrape target into /etc/opsverse/targets/, so the agent will begin automatically scraping