PostgreSQL is an object-relational database management system available for many platforms including Linux, FreeBSD, Solaris, Microsoft Windows, and macOS. For more information visit postgresql.org.
Even if the PostgreSQL plugin is not configured, Stackdriver Monitoring discovers PostgreSQL services running in your Google Cloud Platform project by:
- Searching instance names for postgresql
- Checking for ports opened to 5432 via firewall rules
The services discovered are displayed on the PostgreSQL Services page in the Resources menu. After you install the Monitoring agent and configure the PostgreSQL plugin on your instances, Monitoring populates the PostgreSQL Services page with inventory and metrics.
Configuring Monitoring to monitor PostgreSQL
After you install the Monitoring agent, use the following instructions to configure the PostgreSQL plugin on your instances.
For PostgreSQL collection you must create a user/role with minimal privileges that
can connect to the database using
This user and password are referred to as
STATS_PASS in the following config file.
Some installations set access controls to
ident authentication by default.
You need to edit your
pg_hba.conf file to enable access for the agent role.
Assuming you have named your role
stackdriver-agent, you might need to add one of
these lines to your
pg_hba.conf file and restart PostgreSQL:
For connecting through unix domain sockets:
local all stackdriver-agent md5
For connecting through TCP/IP to localhost:
host all stackdriver-agent 127.0.0.1/32 md5
Enabling the PostgreSQL monitoring plugin
PostgreSQL is configured per database on your system.
At the moment, no drop-in configuration is available.
The following configuration file shows how to configure one database, named
You would need to use that configuration as a template for your databases.
(cd /opt/stackdriver/collectd/etc/collectd.d/ && sudo curl -O https://raw.githubusercontent.com/Stackdriver/stackdriver-agent-service-configs/master/etc/collectd.d/postgresql.conf)
As root, edit the downloaded configuration file and add information about your databases.
Inline comments point out where you need to add configuration for additional databases.
Wherever you see
DATABASE_NAME, substitute the name of your database.
After editing the configuration file, restart the monitoring agent by running the following command:
sudo service stackdriver-agent restart
For more information on the
postgresql plugin, see
What is monitored
The full list of metrics the PostreSQL plugin monitors is at Agent metrics: postgresql.