> ## Documentation Index
> Fetch the complete documentation index at: https://docs.beam.cloud/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> Install the Beam CLI, sign in, and connect coding agents to the Beam MCP server with `curl -fsSL https://www.beam.cloud/install | sh`. To also create a VM, run `curl -fsSL https://www.beam.cloud/install | sh -s -- --vm`.
> VMs are persistent Linux machines without GPUs. Defaults: 4 CPUs, 8 GiB of RAM, a 50 GiB disk, Ubuntu 24.04, and a browser desktop. A running VM accrues usage until you stop, pause, or remove it, or until an idle timeout puts it to sleep.
> Stopping a VM keeps its disk and discards RAM and processes. Pausing keeps both, and resuming restores them. To pause after 5 idle minutes and wake on access, run `beam vm update NAME --ttl 300 --idle-action pause --auto-resume`.
> Core VM commands: `beam vm new NAME`, `beam vm ssh NAME`, `beam vm sync NAME ./dir`, `beam vm exec NAME -- CMD`, `beam vm expose NAME PORT --protected`, `beam vm fork NAME NEW_NAME`, `beam vm pause NAME`, `beam vm stop NAME`, `beam vm rm NAME`.
> For GPUs, use a sandbox or a deployed endpoint. Sandboxes are disposable environments that boot in seconds and fork from snapshots.
> Current rates are at https://www.beam.cloud/pricing.

# Managed Databases

> Create Postgres, Redis, MySQL, and MongoDB services and connect your apps

You can run Postgres, Redis, MySQL, or MongoDB on Beam. Each database includes a durable disk, generated credentials, and a TLS connection.

| CLI kind | Engine | Default disk | Connection variable |
| - | - | - | - |
| `postgres` | Postgres 16 | 10Gi | `DATABASE_URL` |
| `redis` | Redis 7 | 5Gi | `REDIS_URL` |
| `mysql` | MySQL 8 | 10Gi | `DATABASE_URL` |
| `mongo` | MongoDB 7 | 10Gi | `DATABASE_URL` |

## Create a Database

```bash theme={null}
beam db postgres create web-db
beam db redis create cache
beam db mysql create analytics-db
beam db mongo create documents-db
beam db list
```

Each command creates a separate database with 1 CPU and 512 MB of memory. Names must be unique in your workspace. Use `--cpu`, `--memory`, `--database`, or `--username` to customize it.

To supply a password, use `--password-from-env VARIABLE_NAME` or `--password-stdin`.

Databases are also available in the dashboard and through MCP's `create_database` tool.

## Connect an App

Pass the database URL as an [environment reference](https://docs.beam.cloud/v2/hosting/references.md):

```bash theme={null}
beam deploy --dockerfile Dockerfile --name web --port 8000 \
  --env DATABASE_URL='${{db.web-db.DATABASE_URL}}' \
  --env REDIS_URL='${{db.cache.REDIS_URL}}'
```

Python apps accept the same references in `env`:

```python theme={null}
from beam import function

@function(env={"DATABASE_URL": "${{db.web-db.DATABASE_URL}}"})
def inspect_configuration():
    import os
    return {"database_configured": bool(os.environ.get("DATABASE_URL"))}
```

For an existing app, edit its environment variables in the dashboard or use MCP's `connect_services`. Both deploy a new version.

## Connect from Your Machine

Print a connection command for Postgres or Redis:

```bash theme={null}
beam db postgres connect web-db --psql
beam db redis connect cache --redis-cli
```

Run the printed command with `psql` or `redis-cli` installed. The output contains credentials.

For other clients, use `beam db KIND credentials NAME`. Redis also supports `connect --node-redis` and `--ioredis` for TLS connection examples.

## Serverless or Always On

Databases shut down after 300 idle seconds by default. To avoid cold starts, keep one replica running:

```bash theme={null}
beam db postgres scale web-db --always-on
beam db postgres scale web-db --serverless
beam db postgres scale web-db --cpu 2 --memory 2Gi
```

Use `--min-replicas 1` at creation for always-on mode. Each database has one writable replica; clients should reconnect after restarts or resource changes.

## Credentials and Lifecycle

```bash theme={null}
beam db postgres status web-db
beam logs web-db --since 30m
beam db postgres rotate web-db
```

Rotation restarts the database and apps using its generated secrets. Update any connection strings you copied manually.

`beam db postgres delete web-db` deletes the service and credentials, but **keeps the durable disk**. Use `beam disk list` to find it. See [disk snapshots](https://docs.beam.cloud/v2/data/durable-disks.md#snapshots) for backups.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.