# Databases

Run Redis or Postgres on the phone, next to your apps. Your apps get the connection URL by themselves.

## Make one

On the phone, tap **Templates** at the bottom, or open **Templates** in the dashboard. Pick **Redis** or **Postgres**, tick the apps that need it and tap **Create**. Or from your computer:

```sh
$ dukoi db create redis --app my-api
Starting Redis on pixel-10a…
✓ redis is running on port 6380
  my-api got REDIS_URL and restarted.
```

Your app reads `process.env.REDIS_URL`, or `process.env.DATABASE_URL` for Postgres. Use a JavaScript client, like `redis` or `ioredis`, and `pg` or `postgres`.

```
import { createClient } from 'redis'

const redis = createClient({ url: process.env.REDIS_URL })
await redis.connect()
await redis.incr('visits')
```

## What runs

-   **Redis** is [Valkey](https://valkey.io) 9.1, the open-source Redis. Every Redis client and command works. It uses about 10 MB of memory to start.
-   **Postgres** is [PGlite](https://pglite.dev), real Postgres 18 that runs on the phone’s Node. Several connections work, and queries run one at a time, so it suits small apps. It uses about 400 MB of memory, so check your phone has room.

Data is saved on the phone, so it survives restarts, reboots and deploys.

## Connect and disconnect apps

```sh
$ dukoi db connect redis worker
✓ worker got REDIS_URL and restarted
```

Connecting sets the app’s `REDIS_URL` or `DATABASE_URL` setting and restarts it once. `dukoi db disconnect redis worker` takes it away. Several apps can share one database.

## Use it from your computer

A database is for the phone’s apps until you turn on Wi-Fi access. Then devices on your Wi-Fi can connect, with the same password:

```sh
$ dukoi db wifi postgres
✓ postgres is reachable on your Wi-Fi
  URL: dukoi db url postgres --wifi
```

```sh
$ psql "$(dukoi db url postgres --wifi)"
```

On the phone and in the dashboard, it’s the **Also reachable on Wi-Fi** box on the database’s page. Databases never get a public link.

> Use a network you trust
> 
> The password crosses your Wi-Fi in plain text, like it does for any Redis or Postgres without TLS. Turn Wi-Fi access off with `dukoi db wifi postgres --off` when you’re done.

## Passwords

Every database has its own password, already in its URL. Dukoi shows URLs with the password hidden. `dukoi db url redis` and the copy buttons give you the full one.

`dukoi db password redis` makes a new one. Connected apps get the new URL and restart, and the old password stops working at once.

## Everything else

-   `dukoi db` lists your databases. `dukoi db logs redis` shows a database’s log.
-   `dukoi db stop`, `start` and `restart` work like they do for apps.
-   `dukoi db remove redis` deletes the database and its data, and takes its URL from your apps. It asks first.
