> ## Documentation Index
> Fetch the complete documentation index at: https://mw-docs.middleware.io/llms.txt
> Use this file to discover all available pages before exploring further.

# PostgreSQL

> PostgreSQL Integration - Setup & Installation Docs | Middleware

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](https://docs.middleware.io/agent-installation/overview).

# Setup

### Step 1: Create Database Credentials

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

`/home/ubuntu/postgres_creds.yaml`

```yaml .yaml theme={null}
postgresql:
  endpoint: localhost:5423
  username: postgres
  password: postgres
```

### Step 2: Access Integrations

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

<img src="https://mintcdn.com/middlewareio/cgLzouXcJUXtP_sv/images/integration/pgdb-store.png?fit=max&auto=format&n=cgLzouXcJUXtP_sv&q=85&s=c14274a7fddd4a23d68ed18fd92460b9" width="1542" height="682" data-path="images/integration/pgdb-store.png" />

### Step 3: 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.

<img src="https://mintcdn.com/middlewareio/cgLzouXcJUXtP_sv/images/integration/postgres-dashboard.png?fit=max&auto=format&n=cgLzouXcJUXtP_sv&q=85&s=d7ccdc21ee8dd2fa67619f002cd1c95a" width="1786" height="795" data-path="images/integration/postgres-dashboard.png" />

### 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.

<img src="https://mintcdn.com/middlewareio/cgLzouXcJUXtP_sv/images/integration/postgres-custom-graphs.png?fit=max&auto=format&n=cgLzouXcJUXtP_sv&q=85&s=2814a40eac2d692d5d6d454a7bc7cffd" width="1814" height="943" data-path="images/integration/postgres-custom-graphs.png" />

# 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.

<img src="https://mintcdn.com/middlewareio/cgLzouXcJUXtP_sv/images/integration/postgresql-alerts.png?fit=max&auto=format&n=cgLzouXcJUXtP_sv&q=85&s=766657e2d1240763c05e8b37f1853a29" width="1781" height="908" data-path="images/integration/postgresql-alerts.png" />

# Metrics Collected

| **Metric**                              | **Description**                                                                                       |
| --------------------------------------- | ----------------------------------------------------------------------------------------------------- |
| `postgresql.backends`                   | Number of backends                                                                                    |
| `postgresql.bgwriter.buffers.allocated` | Number of buffers allocated                                                                           |
| `postgresql.bgwriter.buffers.writes`    | Number of buffers written                                                                             |
| `postgresql.bgwriter.checkpoint.count`  | Number of checkpoints performed                                                                       |
| `postgresql.bgwriter.duration`          | Total time spent in checkpoint processing writing and syncing files to disk, in milliseconds          |
| `postgresql.bgwriter.maxwritten`        | Number of times the background writer stopped a cleaning scan because it had written too many buffers |
| `postgresql.blocks_read`                | Number of disk blocks read                                                                            |
| `postgresql.commits`                    | Number of transactions that have been committed                                                       |
| `postgresql.connection.max`             | Configured maximum number of client connections allowed                                               |
| `postgresql.database.count`             | Count of databases in a cluster                                                                       |
| `postgresql.db_size`                    | Database disk size                                                                                    |
| `postgresql.index.scans`                | Number of index scans on a table                                                                      |
| `postgresql.index.size`                 | Size of the index on disk                                                                             |
| `postgresql.operations`                 | Number of db row operations                                                                           |
| `postgresql.rollbacks`                  | Number of rollbacks                                                                                   |
| `postgresql.rows`                       | Number of rows in the database                                                                        |
| `postgresql.table.count`                | Number of user tables in a database                                                                   |
| `postgresql.table.size`                 | Disk space used by a table                                                                            |
| `postgresql.table.vacuum.count`         | Number of times a table has been manually vacuumed                                                    |

# Troubleshooting

<Accordion title="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.
</Accordion>

# Next Steps

* [How to Create Alerts](https://docs.middleware.io/workflow/alerting/setup-alert)
* [Dashboard Basics & Customization](https://docs.middleware.io/workflow/custom-dashboard/dashboard-builder-overview)
* [Custom Telemetry Ingestion](https://docs.middleware.io/open-telemetry/otel-getting-started)
* [Getting Started With Real User Monitoring (RUM)](https://docs.middleware.io/rum/rum-overview)
* [Data Ingestion APIs](https://docs.middleware.io/data-ingestion-apis/opentelemetry-metrics)

<Note> Need assistance or want to learn more about Middleware? Contact us at support\[at]middleware.io. </Note>
