# Databases

dudbox runs Postgres, MySQL and Redis for your apps. A database has no web address: only your apps can reach it.

## Add one

1. In the dashboard, click **New**, then **Database**.
2. Pick Postgres, MySQL or Redis, then click **Deploy**. It is ready in about a minute.
3. On the database's page, the **Connect** card has the URL your apps connect with.

| Database | Version | Env var | URL |
| --- | --- | --- | --- |
| Postgres | 18 | `DATABASE_URL` | `postgres://postgres:PASSWORD@postgres:5432/app` |
| MySQL | 8.4 | `DATABASE_URL` | `mysql://root:PASSWORD@mysql:3306/app` |
| Redis | 8.4 | `REDIS_URL` | `redis://:PASSWORD@redis:6379` |

The host in the URL is the database's name. A second Postgres is `postgres-2`, and so on.

## Connect an app

The **Connect** card shows the env var and its URL, with the password hidden. **Show** shows it, and the copy button copies the full URL.

To give the URL to an app, pick the app next to **Add** and click it. dudbox sets the env var on that app as a secret. Then click **Redeploy** so the app starts with it. You can also paste the URL on the app's **Env** tab yourself. See [Env vars](/docs/env.md).

The password is the database's env var `POSTGRES_PASSWORD`, `MYSQL_ROOT_PASSWORD` or `REDIS_PASSWORD`. Do not change it on the **Env** tab: Postgres and MySQL keep the password they started with, so your apps could not log in.

## Backups

Postgres and MySQL: every change goes to an encrypted backup within 5 minutes. On the **Backups** tab, pick a moment of the last 7 days and click **Restore** to put the database back to it. Changes after that moment are gone.

- **Postgres** stays up while it restores, then stops for a few seconds to switch to the restored data. Changes made while it restores are gone too. Apps that use it may need a redeploy to reconnect.
- **MySQL** stays up while it restores, but apps may see errors until it is done.
- If backups stop working, the app's card and its **Backups** tab get a red dot, and we get an alert. The tab says what still works.
- dudbox also saves a dump of each Postgres and MySQL database every night.
- **Redis**: Redis writes every change to disk, and dudbox backs up its folder every night, encrypted. It has no **Backups** tab.

## Slow queries

Every database has a **Metrics** tab: its CPU, memory, disk and network over time. See [Metrics](/docs/metrics.md).

A Postgres database has an **Insights** tab: the slowest query over time, the errors in its log, and the queries that take 100 ms or more, with an index to add when one would help.

## API

Agents and scripts add a database like a one-click app: `POST /api/v1/services` with `"template": "postgres"`, `"mysql"` or `"redis"`. `GET /api/v1/templates` lists them with `"kind": "database"`. Read the password with `GET /api/v1/services/{project}/{service}/env/{key}`. See [Services](/docs/api/services.md) and [Env vars](/docs/api/env.md).
