# Sleep, wake and delete a database

> Park a database, reconnect after waking, and remove it when finished

> Nevia is in beta and open to selected teams. Public launch in Dec 2026. The CLI installs with `curl -fsSL https://get.nevia.cloud | sh`, and the MCP server is at https://api.nevia.cloud/mcp. A person signs in once in the browser.
> Setup, sign-in and requesting access: [SKILL.md](https://nevia.cloud/SKILL.md). When Nevia fits and when it doesn't: [why.md](https://nevia.cloud/why.md).

> For the complete documentation index, see [llms.txt](https://nevia.cloud/llms.txt). This page's HTML version: https://nevia.cloud/docs/databases/lifecycle

Sleep `orders` to pause execution while it keeps its memory allocated and its
data. Wake it when you need SQL access again. Delete it when you no longer need
the database or its data.

You need [the CLI installed and signed in](https://nevia.cloud/docs/get-started/quickstart.md), a
[selected workspace](https://nevia.cloud/docs/workspaces/select.md) where you have the admin or editor
role, and an existing `orders` database. The connection check uses `psql`.
See [Create and connect to a database](https://nevia.cloud/docs/databases/create.md) for setup.

## Sleep

```bash
nevia pg status orders
```

The state must be `ready`, with no pending transition or running operation.
Finish your queries first, because SQL access is unavailable while the database
sleeps. Sleep pauses the machine in memory. It creates no snapshot and releases
no RAM. The CLI command `pg suspend` calls the API's sleep route.

```bash
nevia pg suspend orders --wait
nevia pg status orders
```

The state should be `sleeping`, with no pending transition. The database keeps
its data, host and credentials, but SQL connections can't reach it until you
wake it.

## Wake

You can wake a `sleeping` database with no pending transition or running operation:

```bash
nevia pg awake orders --wait
nevia pg status orders
```

The state should be `ready`. Open a new connection with the same credentials:

```bash
psql "$(nevia pg connect orders --uri)" -c 'SELECT 1;'
```

You should see one row containing `1`. Status reads and `pg connect` don't wake
the database, so run `pg awake` before you reconnect.

Database status doesn't report last connection or query activity, because the
control plane can't observe SQL usage yet. Sleep is manual, not triggered by
idle activity.

The wait lasts up to 10 minutes. If it times out, [track the operation](https://nevia.cloud/docs/guides/operations.md)
before you issue another lifecycle command.

## Protect a database

Block accidental deletion of `orders`:

```bash
nevia pg set orders --protected true
```

The output shows `protected: true`. Protection blocks deletion only. You can
still sleep, wake or branch the database, and the setting takes effect without a
restart.

## Delete

Deletion removes the database and its data and interrupts open connections.
No operation can be running on the database, and protection must be off.
`--yes` only skips the CLI confirmation. Deleting a parent leaves its branches
running with their own data.

If you created `orders-staging` and no longer need it, delete it first. Clear its
protection if you enabled it:

```bash
nevia pg rm orders-staging --yes --wait
```

To delete `orders`, clear its protection and then delete it:

```bash
nevia pg set orders --protected false
nevia pg rm orders --yes --wait
nevia pg ls
```

The deleted databases should be gone from the list. You can delete a sleeping
database without waking it.

See [Database lifecycle states](https://nevia.cloud/docs/reference/database-lifecycle.md) for state
and persistence rules, and [`nevia pg`](https://nevia.cloud/docs/reference/cli/pg.md) for command options.
