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

# sabaoth postgres logs

> Stream a PostgreSQL service's logs live

Follows a service's logs live until you stop it with **Ctrl-C**.

```bash theme={null}
sabaoth postgres logs <service-id> --follow [--severity <level>] [--tail <n>] [--org <org-id>] [--json]
```

## Arguments

**service-id** `string` *required*

The ID of the service whose logs you want, for example `clu_abc`.

## Flags

**--follow, -f** `boolean` *required*

Stream log events until interrupted. Required: this command only streams, and there's no one-off read.

**--severity** `string`

Only show events at this level or above. One of `debug`, `info`, `warn` or `error`.

**--tail** `integer`

Replay this many past lines before following, from `0` to `5000`.

**--org** `string`

Organization the service belongs to, instead of the selected one.

**--json** `boolean` (default: false)

Print newline-delimited JSON (NDJSON), one record per line. See [JSON output](#json-output).

## Examples

```bash theme={null}
# Follow everything
sabaoth postgres logs clu_abc --follow

# Only warnings and errors
sabaoth postgres logs clu_abc -f --severity warn

# Replay the last 200 lines, then keep following
sabaoth postgres logs clu_abc -f --tail 200

# Save to a file while watching
sabaoth postgres logs clu_abc -f | tee orders-db.log

# NDJSON, filtered with jq
sabaoth postgres logs clu_abc -f --json | jq -c 'select(.type == "log") | .event'
```

## Human output

Each event is printed on its own line as it arrives. Log text comes straight from the database, so the CLI cleans out terminal control characters before printing. A log line can't repaint your terminal or fake other output.

Notices, such as reconnect messages, go to stderr. Piping stdout into a file or another tool captures only log lines.

## JSON output

With `--json`, stdout carries one JSON record per line:

```text theme={null}
{"type":"log","event":{ ... }}
{"type":"log","event":{ ... }}
{"type":"error","error":{"code":"API_KEY_UNAUTHORIZED","category":"auth","message":"...","retryable":false}}
```

| Record | Meaning |
| - | - |
| `{"type":"log","event":...}` | A log event. |
| `{"type":"error","error":...}` | The stream ended because of an error that can't be retried. This is always the **last** line, and there's at most one. `error` has the same shape as any [CLI error](https://docs.sabaothcloud.com/cli/scripting.md#errors). |

> [!NOTE]
>
> The `type`, `event` and `error` keys are part of the CLI's stable output. The contents of `event` are passed through exactly as the API sent them and are **not** a stable format: fields may change. Read them defensively. If an event isn't JSON, it's passed through as a string.

Pressing Ctrl-C isn't an error, so it doesn't produce an `error` record.

## Reconnecting

If the connection drops for a reason that can be retried, the CLI reconnects on its own. This includes network failures, `429` (too many log streams open for the organization) and `503` (the log stream couldn't attach to the database).

* **It keeps trying for as long as you let it**, waiting longer between attempts each time, up to 30 seconds. `--follow` means follow, so an outage doesn't quietly cut the log short.
* **It picks up where it left off**, from the time of the last event it saw.
* **Events may still be missed** during the gap. Each reconnect prints `Reconnecting to the log stream; events may have been missed during the gap.` on stderr, so you can see where a gap might be.
* **`--tail` applies only to the first connection.** A reconnect doesn't replay history again.

Errors that can't be fixed by retrying, such as a revoked key or a service that doesn't exist, end the stream with exit code `1`.

## Stopping

Press **Ctrl-C**, or send `SIGTERM`. The CLI closes the stream, cancels any pending reconnect and exits with code `130`.

## Errors

| Code | Exit | Meaning |
| - | - | - |
| `FOLLOW_REQUIRED` | 2 | You didn't pass `--follow`. |
| `INVALID_SEVERITY` | 2 | `--severity` isn't one of `debug`, `info`, `warn` or `error`. |
| `INVALID_TAIL` | 2 | `--tail` isn't a whole number from 0 to 5000. |
| `STREAM_NOT_AVAILABLE` | 1 | The API didn't answer with a log stream. |
| `API_KEY_UNAUTHORIZED` | 1 | The key was rejected. |

## Related

* [Logs in the dashboard](https://docs.sabaothcloud.com/dashboard/logs.md)
* [`sabaoth postgres get`](https://docs.sabaothcloud.com/cli/commands/postgres-get)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.