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

# PostgreSQL server logs with OpenTelemetry

> Collect self-hosted PostgreSQL server logs, slow query output, and connection errors with the OpenTelemetry Collector and forward them to Bronto for troubleshooting.

Collect logs from a self-hosted PostgreSQL server — errors, slow queries, and connection activity — with the OpenTelemetry Collector. The same Collector can also forward traces and metrics from your apps — see [Connect OpenTelemetry Collector to Bronto](/agent-setup/open-telemetry).

## Prerequisites

* A Bronto account and API key ([how to create one](/Account-Management/API-Keys#create-a-new-api-key))
* PostgreSQL writing logs to disk. The default `log_directory` lives under the data directory; Debian/Ubuntu packages use `/var/log/postgresql/`
* An [OpenTelemetry Collector](https://opentelemetry.io/docs/collector/installation/) (recommended) or [Fluent Bit](https://docs.fluentbit.io/manual/installation/getting-started-with-fluent-bit) installed on the same host

To capture useful detail, set these in `postgresql.conf` and reload:

```ini postgresql.conf theme={"dark"}
logging_collector = on
log_min_duration_statement = 1000   # log statements slower than 1s
log_connections = on
log_disconnections = on
```

## Configure the Collector

PostgreSQL entries can span multiple lines (statements, context). Use `multiline` keyed on the leading timestamp:

```yaml /etc/otel/config.yaml theme={"dark"}
receivers:
  filelog/postgresql:
    include:
      - /var/log/postgresql/*.log
    multiline:
      line_start_pattern: '^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}'
    resource:
      service.name: postgresql
      service.namespace: <YOUR_COLLECTION_NAME>

processors:
  batch:

exporters:
  otlphttp/brontologs:
    logs_endpoint: "https://ingestion.<REGION>.bronto.io/v1/logs"
    compression: gzip
    headers:
      x-bronto-api-key: <YOUR_API_KEY>

service:
  pipelines:
    logs:
      receivers: [filelog/postgresql]
      processors: [batch]
      exporters: [otlphttp/brontologs]
```

Set `<REGION>` to `eu` or `us`.

## What you will see in Bronto

Open [Search](https://app.bronto.io/search) and filter by `service.name = postgresql`. Entries include slow-query lines (with duration and statement text), connection and disconnection events, errors, and warnings — each prefixed with a timestamp, process ID, and severity. Bronto's [Custom Parser](/core-features/custom-parser) extracts these fields server-side.

## Troubleshooting

* **Where are the logs?** Run `SHOW log_directory;` and `SHOW log_filename;` in `psql`, or read `$PGDATA/current_logfiles`. Adjust the `include` path to match.
* **Want structured fields at the source?** On PostgreSQL 15+, set `log_destination = 'jsonlog'` for JSON log files (`*.json`) and point `include` at them for direct field extraction.
* For general issues, see [OTel Collector troubleshooting](https://opentelemetry.io/docs/collector/troubleshooting/).

## Alternative: Fluent Bit

If you already run Fluent Bit, tail the PostgreSQL log files and forward them over HTTP:

```ini fluent-bit.conf theme={"dark"}
[INPUT]
    name  tail
    path  /var/log/postgresql/*.log
    tag   postgresql

[OUTPUT]
    name        http
    match       postgresql
    host        ingestion.<REGION>.bronto.io
    port        443
    tls         on
    format      json_lines
    compress    gzip
    header      x-bronto-api-key    <YOUR_API_KEY>
    header      x-bronto-dataset    postgresql
    header      x-bronto-collection <YOUR_COLLECTION_NAME>
```

Set **Format** to `json_lines`, not `json`. For statements that span lines, add a `multiline.parser` keyed on the leading timestamp. See [Connect Fluent Bit to Bronto](/agent-setup/fluent-bit).
