> For the complete documentation index, see [llms.txt](https://docs.bindplane.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.bindplane.com/integrations/sources/postgresql.md).

# PostgreSQL

The PostgreSQL source collects metrics and logs from a PostgreSQL server. Metrics are scraped from PostgreSQL's statistics views over a TCP or Unix connection using a monitoring user. Logs are read from the PostgreSQL log file(s) on disk and optionally parsed into structured fields. Choose Logs, Metrics, or both.

### Supported Telemetry

| Platform | Metrics | Logs | Traces |
| -------- | ------- | ---- | ------ |
| Linux    | ✓       | ✓    |        |
| Windows  | ✓       | ✓    |        |
| macOS    | ✓       | ✓    |        |

### Prerequisites

**For metrics:**

* A reachable PostgreSQL endpoint (host and port, default `localhost:5432`), or a Unix socket if `transport` is set to `unix`. The collector host must have network access to the PostgreSQL port.
* A monitoring user with read-only access to PostgreSQL's statistics views. On PostgreSQL 10 and later, grant the built-in `pg_monitor` role to a dedicated, least-privilege user rather than using a superuser account. The `pg_monitor` role bundles read access to the `pg_stat_*` views and configuration settings the receiver queries. See [Predefined Roles](https://www.postgresql.org/docs/current/predefined-roles.html) in the PostgreSQL documentation.
* TLS material (CA certificate, and a client certificate and key for mutual TLS) if you enable TLS for the metrics connection.

**For logs:**

* PostgreSQL configured to write its logs to disk, and the path(s) to the log file(s). Defaults cover common Debian/Ubuntu, SLES, and CentOS/RHEL locations.
* The collector must have read access to the log file(s).

### Configuration

<figure><img src="/files/aQBOT8wxYKV1qOjXa0Nh" alt="Bindplane docs - PostgreSQL - image 1"><figcaption></figcaption></figure>

**General**

| Parameter             | Type               | Required | Default               | Description                                                          |
| --------------------- | ------------------ | -------- | --------------------- | -------------------------------------------------------------------- |
| Choose Telemetry Type | Telemetry Selector | No       | `["Logs", "Metrics"]` | Which signals this source collects. Valid values: `Logs`, `Metrics`. |

**Metrics**

| Parameter | Type                | Required | Default          | Description                                                                                                                            |
| --------- | ------------------- | -------- | ---------------- | -------------------------------------------------------------------------------------------------------------------------------------- |
| Endpoint  | String              | No       | `localhost:5432` | Endpoint of the PostgreSQL server. If Transport is set to `unix`, the endpoint is translated from `host:port` to `/host.s.PGSQL.port`. |
| Transport | Enum: `tcp`, `unix` | No       | `tcp`            | The transport protocol used to connect to PostgreSQL.                                                                                  |
| Username  | String              | Yes      | *(empty)*        | Username used to authenticate.                                                                                                         |
| Password  | String              | Yes      | *(empty)*        | Password used to authenticate. Stored as a sensitive value.                                                                            |

**Logs**

| Parameter | Type                     | Required | Default   | Description                                                                                                                                                                                                             |
| --------- | ------------------------ | -------- | --------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Log Paths | Strings                  | No       | See below | Path to PostgreSQL log file(s). Defaults: `/var/log/postgresql/postgresql*.log` (Debian/Ubuntu), `/var/lib/pgsql/data/log/postgresql*.log` (SLES), `/var/lib/pgsql/*/data/log/postgresql*.log` (CentOS/RHEL). Advanced. |
| Start At  | Enum: `beginning`, `end` | No       | `end`     | Start reading logs from `beginning` or `end`. Advanced.                                                                                                                                                                 |
| Parse     | Boolean                  | No       | `true`    | Parses the log fields into structured data. Advanced.                                                                                                                                                                   |

**Advanced**

| Parameter                         | Type    | Required | Default   | Description                                                                                                                          |
| --------------------------------- | ------- | -------- | --------- | ------------------------------------------------------------------------------------------------------------------------------------ |
| Databases                         | Strings | No       | *(empty)* | The list of databases for which the receiver collects statistics. An empty list collects statistics for all databases. Metrics only. |
| Collection Interval               | Integer | No       | `60`      | How often (in seconds) to scrape for metrics. Metrics only.                                                                          |
| Enable TLS                        | Boolean | No       | `false`   | Whether to use TLS for the metrics connection. Metrics only.                                                                         |
| TLS Certificate Authority File    | String  | No       | *(empty)* | Certificate authority used to validate TLS certificates. Relevant when Enable TLS is `true`.                                         |
| TLS Client Certificate File       | String  | No       | *(empty)* | A TLS certificate used for client authentication, if mutual TLS is enabled. Relevant when Enable TLS is `true`.                      |
| TLS Client Private Key File       | String  | No       | *(empty)* | A TLS private key used for client authentication, if mutual TLS is enabled. Relevant when Enable TLS is `true`.                      |
| Skip TLS Certificate Verification | Boolean | No       | `false`   | Skip TLS certificate verification. Relevant when Enable TLS is `true`.                                                               |
| Metrics                           | Metrics | No       | *(empty)* | Toggle individual metrics on or off. Metrics only.                                                                                   |

### Examples

#### Collect metrics and logs from a local PostgreSQL server

This source scrapes metrics from PostgreSQL on `localhost:5432` using a monitoring user and tails the default Debian/Ubuntu log path.

```yaml
apiVersion: bindplane.observiq.com/v1
kind: Source
metadata:
  name: postgresql
spec:
  type: postgresql
  parameters:
    - name: telemetry_types
      value: ["Logs", "Metrics"]
    - name: endpoint
      value: localhost:5432
    - name: transport
      value: tcp
    - name: username
      value: otel_monitor
    - name: password
      value: "(redacted)"
    - name: postgresql_log_path
      value:
        - /var/log/postgresql/postgresql*.log
```

#### Scrape a single database over TLS

This source collects metrics for only the `app` database over a TLS connection.

```yaml
apiVersion: bindplane.observiq.com/v1
kind: Source
metadata:
  name: postgresql-tls
spec:
  type: postgresql
  parameters:
    - name: telemetry_types
      value: ["Metrics"]
    - name: endpoint
      value: db.internal:5432
    - name: username
      value: otel_monitor
    - name: password
      value: "(redacted)"
    - name: databases
      value:
        - app
    - name: enable_tls
      value: true
    - name: ca_file
      value: /etc/otel/certs/ca.crt
```

### Configuration Tips

* Grant the dedicated monitoring user the `pg_monitor` role instead of using a superuser. It provides exactly the read access the receiver needs to the `pg_stat_*` views.
* Leave Databases empty to collect statistics for all databases, or list specific database names to narrow the scope.
* Logs and metrics use independent connection paths: metrics connect to the PostgreSQL endpoint, while logs are read directly from the log file(s) on the collector host. Enabling one does not require the other.

### Troubleshooting

#### Connection refused on metrics

Symptoms: the metrics receiver cannot reach the PostgreSQL server.

Solutions:

1. Confirm the Endpoint host and port are correct and that PostgreSQL is listening (check `listen_addresses` in `postgresql.conf`).
2. Verify the collector host can reach the port through any firewall or security group, and that `pg_hba.conf` allows the connecting host.

#### Authentication failed

Symptoms: the receiver connects but cannot authenticate or read statistics.

Solutions:

1. Verify the Username and Password are correct for the monitoring user.
2. Confirm the user has been granted the `pg_monitor` role (or the equivalent SELECT grants on the `pg_stat_*` views on PostgreSQL versions earlier than 10).

#### No logs are collected

Symptoms: the source is running but no log records arrive.

Solutions:

1. Confirm PostgreSQL is writing logs to disk and that the Log Paths match the actual file location.
2. Verify the collector process has read permission on the log file(s) and parent directories.

### Standalone Source

```yaml
apiVersion: bindplane.observiq.com/v1
kind: Source
metadata:
  name: postgresql
spec:
  type: postgresql
  parameters:
    - name: telemetry_types
      value: ["Logs", "Metrics"]
    - name: endpoint
      value: localhost:5432
    - name: transport
      value: tcp
    - name: username
      value: otel_monitor
    - name: password
      value: "(redacted)"
    - name: databases
      value: []
    - name: collection_interval
      value: 60
    - name: enable_tls
      value: false
    - name: postgresql_log_path
      value:
        - /var/log/postgresql/postgresql*.log
        - /var/lib/pgsql/data/log/postgresql*.log
        - /var/lib/pgsql/*/data/log/postgresql*.log
    - name: start_at
      value: end
    - name: parse
      value: true
```

### Related Resources

* [PostgreSQL Predefined Roles (`pg_monitor`)](https://www.postgresql.org/docs/current/predefined-roles.html)
* [OpenTelemetry `postgresqlreceiver`](https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/receiver/postgresqlreceiver/README.md)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.bindplane.com/integrations/sources/postgresql.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
