PostgreSQL

The PostgreSQL Integration allows you to ingest and monitor the performance and health metrics of your object-relational database management system (ORDBMS) data. This integration is useful for tracking the total number of blocks read into memory, identifying disk space utilization per table, tallying insert operations, and rollbacks triggered.

Prerequisites

Middleware Host Agent (MW Agent) must be installed on your local machine. To install the MW Agent, see our Installation Guide.

Setup

Step 1: Enable pg_stat_statements

This is needed to collect statistics about postgresql statements.

Login to postgres shell as root user.

First we need to ensure pg_stat_statements is working. This view has the statistics about the statements executed by the postgres engine.

For this we need to modify a config file. You can find that file at: /etc/postgresql/14/main/postgresql.conf.

Add/Uncomment the following lines:

With root user logged in,

Now restart the server,

Lets verify, As a superuser, run the following statements:

If you have configured your database correctly, this will return a result like this

Note: This result may have different data as this is info about queries that you have run.

Step 2 (Optional): Creating a least privileged user.

Lets create a least privileged user.

Check if the user is created by running:

This should give you a table where you can see:

Now we need our user to permission to connect to the db,

Grant permissions to read stats,

Now login with the user we've created,

Note: This result may have different data as this is info about queries that you have run.

Step 3: Create Database Credentials

Create a .yaml file containing database credentials like the below example:

/home/ubuntu/postgres_creds.yaml

Step 4: Access Integrations

Log in to Middleware, navigate to the Installations Page in the bottom left corner, select All Integration and click PostgreSQL

Step 5: Enable Integration

Add a host machine from the dropdown list, input the credential path from Step 1, and Save

Visualize Your Data

Default PostgreSQL Dashboard

Once the PostgreSQL integration setup is complete, a new PostgreSQL-specific dashboard will appear in the Dashboard Builder. This default dashboard serves as a jumping off point for visualizing and analyzing PostgreSQL data.

Create PostgreSQL Widget

PostgreSQL data can be added to dashboards as a custom widget. When adding a new widget, select the postgresql data source to view a full list of available PostgreSQL data.

Alerts

Alerts can be configured for any PostgreSQL metrics. When creating a new rule select the Database detection method and PostgreSQL database type for available metrics to appear in the Metrics dropdown list. Select the desired metric and continue configuring the alert conditions.

Metrics Collected

MetricDescription
postgresql.backendsNumber of backends
postgresql.bgwriter.buffers.allocatedNumber of buffers allocated
postgresql.bgwriter.buffers.writesNumber of buffers written
postgresql.bgwriter.checkpoint.countNumber of checkpoints performed
postgresql.bgwriter.durationTotal time spent in checkpoint processing writing and syncing files to disk, in milliseconds
postgresql.bgwriter.maxwrittenNumber of times the background writer stopped a cleaning scan because it had written too many buffers
postgresql.blocks_readNumber of disk blocks read
postgresql.commitsNumber of transactions that have been committed
postgresql.connection.maxConfigured maximum number of client connections allowed
postgresql.database.countCount of databases in a cluster
postgresql.db_sizeDatabase disk size
postgresql.index.scansNumber of index scans on a table
postgresql.index.sizeSize of the index on disk
postgresql.operationsNumber of db row operations
postgresql.rollbacksNumber of rollbacks
postgresql.rowsNumber of rows in the database
postgresql.table.countNumber of user tables in a database
postgresql.table.sizeDisk space used by a table
postgresql.table.vacuum.countNumber of times a table has been manually vacuumed
postgresql.rows_deletedRows deleted by queries in this db
postgresql.rows_fetchedRows fetched by queries in this db
postgresql.rows_updatedRows updated by queries in this db
postgresql.rows_insertedRows inserted by queries in this db
postgresql.query.total_exec_timeTotal wait time of the normalised timed events in nanaoseconds.
postgresql.query.countNumber of times the statement was executed.
postgresql.live_rowsThe approximate number of live rows, tagged with relation name.
postgresql.operationsThe number of db row operations.
postgresql.buffer_hitThe number of disk block hits in the buffer cache, thereby avoiding database reads, tagged with database name.

Troubleshooting

Missing Integrations Menu

If you do not see the Integrations Menu in Middlware, that means your account has not been granted Installation permissions. Contact your system administrator to add the Installation permission to your user role in Settings.

Next Steps

Need assistance or want to learn more about Middleware? Contact our support team in Slack.