# ry postgres

> Managed Postgres: create, branch, fork, sleep policy (stored; not in force on every host).

```text
ry postgres [options] [command]
```

Alias: `pg`.

## Subcommands

### `ry postgres create`

Create a Postgres database: the connection URL is in --json output only.

```text
ry postgres create [options] <name>
```

Options:

- `-m, --memory <mb>`: Memory in MB. Default: `1024`.
- `-s, --size <gb>`: Volume size in GB (minimum 4: the database keeps its write-ahead log on it). Default: `10`.
- `--locale <locale>`: Collation locale of the database, e.g. de-DE, fr-FR, de-DE-u-co-phonebk.
- `--always-on`: Store the policy 'always on' (never suspend) instead of the default policy 'suspend after 5m idle'.
- `--sleep-after <duration>`: Store the sleep policy 'suspend after this long without a query or traffic', e.g. 5m, 1h (10s to 1d).

Example:

```bash
ry postgres create appdb
ry postgres create appdb --size 20 --locale en-US
```

### `ry postgres list`

List Postgres databases with their sleep policy.

```text
ry postgres list [options]
```

Example:

```bash
ry postgres list
```

### `ry postgres expire`

When a copy (fork or branch) is deleted: --in `<duration>`, --at `<time>` or --never.

```text
ry postgres expire [options] <name>
```

Options:

- `--in <duration>`: Delete it after this long from now, e.g. 12h, 7d (60s to 30d).
- `--at <time>`: Delete it at this moment, ISO 8601 UTC (at most 30 days ahead).
- `--never`: Keep it until somebody deletes it.

Example:

```bash
ry postgres expire appdb-try --in 12h
```

### `ry postgres sleep`

Set the sleep policy of the database: --after `<duration>` (e.g. 5m) or --off (always on).

```text
ry postgres sleep [options] <name>
```

Options:

- `--after <duration>`: Store 'suspend after this long without a query or traffic', e.g. 5m, 1h (10s to 1d).
- `--off`: Store 'always on': never suspend.

Example:

```bash
ry postgres sleep appdb --after 10m
ry postgres sleep appdb --off
```

### `ry postgres branch`

Branch a database from NOW: a copy-on-write snapshot on the source's host, usable in seconds.

```text
ry postgres branch [options] <source> <name>
```

Options:

- `--ephemeral`: Throwaway branch for a test or a task: ready without its own backup, but lost with its host (never restarted empty).
- `--expires-in <duration>`: Delete the branch after this long, e.g. 12h, 7d (60s to 30d).
- `--expires-at <time>`: Delete the branch at this moment, ISO 8601 UTC (at most 30 days ahead).

Example:

```bash
ry postgres branch appdb appdb-try --expires-in 1d
```

### `ry postgres fork`

Fork a database from its archive onto any host: a full copy, minutes for large databases; --at for a point in time.

```text
ry postgres fork [options] <source> <name>
```

Options:

- `--at <time>`: Restore to this point in time instead of now, ISO 8601 UTC, e.g. 2026-10-04T09:30:00Z (within the archive's 7 days).
- `--expires-in <duration>`: Delete the fork after this long, e.g. 12h, 7d (60s to 30d).
- `--expires-at <time>`: Delete the fork at this moment, ISO 8601 UTC (at most 30 days ahead).

Example:

```bash
ry postgres fork appdb appdb-yesterday --at 2026-10-20T09:00:00Z
```

### `ry postgres restore`

Put a database back to a point in time IN PLACE: same name and URL, the old state is kept as a branch.

```text
ry postgres restore [options] <name>
```

Options:

- `--at <time>`: The point in time, ISO 8601 UTC, e.g. 2026-10-07T09:30:00Z (within the archive's 7 days).
- `--backup-name <name>`: Name of the branch that keeps the old state (default `<name>-old-<yyyymmddhhmmss>`).
- `-y, --yes`: Confirm without asking (automation, and the way back after consent).

Example:

```bash
ry postgres restore appdb --at 2026-10-20T09:00:00Z
```

### `ry postgres destroy`

Destroy a database, its machine and its volume (irreversible).

```text
ry postgres destroy [options] <name>
```

Options:

- `-y, --yes`: Confirm without asking (automation, and the way back after consent).

Example:

```bash
ry postgres destroy appdb-try --yes
```
