The New Relic PostgreSQL on-host integration receives and sends inventory metrics from your PostgreSQL instance to the New Relic platform, where you can aggregate and visualize key performance metrics. Data from instances, databases, and clusters helps you find the source of problems.
To install the PostgreSQL monitoring integration, you must run through the following steps:
Our integration is compatible with PostgreSQL v17 and lower.
Supported managed services
Amazon RDS
Azure Flexible
Supported operating systems
Windows
Linux
For a comprehensive list of specific Windows and Linux versions, check the table of compatible operating systems.
System requirements
A New Relic account. Don't have one? Sign up for free! No credit card required.
If PostgreSQL is not running on Kubernetes or Amazon ECS, you can install the infrastructure agent on a Linux or Windows OS host or on a host capable of remotely accessing where PostgreSQL is installed. Otherwise:
Edit the postgresql-config.yml configuration file with your favorite editor. Check out some configuration file examples..
To enable automatic Postgresql parsing and forwarding, copy or rename the postgresql-log.yml.example file to postgresql-log.yml. You don't need to restart the agent but you may need to update the YML file with the location of your postgresql log files, if you aren't using the default locations.
If installed on-host, edit the config in the integration's YAML config file, postgresql-config.yml. An integration's YAML-format configuration is where you can place required login credentials and configure how data is collected. Which options you change depend on your setup and preference. The configuration file has common settings applicable to all integrations, such as interval, timeout, inventory_source. To read all about these common settings, refer to our Configuration Format document.
Specific settings related to PostgreSQL are defined using the env section of the configuration file. These settings control the connection to your PostgreSQL instance as well as other security settings and features. The list of valid settings is described in the next section of this document.
PostgreSQL users and permissions
Create a user with SELECT permissions on:
pg_stat_database
pg_stat_database_conflicts
pg_stat_bgwriter
To create the user for the PostgreSQL integration:
CREATEUSER new_relic WITH PASSWORD MY_PASSWORD;
GRANTSELECTON pg_stat_database TO new_relic;
GRANTSELECTON pg_stat_database_conflicts TO new_relic;
GRANTSELECTON pg_stat_bgwriter TO new_relic;
This will allow the integration to gather global metrics related to the PostgreSQL instance.
If you also want to obtain table and index-related metrics (for example, table size and index size), the PostgreSQL role used by the integration (new_relic) also needs SELECT permissions on the tables from which it will gather metrics from. For example, to allow the integration to collect metrics from all the tables and indexes present in the database (in the public schema), use the following:
GRANTSELECTONALLTABLESINSCHEMApublicTO new_relic;
If you also want to obtain query-level metrics from the PostgreSQL custom query config file, the PostgreSQL role used by the integration (new_relic) needs to be added to the (pg_read_all_stats) role. This is due to the user leveraging the (pg_stat_statements) extension.
GRANT pg_read_all_stats TO new_relic;
Enabling the pg_stat_statements extension may require you to manually create it from a query prompt:
CREATE EXTENSION pg_stat_statements;
postgresql-config.yml sample files
JSON array: Interpreted as a list of database names from which to collect all relevant metrics, including any tables and indexes belonging to that database.
For example:
collection_list:'["postgres"]'
JSON object: only entities specified in the object will be collected, no automatic discovery will be performed. The levels of JSON are database name -> schema name -> table name -> index name.
Azure/AWS SSL Enabled Options: Azure Flexible managed database offerings require SSL to connect. AWS RDS/Aurora may require SSL if your MySQL version is 5.7+ and require_secure_transport is set to ON in your Aurora Parameter Group. To accomodate the SSL requirement, these settings in the postgresql-config.yml need to be set to true.
For example:
ENABLE_SSL:"true"
TRUST_SERVER_CERTIFICATE:"true"
Azure/AWS SSL Disabled Options: In addition to the settings above, the following SSL settings should be commented out or removed from the config. This is due to the config trusting the server certificate above.
Summary: Once these settings are in place, the complete Azure/AWS config file should look like the one below. Note: the infra agent and Postgresql integration should be installed on a host with network access to the database instances.
An additional YAML configuration file with one or more custom SQL can be defined and the integration will need the path to the file in the CUSTOM_METRICS_CONFIG parameter.
The PostgreSQL integration collects the following metrics. Some metric names are prefixed with a category indicator and a period, such as db. or index..
PostgreSQLDatabaseSample attributes
Description
db.connections
Number of backends currently connected to this database.
db.maxconnections
The maximum number of concurrent connections to the database server.
db.commitsPerSecond
Committed transactions per second.
db.rollbacksPerSecond
Transactions rolled back per second.
db.readsPerSecond
Number of disk blocks read in this database per second.
db.bufferHitsPerSecond
Number of times disk blocks were found already in the buffer cache, so that a read was not necessary. This only includes hits in the PostgreSQL buffer cache, not the operating system's file system cache.
db.rowsReturnedPerSecond
Rows returned by queries per second.
db.rowsFetchedPerSecond
Rows fetched by queries per second.
db.rowsInsertedPerSecond
Rows inserted per second.
db.rowsUpdatedPerSecond
Rows updated per second.
db.rowsDeletedPerSecond
Rows deleted per second.
db.conflicts.tablespacePerSecond
Number of queries in this database that have been canceled due to dropped tablespaces.
db.conflicts.locksPerSecond
Number of queries in this database that have been canceled due to lock timeouts.
db.conflicts.snapshotPerSecond
Number of queries in this database that have been canceled due to old snapshots.
db.conflicts.bufferpinPerSecond
Number of queries in this database that have been canceled due to pinned buffers.
db.conflicts.deadlockPerSecond
Number of queries in this database that have been canceled due to deadlocks.
db.tempFilesCreatedPerSecond
Number of temporary files created by queries in this database. All temporary files are counted, regardless of why the temporary file was created (for example, sorting or hashing), and regardless of the log_temp_files setting.
db.tempWrittenInBytesPerSecond
Total amount of data written to temporary files by queries in this database. All temporary files are counted, regardless of why the temporary file was created, and regardless of the log_temp_files setting.
db.deadlocksPerSecond
Number of deadlocks detected in this database.
db.readTimeInMillisecondsPerSecond
Time spent reading data file blocks by backends in this database, in milliseconds.
db.writeTimeInMillisecondsPerSecond
Time spent writing data file blocks by backends in this database, in milliseconds.
PostgreSQLIndexSample attributes
Description
index.sizeInBytes
The size of an index.
index.rowsReadPerSecond
The number of index entries returned by scans on this index.
index.rowsFetchedPerSecond
The number of index entries fetched by scans on this index.
Sugerencia
With PostgreSQL v17, we renamed some metrics to better reflect their source tables. You can see the updated names indented below their earlier versions.
The average number of queries per second in last stat period.
pgbouncer.stats.avgBytesIn
The client network traffic received.
pgbouncer.stats.avgBytesOut
The client network traffic sent.
pgbouncer.stats.avgQueryDurationInMilliseconds
The average query duration.
pgbouncer.pools.clientConnectionsActive
Client connections linked to server connection and able to process queries.
pgbouncer.pools.clientConnectionsWaiting
Client connections waiting on a server connection.
pgbouncer.pools.clientConnectionsWaitingCancelReq
Client connections that have not forwarded query cancellations to the server yet.
pgbouncer.pools.clientConnectionsActiveCancelReq
Client connections that have forwarded query cancellations to the server and are waiting for the server response.
pgbouncer.pools.serverConnectionsActiveCancel
Server connections that are currently forwarding a cancel request.
pgbouncer.pools.serverConnectionsBeingCancel
Servers that normally could become idle but are waiting to do so until all in-flight cancel requests have completed that were sent to cancel a query on this server.
pgbouncer.pools.serverConnectionsActive
Server connections linked to a client connection.
pgbouncer.pools.serverConnectionsIdle
Server connections idle and ready for a client query.
pgbouncer.pools.serverConnectionsUsed
Server connections idle more than server_check_delay, needing server_check_query.
pgbouncer.pools.serverConnectionsTested
Server connections currently running either server_reset_query or server_check_query.
pgbouncer.pools.serverConnectionsLogin
Server connections currently in the process of logging in.