Docs » Available host and application monitors » Configure application receivers for databases » PostgreSQL

PostgreSQL ๐Ÿ”—

Description ๐Ÿ”—

The Splunk Distribution of OpenTelemetry Collector deploys this integration as the postgresql monitor via the Smart Agent Receiver.

This monitor pulls metrics from all PostgreSQL databases from a specific Postgres server instance. This monitor pulls basic information that is applicable to any database and gathers these metrics via SQL queries.

Benefits ๐Ÿ”—

After you configure the integration, you can access these features:

  • View metrics. You can create your own custom dashboards, and most monitors provide built-in dashboards as well. For information about dashboards, see View dashboards in Observability Cloud.

  • View a data-driven visualization of the physical servers, virtual machines, AWS instances, and other resources in your environment that are visible to Infrastructure Monitoring. For information about navigators, see Splunk Infrastructure Monitoring navigators.

  • Access the Metric Finder and search for metrics sent by the monitor. For information, see Use the Metric Finder.

Installation ๐Ÿ”—

This monitor is provided by the Smart Agent and is available by using the SignalFx Smart Agent Receiver in the Splunk Distribution of OpenTelemetry Collector.

Follow these steps to deploy this integration:

  1. Deploy the Splunk Distribution of OpenTelemetry Collector to your host or container platform:

  2. Configure the monitor, as described in the Configuration section.

  3. Restart the Splunk Distribution of OpenTelemetry Collector.

To report all available metrics, enable the pg_stat_statements extension in your PostgreSQL deployment. This extension must be specified in the shared_preload_libraries configuration option in the main PostgreSQL configuration at server start up. You must also enable the extension for each database by running CREATE EXTENSION IF NOT EXISTS pg_stat_statements; on each database.

Note that to get consistent and accurate query execution time metrics, you must set the pg_stat_statements.max configuration option to larger than the number of distinct queries on the server.

Here is a sample configuration of Postgres to enable statement tracking.

This configuration was tested with PostgreSQL 9.2+.

If you want to collect additional metrics about PostgreSQL, use the sql monitor.

Configuration ๐Ÿ”—

This monitor type is available in the Smart Agent Receiver, which is part of the Splunk Distribution of OpenTelemetry Collector. You can use existing Smart Agent monitors as OpenTelemetry Collector metric receivers with the Smart Agent Receiver.

This monitor type requires a properly configured environment on your system in which youโ€™ve installed a functional Smart Agent release bundle. The Collector provides this bundle in the installation paths for x86_64/amd64.

To activate this monitor type in the Collector, add the following lines to your configuration (YAML) file:

receivers:
  smartagent/postgresql:
    type: postgresql
    ...  # Additional config

To complete the monitor activation, you must also include the smartagent/postgresql receiver item in a metrics pipeline. To do this, add the receiver item to the service/pipelines/metrics/receivers section of your configuration file. For example:

service:
  pipelines:
    metrics:
      receivers: [smartagent/postgresql]

See configuration examples for specific use cases that show how the Splunk Distribution of OpenTelemetry Collector can integrate and complement existing environments.

Configuration settings ๐Ÿ”—

The following table shows the configuration options for the postgresql monitor:

Option

Required

Type

Description

host

no

string

port

no

integer

(default: 0)

masterDBName

no

string

The โ€œmasterโ€ database to which the agent first connects to query the list of databases available in the server. This database should be accessible to the user specified with connectionString and params below, and that user should have permission to query pg_database. If you want to filter which databases are monitored, use the databases option below. (default: postgres)

connectionString

no

string

See Connection String Parameters.

params

no

map of strings

Parameters to the connection string that can be templated into the connection string with the syntax {{.key}}.

databases

no

list of strings

List of databases to send database-specific metrics about. If omitted, metrics about all databases will be sent. This is an overridable set. (default: [*])

databasePollIntervalSeconds

no

integer

How frequently to poll for new/deleted databases in the DB server. Defaults to the same as intervalSeconds if not set. (default: 0)

logQueries

no

bool

If true, queries will be logged at the info level. (default: false)

topQueryLimit

no

integer

The number of top queries to consider when publishing query-related metrics (default: 10)

The following is an exampleย postgresqlย Smart Agent monitor configuration. This example uses the Vault remote configuration source to connect to PostgreSQL using the params map. This map allows you to pull out the username and password individually from Vault and interpolate them into the connectionString configuration option.

monitors:
 - type: postgresql
   connectionString: 'sslmode=disable user={{.username}} password={{.password}}'
   params: &psqlParams
     username: {"#from": "vault:secret/my-database[username]"}
     password: {"#from": "vault:secret/my-database[password]"}
   discoveryRule: 'container_image =~ "postgres" && port == 5432'

 # This monitor will monitor additional queries from PostgreSQL using the
 # provided SQL queries.
 - type: sql
   dbDriver: postgres
   connectionString: 'sslmode=disable user={{.username}} password={{.password}}'
   # This is a YAML reference to avoid duplicating the above config.
   params: *psqlParams
   queries:
     - query: 'SELECT COUNT(*) as count, country, status FROM customers GROUP BY country, status;'
       metrics:
         - metricName: "customers"
           valueColumn: "count"
           dimensionColumns: ["country", "status"]

Metrics ๐Ÿ”—

The following metrics are available for this integration:

Metrics about replication ๐Ÿ”—

Replication metrics may not be available on some PostgreSQL servers. For now, this monitor automatically disables the replication metrics group if the monitor detects Aurora. This helps avoid following the error: Function pg_last_xlog_receive_location() is currently not supported for Aurora

The metric postgres_replication_state will be reported only for master and for postgres_replication_lag for the standby role (replica).

Get help ๐Ÿ”—

If you are not able to see your data in Splunk Observability Cloud, try these tips:

To learn about even more support options, see Splunk Customer Success.