# Doctor

> Run postern-hub doctor for each install method, what every check means and how to fix each warning and problem, exit codes, and the setup-code command.

Source: https://docs.posternmail.app/admin/doctor/

`postern-hub doctor` checks a Hub's configuration, files, key, network and backups and tells you
what to fix. Run it after installing, after changing settings, after an upgrade or a restore, and
whenever something seems wrong. This page lists every check with its exact messages. It also
covers `postern-hub setup-code`.

## Run it

`doctor` only reads. It opens the database read-only, applies nothing, and works whether the Hub
is running or not. It must run with the same settings as the Hub, which the commands below take
care of.

**Docker Compose:**
```sh
cd ~/postern
docker compose exec hub postern-hub doctor
```

If the Hub container is stopped, use `docker compose run --rm hub doctor` instead.
**Debian and Ubuntu, Fedora and RHEL and Raspberry Pi OS:**
```sh
sudo -u postern sh -c 'set -a; . /etc/postern/hub.env; exec postern-hub doctor'
```

Running it as the `postern` user matters: as root or as yourself, the file permission and write
checks would test the wrong user.
**Desktop app (built-in Hub):**
Not available from the app. The app reports problems with its built-in Hub itself, and
`logs/hub.log` in the app's data folder has the details (see [Logs](https://docs.posternmail.app/admin/logs/)).

If you are comfortable with a terminal, you can run the binary that ships inside the app. On
macOS:

```sh
/Applications/Postern.app/Contents/Resources/hub/hub doctor --data-dir ~/Library/Application\ Support/Postern/hub-data --key-file ~/Library/Application\ Support/Postern/hub-key/hub.key
```

On Windows and Linux the binary is `resources/hub/hub` (`hub.exe` on Windows) inside the app's
installation folder.

## Reading the output

```text
Postern Hub 0.9.0 linux/arm64 go1.27.1

Data directory
✓ /var/lib/postern (mode 0700)
  A Hub is currently running on this data directory.
✓ 21.2 GiB of free disk space

Database
✓ /var/lib/postern/hub.db (48.3 MiB), integrity check passed
✓ schema up to date (21 migrations)

Master key
✓ /var/lib/postern-key/hub.key (plain, matches the database)

Network
✓ https://mail.example.com is reachable (Hub 0.9.0)
✓ TLS certificate for mail.example.com valid until 2027-02-11
  Push relay disabled (POSTERN_RELAY_URL not set): mobile apps rely on background refresh or UnifiedPush.

Sign-in & providers
✓ Google OAuth client configured (POSTERN_GOOGLE_CLIENT_ID)
  Microsoft client not configured via environment (can also be set in the admin UI)
  Single sign-on (OIDC) not configured

Backups
✓ scheduled backups every 24h0m0s, keeping 7, in /var/lib/postern/backups
✓ newest backup: Sat, 05 Dec 2026 03:30:00 UTC

Everything looks good.
```

| Mark | Meaning |
|---|---|
| `✓` | The check passed. |
| `!` | A warning: works, but something is missing or will cause trouble. |
| `✗` | A problem: something does not work and needs fixing. |
| (two spaces) | Information, no action needed. |

The last line sums up: "Everything looks good.", "No problems, N warning(s)." or "N problem(s),
N warning(s)."

## Exit codes

| Code | When |
|---|---|
| `0` | No problems. Warnings do not change the exit code. |
| `1` | At least one `✗` problem. `doctor` then also prints `error: doctor found N problem(s)` to standard error. Also used when the command itself cannot run, for example with an unknown flag. |

So `postern-hub doctor` works in a monitoring script or a health check that should only fail on
real problems.

## Every check

### Before the sections

| Message | Meaning and fix |
|---|---|
| `! MC_... is ignored: POSTERN_... is set too, with another value (rename the old MC_* lines in your env file)` | An old variable from before the rename is set next to its new name with a different value. The new one wins. Rename or remove the old line. See [Migrating from MailClient](https://docs.posternmail.app/migrating-from-mailclient/). |

### Data directory

| Message | Meaning and fix |
|---|---|
| `✓ <dir> (mode 0700)` | The directory exists and only its owner can open it. |
| `! <dir> does not exist yet (the Hub creates it on first start)` | Normal before the first start. Otherwise check `POSTERN_DATA_DIR`. |
| `✗ <dir> is not a directory` | `POSTERN_DATA_DIR` points at a file. |
| `! <dir> is accessible by other users (mode 0755); run: chmod 700 <dir>` | Other accounts on the machine can list the files. Run the command shown. |
| `✗ cannot write to <dir>: ...` | The user running `doctor` (and the Hub) cannot write there. Fix the owner: `sudo chown -R postern:postern /var/lib/postern`; in Docker the owner must be uid 10001. |
| `A Hub is currently running on this data directory.` / `No Hub is running on this data directory.` | Whether a Hub holds the data directory's lock (`hub.lock`). |
| `✓ N GiB of free disk space` | 2 GiB or more free. |
| `! only N of free disk space left` | Less than 2 GiB. Free up space soon: sync, backups and migrations need room. |
| `✗ only N of free disk space left` | Less than 512 MiB. Free up space now. |
| `Free disk space: unknown on this platform` | The check is not available on this system. |

### Database

| Message | Meaning and fix |
|---|---|
| `✓ <path> (size), integrity check passed` | SQLite's integrity check found nothing wrong. |
| `! no database at <path> yet (created on first start)` | Normal before the first start. |
| `! <path> is readable by other users; run: chmod 600 <path>` | Run the command shown. |
| `✗ cannot open <path>: ...` | The file cannot be opened: permissions, or not a database. |
| `✗ integrity check failed: ...` | The check could not run. |
| `✗ integrity check reported damage: ... (restore a backup with 'hub restore')` | The database is damaged, usually after a full disk, a power cut on a bad SD card, or a copy taken while the Hub was writing. Restore the newest backup: [Backups and restore](https://docs.posternmail.app/admin/backups/#restore). |
| `✓ schema up to date (N migrations)` | The database matches this version of the Hub. |
| `! N schema migration(s) pending: ... (applied automatically on next start, after an automatic backup)` | You installed a newer binary but have not restarted the Hub yet. Restart it. See [Upgrades](https://docs.posternmail.app/admin/upgrades/#what-happens-on-the-first-start). |
| `N schema migrations applied (pending check skipped: ...)` | The pending check works on a temporary copy and is skipped for databases larger than 512 MB or when the copy fails. |
| `✗ cannot read schema migrations: ...` | The file is not a Postern database or is badly damaged. |

### Master key

| Message | Meaning and fix |
|---|---|
| `✓ <path> (plain, matches the database)` | The key file is readable, valid, and decrypts this Hub's data. `sealed` instead of `plain` means it is protected by a passphrase. |
| `! no key file at <path> yet (created on first start)` | Normal before the first start. |
| `✗ key file <path> is missing but a database exists: restore the key file from your backup` | Without the key the data cannot be read. Put your copy of `hub.key` back. Starting the Hub without it would create a new key that does not fit the data. |
| `✗ <path> is readable by other users (mode 0644); run: chmod 600 <path>` | Anyone on the machine could copy the key. Run the command shown. |
| `! <path> is sealed; set POSTERN_KEY_PASSPHRASE to let doctor (and the Hub) unlock it` | The key is protected by a passphrase that this environment does not have. |
| `✗ cannot read <path>: ...` | Permissions: the key must be readable by the Hub's user only. |
| `✗ <path>: ...` | The file is not a valid key, or the passphrase is wrong. |
| `✗ <path> does not match this database (cannot decrypt ...): wrong key file?` | The key belongs to another Hub or to a time before `rotate-key`. Put the right key in place (after a rotation the old one is `hub.key.bak`). |
| `The key file lives in the data directory. Backups exclude it: keep a separate copy somewhere safe.` | Only a hint: `POSTERN_KEY_FILE` is inside the data directory, which is the default for a manual binary. Keep a copy elsewhere. |

### Setup

This section only appears while the Hub has no account.

| Message | Meaning and fix |
|---|---|
| `! this Hub is not set up yet: open it in a browser and enter the setup code K7QF-2M9X-H4TC` | Open the Hub and run the setup wizard with this code. See [Set up your Hub](https://docs.posternmail.app/setup/). |
| `! this Hub is not set up yet: run 'postern-hub setup-code' (or start the Hub) for the setup code` | No code was created yet. Start the Hub or run `setup-code`. |

### Network

| Message | Meaning and fix |
|---|---|
| `! POSTERN_PUBLIC_URL is not set: invite and pairing links use whatever address a browser used, and passkeys only work on localhost` | Set `POSTERN_PUBLIC_URL` to the address people use. |
| `! POSTERN_PUBLIC_URL is not HTTPS: passkeys and Google sign-in are unavailable` | The public URL uses `http://` and is not `localhost`. See [HTTPS](https://docs.posternmail.app/reach/https/). |
| `✓ <url> is reachable (Hub <version>)` | `doctor` fetched `<url>/api/v1/info` from this machine and a Postern Hub answered. |
| `✗ <url> is not reachable from this machine: ... (is the Hub running? DNS / firewall / reverse proxy?)` | The request failed. Check that the Hub runs, that the name resolves on the server itself, and the proxy. Some setups cannot reach their own public address from inside (no hairpin NAT); then this check fails although phones get through. |
| `✗ <url> answered, but not with a compatible Postern Hub (apiVersion N)` | Something else answers at that address, or a Hub with an incompatible API version. |
| `! <url> is behind an access gateway (Cloudflare Access) that turned this check away: set POSTERN_ACCESS_CLIENT_ID and POSTERN_ACCESS_CLIENT_SECRET ...` | Cloudflare Access blocks the apps too. Create a service token and set both variables. See [Cloudflare Tunnel](https://docs.posternmail.app/reach/cloudflare/). |
| `✗ Cloudflare Access in front of <url> rejected the configured service token (POSTERN_ACCESS_CLIENT_ID): ...` | The token is not in the application's Service Auth policy, or it expired or was revoked. |
| `✓ <url> is reachable through Cloudflare Access with the apps' service token (Hub <version>)` | The gateway lets the apps through. |
| `! the system clock differs from <url> by N: TOTP codes and TLS may fail (enable NTP)` | The `Date` header of the answer is more than a minute off this machine's clock. Turn on NTP (`sudo timedatectl set-ntp true`). |
| `✓ TLS certificate for <host> valid until <date>` | The certificate the public address presents. |
| `! TLS certificate for <host> expires in N days (<date>)` | Less than 14 days left. Check that renewal works (Caddy, Tailscale, your ACME client). |
| `✗ TLS certificate for <host> expired on <date>` | Browsers and apps refuse the connection. Renew it. |
| `✗ TLS connection to <host>:443 failed: ...` | No TLS on that port, an invalid certificate, or the host is unreachable. |
| `✓ / ! / ✗ TLS certificate for <file> ...`, `✗ cannot read POSTERN_TLS_CERT ...`, `✗ POSTERN_TLS_CERT ... is not a PEM certificate` | The same expiry checks for a certificate file set with `POSTERN_TLS_CERT`, and errors reading it. |
| `✓ automatic TLS (ACME) for <domain>` | `POSTERN_TLS_DOMAIN` is set. |
| `Push relay disabled (POSTERN_RELAY_URL not set): mobile apps rely on background refresh or UnifiedPush.` | No push relay. See [Push relay](https://docs.posternmail.app/relay/). |
| `✓ push relay <url> is healthy` / `✗ push relay <url> is unreachable` | `doctor` asked the relay's `/healthz`. |

### Sign-in & providers

| Message | Meaning and fix |
|---|---|
| `✓ Google OAuth client configured (POSTERN_GOOGLE_CLIENT_ID)` | Set by environment variables. |
| `! POSTERN_GOOGLE_CLIENT_ID and POSTERN_GOOGLE_CLIENT_SECRET must be set together` | Set both, or neither. |
| `Google OAuth not configured via environment (can also be set in the admin UI)` | Information. A client saved in the admin panel is not checked here. |
| `✓ Microsoft client configured (tenant common)` / `Microsoft client not configured via environment ...` | The same for Microsoft. |
| `Single sign-on (OIDC) not configured` | Information. |
| `✗ OIDC is partially configured: POSTERN_OIDC_ISSUER and POSTERN_OIDC_CLIENT_ID are required` | Set both. |
| `✓ OIDC issuer <url> reachable ("<name>")` | The provider's discovery document loads. |
| `✗ OIDC issuer <url> is not reachable: ...` | Check the issuer URL and that this machine can reach it. See [Sign-in methods](https://docs.posternmail.app/admin/sign-in/#single-sign-on-oidc). |

`doctor` does not sign in to any mail provider and does not test mailboxes. The admin panel's
**Mailboxes on your Hub** table shows each mailbox's sync status.

### Backups

| Message | Meaning and fix |
|---|---|
| `✓ scheduled backups every 24h0m0s, keeping 7, in <dir>` | The schedule in effect. |
| `! scheduled backups are disabled (POSTERN_BACKUP_INTERVAL=0)` | Turn them on, or back up another way. |
| `✓ newest backup: <time>` | The newest `backup-*` folder. |
| `No backups yet (run: hub backup)` | Normal on a new Hub: the first scheduled backup runs 5 minutes after the first start. |
| `! the newest backup is from <time>` | Older than twice the interval plus an hour. Look for `scheduled backup failed` in the [logs](https://docs.posternmail.app/admin/logs/). |

## Privacy of the output

`doctor` prints no passwords, tokens, client secrets or key material. It does print paths, your
public URL, the relay URL, the single sign-on issuer and button name, version information, and,
before setup, the **setup code**. Remove what you would rather keep private before you post the
output, and never post it while the setup code is still in it.

## setup-code

Until the Hub has an account, whoever opens the setup wizard first becomes its admin. A Hub can
be reachable before you get to it: scanners find new HTTPS names within minutes of the
certificate being issued. So the wizard asks for a **setup code** that only someone with access to
the server can read. Browsers on the Hub's own machine (`http://localhost:8080` with no proxy
in between, as with the desktop app) do not need it.

The Hub creates the code on its first start, stores it in `<data-dir>/setup-code`, logs it on
every start until setup is done, and deletes it once the first account exists. It looks like
`K7QF-2M9X-H4TC`; capitals, spaces and dashes do not matter when you type it.

**Docker Compose:**
```sh
cd ~/postern
docker compose exec hub postern-hub setup-code
```
**Debian and Ubuntu, Fedora and RHEL and Raspberry Pi OS:**
```sh
sudo -u postern sh -c 'set -a; . /etc/postern/hub.env; exec postern-hub setup-code'
```
**Desktop app (built-in Hub):**
Not needed: the app opens its built-in Hub from the same computer, which skips the code.

The command prints the code (and creates it if the Hub has not started yet). On a Hub that is
already set up it prints "This Hub is already set up: no setup code is needed. Sign in, or create
users with 'postern-hub admin create-user'." `doctor` shows the code too, in its **Setup**
section.

If the wizard says "That setup code isn't right", copy it again from the command's output. The
setup page allows 5 attempts per IP address, then one per minute.
