# Databases, Redis and buckets

> Run Postgres and Redis next to your units, store files in S3-compatible buckets, and keep state on a volume. Private to the project unless you open a database to the outside.

Web page: https://kuiper.sh/docs/databases/

## Postgres and Redis

Kuiper runs Postgres 17 and Redis (Valkey 8.1) for you. Each one is a private service inside your project, with a persistent disk and CPU and memory reserved for it. Only your units can reach a database, until you turn on [public access](#public-access).

![The Databases page listing a Redis cache and a Postgres database, with New database… at the top.](https://kuiper.sh/docs/img/dashboard-databases.webp "Databases. A Redis called cache and a Postgres called main.")

Create one in the dashboard from **Data**, then **Databases**: **New database…** asks for the engine, a name (Kuiper suggests a free one) and the size. Or from the CLI:

![The New database dialog with the engine, a suggested name and the size.](https://kuiper.sh/docs/img/dashboard-new-database.webp "New database. Nothing is created until you choose Create database.")

```sh
kuiper db create postgres main -p my-agent
kuiper db create redis cache -p my-agent
kuiper db list -p my-agent
kuiper db show main -p my-agent
```

Then give a unit the connection string. The variable name is your choice, and the template selects the database output:

```sh
kuiper env set -p my-agent -u web 'DATABASE_URL=${{main.DATABASE_URL}}'
kuiper env set -p my-agent -u web 'REDIS_URL=${{cache.REDIS_URL}}'
kuiper restart -p my-agent -u web
```

Postgres exports `DATABASE_URL`, `PGHOST`, `PGPORT`, `PGUSER`, `PGPASSWORD` and `PGDATABASE`. Redis exports `REDIS_URL`, `REDIS_HOST`, `REDIS_PORT` and `REDIS_PASSWORD`. See [Variables and secrets](https://kuiper.sh/docs/variables.md) for how templates work.

Hostnames look like `<database>.<project>.internal` and resolve only inside the project's private network. Postgres URLs use `sslmode=disable` because the traffic never leaves that network.

### Public access

Public access lets clients outside Kuiper connect to a database: `psql` on your laptop, a database GUI, an app hosted somewhere else, a CI job. It is off until you turn it on.

1. In the dashboard, open **Data**, then **Databases**, pick the database, and under **Public access** choose **Make public**.
2. Choose who may connect: **Any address**, or **Only these addresses**, with IP addresses like `203.0.113.7` or ranges like `198.51.100.0/24`.
3. Connect with the new URL in the database's outputs: `DATABASE_PUBLIC_URL` for Postgres, `REDIS_PUBLIC_URL` for Redis.

From the CLI:

```sh
kuiper db public main -p my-agent --on --allow 203.0.113.7
kuiper db public main -p my-agent                  # show it
kuiper db credentials main -p my-agent --reveal    # DATABASE_PUBLIC_URL=…
kuiper db public main -p my-agent --off
```

`--on` without `--allow` lets any address connect. The addresses you give replace the whole list.

The database gets a port of its own on one shared host, like `db.kiprsh.app:20417`. Connections are encrypted with TLS, with a publicly trusted certificate, and the database keeps its password.

| Engine | Outputs public access adds |
| --- | --- |
| Postgres | `DATABASE_PUBLIC_URL` (`postgresql://kuiper:…@db.kiprsh.app:20417/kuiper?sslmode=require`), `PUBLIC_HOST`, `PUBLIC_PORT` |
| Redis | `REDIS_PUBLIC_URL` (`rediss://default:…@db.kiprsh.app:20418/0`), `PUBLIC_HOST`, `PUBLIC_PORT` |

- Postgres clients must use TLS: `sslmode=require` or stricter. With psql 16 or newer, add `sslrootcert=system` and use `sslmode=verify-full` to check the certificate as well.
- Redis clients use `rediss://`, with two s's.
- Turning public access on or off restarts the database, which takes a few seconds. Changing the list of addresses doesn't, and applies at once, to open connections too.
- A client whose address isn't on the list gets an error that says so.
- Turning public access off removes the public outputs. Kuiper refuses while a variable references one, and lists those variables.
- Your units keep using the private outputs. They are faster and never leave the project.
- A database in a new [environment](https://kuiper.sh/docs/environments.md) starts private, even when the one it copies is public.

> **Keep the list short**
>
> Anyone who has the URL can connect from an allowed address. List only the addresses that need access, and turn public access off when you no longer need it.

### Sizes and versions

Choose a size with `--size`. The default is `small`.

| Size | CPU | Memory | Disk |
| --- | --- | --- | --- |
| `small` | 0.5 | 512 MiB | 5 GiB |
| `medium` | 1 | 2 GiB | 20 GiB |
| `large` | 2 | 4 GiB | 50 GiB |

```sh
kuiper db create postgres main --size medium
```

`--version 17` selects Postgres 17 and `--version 8.1` selects Redis 8.1. Those are the supported versions. Images are pinned, so a restart never upgrades the engine. Resizing and upgrades are not available yet. A major-version move means a dump and restore into a fresh database.

### Credentials

Passwords and URLs are sealed. The dashboard, the CLI and the API mask them by default. To read them, ask for it explicitly:

```sh
kuiper db credentials main -p my-agent --reveal
```

To change a password, for example after a URL was shared by mistake, rotate it. In the dashboard, open the database and choose **Rotate password**, or:

```sh
kuiper db rotate-password main -p my-agent
```

Kuiper makes a new password and restarts the database with it, which takes a few seconds. It also restarts every unit whose variables use the database's outputs, so they get the new values. The old password stops working, and so does every URL that contains it, including the public one. Give clients outside Kuiper the new URL from `kuiper db credentials --reveal`. If a unit can't restart, Kuiper says which one; restart it yourself once it can.

### Restart and delete

```sh
kuiper db restart main -p my-agent
kuiper db delete main -p my-agent --confirm main
```

A restart stops the database and starts it again on the same disk, with the same data and credentials. Deleting is permanent: it removes the credentials, the service and its disk. Remove the variables that reference the database first. Kuiper lists any that remain.

> **No automatic backups yet**
>
> Kuiper does not back up databases for you yet. On a single-node installation the data lives on that node's disk, and losing the disk loses the database. Arrange your own backups before you store anything you cannot recreate.

## Buckets

A bucket is private, S3-compatible object storage for files: reports, uploads, media. Create one from **Data**, then **Buckets**, or the CLI:

```sh
kuiper buckets create reports -p my-agent
kuiper buckets list -p my-agent
kuiper buckets show reports -p my-agent
```

![The Buckets page with one bucket, its object count, bytes used and quota.](https://kuiper.sh/docs/img/dashboard-buckets.webp "Buckets.")

Each bucket has its own access key. Bind its values to a unit like any other output:

```sh
kuiper env set -p my-agent -u web \
  'S3_ENDPOINT=${{reports.S3_ENDPOINT}}' \
  'S3_BUCKET=${{reports.S3_BUCKET}}' \
  'S3_REGION=${{reports.S3_REGION}}' \
  'S3_FORCE_PATH_STYLE=${{reports.S3_FORCE_PATH_STYLE}}' \
  'S3_ACCESS_KEY_ID=${{reports.S3_ACCESS_KEY_ID}}' \
  'S3_SECRET_ACCESS_KEY=${{reports.S3_SECRET_ACCESS_KEY}}'
```

Use path-style addressing with any S3 client. The endpoint is a public address, so the same bucket works from inside and outside Kuiper.

```sh
kuiper buckets credentials reports -p my-agent --reveal
kuiper buckets delete reports -p my-agent --confirm reports
```

A bucket holds up to 10 GiB and 1,000,000 objects by default, and an organisation can allocate 100 GiB in total. Deleting needs an empty bucket with no unfinished uploads and no variable that references it.

### Browser access (CORS)

By default only your app's server can use a bucket. Browsers block a web page on another site from reading or uploading files in it. To let your website do that, for example to upload media straight from the browser with a signed link your app hands out, allow its address.

In the dashboard, open **Data**, then **Buckets**, pick the bucket, and under **Browser access** choose **Allow websites**:

1. Add each website by the address people visit, like `https://app.example.com`, with no path. Kuiper suggests your project's own addresses and `http://localhost:3000` for local development. **Allow any website (\*)** suits public files.
2. Choose **Read files** (GET, HEAD) or **Read and upload** (also PUT, POST, DELETE).

**Advanced** sets the request headers pages may send (`*` by default), the response headers scripts may read (`ETag` by default) and how long a browser caches the check (an hour). The status turns **On** within seconds.

From the CLI:

```sh
kuiper buckets cors media -p my-agent --origin https://app.example.com --uploads
kuiper buckets cors media -p my-agent              # show it
kuiper buckets cors media -p my-agent --off
```

Every request still needs a signed link or the bucket's key; browser access only decides which websites a browser lets use them. Plain `<img src>` and `<video src>` tags work without it.

## Volumes

A volume is a persistent disk. Foundry and Station units get one automatically, mounted at `/data`. Other apps ask for one with `resources.volumeGiB` in `kuiper.json`.

```sh
kuiper volumes -p my-agent
```

![The Volumes page listing a disk for each unit and database.](https://kuiper.sh/docs/img/dashboard-volumes.webp "Volumes. A disk for each unit that keeps state, and one for each database.")

A volume belongs to the project and outlives the container. Because a volume lives on one node, a unit with a volume runs as a single instance. Keep state that must survive restarts on `/data`, such as a SQLite file.

## External databases

Prefer a database you already have, like Neon, Upstash or your own RDS? Add it as a resource with its outputs and reference it the same way. See [External services](https://kuiper.sh/docs/variables/#external-services).
