---
title: "Log Formats and Log Retrieval"
description: "The log line prefixes Managed PostgreSQL accepts, sample lines for each, the settings that control what is logged, and how to read the log."
url: https://community.exoscale.com/product/dbaas/service-specific/postgresql/reference/log-formats/
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`.

# Log Formats and Log Retrieval

This page lists the log line formats Managed PostgreSQL accepts, shows what each one looks like, and describes how to read the server log.

## Log Line Formats

`log_line_prefix` is not free-form: the API accepts four values and rejects any other string with
`log_line_prefix must be one of the following`. A new service uses the first one.

| Value | Fields it emits |
| --- | --- |
| `'pid=%p,user=%u,db=%d,app=%a,client=%h '` | process ID, user, database, application, client host |
| `'pid=%p,user=%u,db=%d,app=%a,client=%h,txid=%x,qid=%Q '` | the same, plus transaction ID and query ID |
| `'%t [%p]: [%l-1] user=%u,db=%d,app=%a,client=%h '` | timestamp, process ID, line number in the session, user, database, application, client host |
| `'%m [%p] %q[user=%u,db=%d,app=%a] '` | timestamp with milliseconds, process ID, then user, database and application for client sessions only |

The escapes are those of PostgreSQL's
[`log_line_prefix`](https://www.postgresql.org/docs/current/runtime-config-logging.html#GUC-LOG-LINE-PREFIX) ↗.
Timestamps are in `GMT`.

### Sample Lines

Every message returned by `exo dbaas logs` starts with a sequence number in brackets, for example
`[29-1]`, added before the prefix. The same failed statement, logged with each format:

`'pid=%p,user=%u,db=%d,app=%a,client=%h '`

```text
[29-1] pid=7230,user=avnadmin,db=defaultdb,app=psql,client=203.0.113.10 ERROR:  division by zero
[29-2] pid=7230,user=avnadmin,db=defaultdb,app=psql,client=203.0.113.10 STATEMENT:  begin; insert into accounts values (1000,'fmt'); select 1/0;
```

`'pid=%p,user=%u,db=%d,app=%a,client=%h,txid=%x,qid=%Q '`

```text
[33-1] pid=7268,user=avnadmin,db=defaultdb,app=psql,client=203.0.113.10,txid=1426,qid=-8066023609998936931 ERROR:  division by zero
[33-2] pid=7268,user=avnadmin,db=defaultdb,app=psql,client=203.0.113.10,txid=1426,qid=-8066023609998936931 STATEMENT:  begin; insert into accounts values (2000,'fmt'); select 1/0;
```

`'%t [%p]: [%l-1] user=%u,db=%d,app=%a,client=%h '`

```text
[37-1] 2026-11-10 14:12:42 GMT [7294]: [4-1] user=avnadmin,db=defaultdb,app=psql,client=203.0.113.10 ERROR:  division by zero
[37-2] 2026-11-10 14:12:42 GMT [7294]: [5-1] user=avnadmin,db=defaultdb,app=psql,client=203.0.113.10 STATEMENT:  begin; insert into accounts values (3000,'fmt'); select 1/0;
```

`'%m [%p] %q[user=%u,db=%d,app=%a] '`

```text
[41-1] 2026-11-10 14:12:47.961 GMT [7327] [user=avnadmin,db=defaultdb,app=psql] ERROR:  division by zero
[41-2] 2026-11-10 14:12:47.961 GMT [7327] [user=avnadmin,db=defaultdb,app=psql] STATEMENT:  begin; insert into accounts values (4000,'fmt'); select 1/0;
```

Points to weigh when you choose:

- The first three formats show the client address. The `%m` format drops it.
- The first format has no timestamp in the message. The `time` field of each entry, and the
  `timestamp` field in OpenSearch, still carry the time.
- `txid` is `0` until a statement is assigned a transaction ID. `qid` is filled while query
  identifiers are computed: `compute_query_id` is `auto` on a new service, and identifiers appear
  once `pg_stat_statements` is installed.
- Lines from background processes, such as configuration reloads, have empty fields, for example
  `pid=95,user=,db=,app=,client=` in the first format.

### Set the Format

The values include their own surrounding single quotes and a trailing space, both part of the
string. Put the setting in a file to avoid shell quoting. Write `pg-settings.json`:

```json
{
  "log_line_prefix": "'%m [%p] %q[user=%u,db=%d,app=%a] '"
}
```

Then apply it:

```bash
exo dbaas update SERVICE_NAME -z ZONE -f --pg-settings "$(<pg-settings.json)"
```

Parameters:

- `SERVICE_NAME`: name of the Managed PostgreSQL service.
- `ZONE`: zone the service runs in, for example `ch-gva-2`.

`$(<file)` is a bash and zsh construct. In other shells, use `$(cat pg-settings.json)`.

The change is applied by a configuration reload, without a restart, within seconds. Confirm it:

```sql
SHOW log_line_prefix;
```

> [!TIP]
> Decide the format before you point a log analyzer at the stream. Lines written before and after a
> change have different layouts.

## Settings That Control What Is Logged

| Setting | Values | In force on a new service |
| --- | --- | --- |
| `log_min_duration_statement` | `-1` to `86400000` ms; `-1` disables, `0` logs every statement | `1000` |
| `log_temp_files` | `-1` to `2147483647` kB; `-1` disables, `0` logs every temporary file | `100` |
| `log_error_verbosity` | `TERSE`, `DEFAULT`, `VERBOSE` | `default` |
| `log_autovacuum_min_duration` | `-1` to `2147483647` ms, in the `autovacuum` group | `1000` |

`log_connections` and `log_disconnections` are on, and they are not part of the settings catalog. The platform's monitoring
user `_avnadmin_monitor` and the `postgres` superuser connect every few seconds, so most lines on a
quiet service are their connections and disconnections.

Set the values with `exo dbaas update`:

```bash
exo dbaas update my-postgresql -z ch-gva-2 -f \
  --pg-settings='{"log_min_duration_statement":500,"log_temp_files":1024,"log_error_verbosity":"VERBOSE"}'
```

`log_autovacuum_min_duration` is nested in the `autovacuum` group:

```bash
exo dbaas update my-postgresql -z ch-gva-2 -f \
  --pg-settings='{"autovacuum":{"log_autovacuum_min_duration":5000}}'
```

> [!IMPORTANT]
> `exo dbaas update --pg-settings` leaves out keys whose value is `0`. Alone, such a key fails with
> `No data to update the service`; nested in a group, it is skipped without an error. Set a `0`
> with the API instead:
>
> ```bash
> echo '{"pg-settings":{"log_min_duration_statement":0}}' | \
>   exo api update-dbaas-service-pg my-postgresql -z ch-gva-2
> ```

A slow statement is logged with its duration:

```text
[41-1] 2026-11-10 14:12:49.346 GMT [7331] [user=avnadmin,db=defaultdb,app=psql] LOG:  duration: 1101.890 ms  statement: select pg_sleep(1.1), 'slow_fmt_4'
```

For finding slow queries systematically, use `pg_stat_statements` as described in
[Identify slow queries](https://community.exoscale.com/product/dbaas/service-specific/postgresql/how-to/identify-slow-queries/index.md).

## Retrieve Logs

```bash
exo dbaas logs SERVICE_NAME -z ZONE --limit LIMIT --sort ORDER
```

Parameters:

- `SERVICE_NAME`: name of the Managed PostgreSQL service.
- `ZONE`: zone the service runs in, for example `ch-gva-2`.
- `LIMIT`: number of entries, from `1` to `500`. Without `--limit`, the command returns 100 entries.
- `ORDER`: `desc` for newest first, which is the default, or `asc`. Both return the newest `LIMIT`
  entries; `asc` lists them oldest first.

For example, the last 200 entries in chronological order, messages only:

```bash
exo dbaas logs my-postgresql -z ch-gva-2 --limit 200 --sort asc \
  --output-template '{{range $l := .Logs}}{{println $l.Message}}{{end}}'
```

Each entry carries `time` (UTC), `node`, `unit` and `message`. In an output template the fields are
`.Time`, `.Node`, `.Unit` and `.Message`. The `unit` is `postgresql-18.service` on PostgreSQL 18:
PgBouncer lines are not part of the stream, and neither are
[pgaudit](https://community.exoscale.com/product/dbaas/service-specific/postgresql/how-to/collect-pgaudit-logs/index.md) records. The
stream lags behind the server by up to about a minute.

The equivalent API operation is `get-dbaas-service-logs`:

```bash
echo '{"limit":500,"sort-order":"asc"}' | \
  exo api get-dbaas-service-logs my-postgresql -z ch-gva-2
```

### Page Through Older Entries

The JSON output carries an opaque `offset`. Pass it back to get the next older batch:

```bash
exo dbaas logs my-postgresql -z ch-gva-2 --limit 500 -O json | jq -r .offset
```

```bash
exo dbaas logs my-postgresql -z ch-gva-2 --limit 500 -o OFFSET
```

Parameters:

- `OFFSET`: the `offset` value returned by the previous call.

The response also carries the offset of the first entry of the batch, under `first_log_offset` in
`exo dbaas logs -O json` output, `first-log-offset` in the `exo api get-dbaas-service-logs`
response, and `.FirstLogOffset` in an output template.

### Keep the Logs

`exo dbaas logs` reads a bounded buffer. To keep and search the log, and to receive pgaudit records,
send it to a Managed OpenSearch service of your organization as described in
[Send logs to Managed OpenSearch](https://community.exoscale.com/product/dbaas/service-specific/postgresql/how-to/send-logs-to-opensearch/index.md).
For a system you run yourself, the rsyslog, OpenSearch and Elasticsearch external endpoints are
described in [Use External Integrations](https://community.exoscale.com/product/dbaas/how-to/external-integrations/index.md).

## Related Pages

- [Monitor a Managed PostgreSQL service](https://community.exoscale.com/product/dbaas/service-specific/postgresql/how-to/monitor-your-service/index.md)
- [Send logs to Managed OpenSearch](https://community.exoscale.com/product/dbaas/service-specific/postgresql/how-to/send-logs-to-opensearch/index.md)
- [Collect pgaudit logs](https://community.exoscale.com/product/dbaas/service-specific/postgresql/how-to/collect-pgaudit-logs/index.md)
- [PostgreSQL configuration parameters](https://community.exoscale.com/product/dbaas/service-specific/postgresql/reference/configuration-parameters/index.md)
- [Configure PostgreSQL settings](https://community.exoscale.com/product/dbaas/service-specific/postgresql/how-to/configure-settings/index.md)
- [Identify slow queries](https://community.exoscale.com/product/dbaas/service-specific/postgresql/how-to/identify-slow-queries/index.md)

