---
title: "Send Logs to Managed OpenSearch"
description: "Ship the Managed PostgreSQL server log and pgaudit records to an Exoscale Managed OpenSearch service with a logs integration, then search them."
url: https://community.exoscale.com/product/dbaas/service-specific/postgresql/how-to/send-logs-to-opensearch/
product: "PostgreSQL"
section: product
last_updated: 2026-11-10
---
> For AI agents: the documentation index is at https://community.exoscale.com/llms.txt. Every page is available as markdown at `<page URL>index.md` or with `Accept: text/markdown`.

# Send Logs to Managed OpenSearch

Send the server log of a Managed PostgreSQL service to an Exoscale Managed OpenSearch service, and keep it searchable for as many days as you choose. `exo dbaas logs` only reads a short buffer and never shows [pgaudit](https://community.exoscale.com/product/dbaas/service-specific/postgresql/how-to/collect-pgaudit-logs/index.md) records; a logs integration keeps both.

This page covers an OpenSearch service of your own organization. For an OpenSearch or
Elasticsearch cluster that you run elsewhere, use an external endpoint instead, as described in
[Use External Integrations](https://community.exoscale.com/product/dbaas/how-to/external-integrations/index.md).

## Prerequisites

- The [Exoscale CLI](https://community.exoscale.com/reference/cli/exo/index.md), configured with your API credentials.
- A running Managed PostgreSQL service.
- A running [Managed OpenSearch](https://community.exoscale.com/product/dbaas/service-specific/opensearch/index.md) service in the same
  organization.

The IP filter of the OpenSearch service does not need to list the PostgreSQL service: the
integration delivers logs to an OpenSearch service whose filter allows only your own address.

## Create the Integration

```bash
echo '{"integration-type":"logs","source-service":"SERVICE_NAME","dest-service":"OPENSEARCH_SERVICE","settings":{"elasticsearch_index_prefix":"INDEX_PREFIX","elasticsearch_index_days_max":DAYS}}' | \
  exo api create-dbaas-integration -z ZONE
```

Parameters:

- `SERVICE_NAME`: name of the Managed PostgreSQL service.
- `OPENSEARCH_SERVICE`: name of the Managed OpenSearch service that receives the logs.
- `INDEX_PREFIX`: prefix of the daily indices. Lowercase letters, digits, `-`, `_` and `.`,
  starting with a letter or a digit. Defaults to `logs`.
- `DAYS`: number of daily indices to keep, from 1 to 10000. Defaults to `3`.
- `ZONE`: zone of the PostgreSQL service.

For example, to keep 14 days of logs of `my-postgresql` in `my-opensearch`:

```bash
echo '{"integration-type":"logs","source-service":"my-postgresql","dest-service":"my-opensearch","settings":{"elasticsearch_index_prefix":"my-postgresql","elasticsearch_index_days_max":14}}' | \
  exo api create-dbaas-integration -z ch-gva-2
```

The command returns the ID of the integration in `reference.id`. Keep it: you need it to delete the
integration. It is also listed in the `integrations` field of the service:

```bash
exo api get-dbaas-service-pg my-postgresql -z ch-gva-2 -q integrations
```

A third setting, `selected_log_fields`, limits the fields sent with each line. `MESSAGE` and
`timestamp` are always sent. Without the setting, the five other fields are sent too; with it, only
those you list among `HOSTNAME`, `PRIORITY`, `REALTIME_TIMESTAMP`, `SYSTEMD_UNIT` and
`service_name`. For example, `"selected_log_fields":["HOSTNAME","SYSTEMD_UNIT"]` inside `settings`.

> [!TIP]
> Give each service its own index prefix, for example its name. With the default `logs`, every
> service that sends logs to the same OpenSearch service writes into the same daily index.

> [!IMPORTANT]
> Choose the settings when you create the integration. `exo api update-dbaas-integration` answers
> `Integration does not exist.` (HTTP 404), and a second logs integration between the same two
> services is refused with `Such integration already exists.` To change a setting, delete the
> integration and create it again. The new integration starts by sending every line the service
> still holds, so its first index repeats lines that the previous one already sent.

## Check That Logs Arrive

The status reported by `exo api get-dbaas-integration INTEGRATION_ID -z ZONE` stays at `starting`
while logs flow, so check OpenSearch itself. New lines are searchable within seconds.

List the indices of the service:

```bash
curl -s "OPENSEARCH_URI/_cat/indices/INDEX_PREFIX-*?v"
```

Parameters:

- `OPENSEARCH_URI`: the URI returned by `exo dbaas show OPENSEARCH_SERVICE -z ZONE --uri`. It
  contains the `avnadmin` credentials of the OpenSearch service.
- `INDEX_PREFIX`: the prefix set on the integration.

The integration writes one index per day, named `INDEX_PREFIX-YYYY-MM-DD`:

```text
health status index                    uuid                   pri rep docs.count docs.deleted store.size pri.store.size
green  open   my-postgresql-2026-11-10 Lu2Jxm_UTnGxAbGSqjiifA   1   0        998            0      206kb          206kb
```

## What a Log Document Contains

Each line of the PostgreSQL server log becomes one document:

| Field | Content |
| --- | --- |
| `MESSAGE` | The log line, starting with the `log_line_prefix` of the service. Always sent. |
| `timestamp` | Time of the line in UTC, for example `2026-11-10T13:54:44.596031`. Always sent. The only date field of the index. |
| `HOSTNAME` | Node that wrote the line, for example `my-postgresql-1`. |
| `PRIORITY` | Syslog priority: `6` for `LOG` lines, `4` for `ERROR` and `DETAIL` lines, `3` for `FATAL` lines. |
| `REALTIME_TIMESTAMP` | The same instant in Unix seconds. |
| `SYSTEMD_UNIT` | `postgresql-18.service` on PostgreSQL 18. |
| `service_name` | Name of the PostgreSQL service. |

[pgaudit](https://community.exoscale.com/product/dbaas/service-specific/postgresql/how-to/collect-pgaudit-logs/index.md#read-the-audit-records)
records arrive in the same indices with additional `PG_*` fields (user, database, client address,
application) and a `MESSAGE` that starts with `AUDIT:`.

Three properties of these indices shape how you query them:

- **Only the PostgreSQL server log is sent.** Every document comes from the `postgresql-18.service`
  unit, also when a connection pool is in use: PgBouncer lines are not sent.
- **The fields are full text.** You can search them, but not group by them: a terms aggregation on
  `SYSTEMD_UNIT` fails with `Text fields are not optimised for operations that require per-document
  field data like aggregations and sorting`.
- **The platform's own connections are logged.** `log_connections` and `log_disconnections` are on,
  and the monitoring user `_avnadmin_monitor` connects every few seconds, which accounts for a large
  share of the lines on a quiet service. Exclude them with `NOT MESSAGE:"user=_avnadmin_monitor"`.

## Search the Logs

Find the most recent errors, without the platform's monitoring connections:

```bash
curl -s "OPENSEARCH_URI/INDEX_PREFIX-*/_search?pretty" \
  -H 'Content-Type: application/json' \
  -d '{
    "size": 20,
    "sort": [{"timestamp": "desc"}],
    "_source": ["timestamp", "MESSAGE"],
    "query": {"query_string": {"query": "MESSAGE:ERROR AND NOT MESSAGE:\"user=_avnadmin_monitor\""}}
  }'
```

The match is full text and ignores case, so `MESSAGE:ERROR` also returns lines that contain the word
anywhere, such as `LOG:  SSL error: unexpected eof while reading`.

To chart and browse the same indices, add them to Grafana as shown in
[Visualize a service in Managed Grafana](https://community.exoscale.com/product/dbaas/service-specific/postgresql/how-to/visualize-in-grafana/index.md#add-the-logs-from-opensearch).

## Where the Logs Are Stored

The logs are stored in the zone of the OpenSearch service. Keep both services in the same zone when
the logs must stay in one country.

## Delete the Integration

```bash
exo api delete-dbaas-integration INTEGRATION_ID -z ZONE
```

Parameters:

- `INTEGRATION_ID`: the ID returned when the integration was created, also listed in the
  `integrations` field of the service.
- `ZONE`: zone of the PostgreSQL service.

The indices already written stay in OpenSearch. Deleting the OpenSearch service also deletes the
integration.

## Related Pages

- [Collect pgaudit logs](https://community.exoscale.com/product/dbaas/service-specific/postgresql/how-to/collect-pgaudit-logs/index.md)
- [Monitor a Managed PostgreSQL service](https://community.exoscale.com/product/dbaas/service-specific/postgresql/how-to/monitor-your-service/index.md)
- [Send metrics to Managed Thanos](https://community.exoscale.com/product/dbaas/service-specific/postgresql/how-to/send-metrics-to-thanos/index.md)
- [Visualize a service in Managed Grafana](https://community.exoscale.com/product/dbaas/service-specific/postgresql/how-to/visualize-in-grafana/index.md)
- [Log formats and log retrieval](https://community.exoscale.com/product/dbaas/service-specific/postgresql/reference/log-formats/index.md)
- [Managed OpenSearch](https://community.exoscale.com/product/dbaas/service-specific/opensearch/index.md)

