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

# Databases

> Connect your PostgreSQL, MySQL or Redshift databases, or create shared organization databases

Vybe works with two kinds of databases. **External databases** are yours: connect them so AI coworkers and apps can query live data without copying it. **Organization databases** are shared Postgres databases that Vybe hosts for your organization, for tables your coworkers and apps build up over time.

| | External databases | Organization databases |
| - | - | - |
| Where the data lives | Your own server | Vybe |
| Engines | PostgreSQL, MySQL, Amazon Redshift | PostgreSQL |
| Set up with | A database URL, optionally through an SSH tunnel | A name |
| Coworker access | Off until you approve each database | On by default |
| Read-only option | **Enforce Read Only**, on by default | Per coworker, with the **Read only** level |

Each app also has its own database. See [Data](https://docs.vybe.build/apps/data.md).

## External databases

| Database | Connection | Enforce Read Only | SSH tunnel |
| - | - | - | - |
| **PostgreSQL** | Database URL | Yes | Yes |
| **MySQL** | Database URL | Yes | Yes |
| **Amazon Redshift** | AWS IAM role, set up with support | No | No |

### Connect a database

**1. Open the form**

Go to **Connections** in the sidebar, open the **Advanced** tab and click **Connect database** under **External Databases**. You can also use **Settings → Data → Databases**. The **Connect External Database** dialog opens.

**2. Choose the type and name**

Pick the **Database Type** and give the connection a **Name**, such as "Production Database". Coworkers and apps refer to the database by this name.

**3. Enter the database URL**

Paste a **Database URL** in the form `postgresql://username:password@host/database` or `mysql://username:password@host/database`.

**4. Keep read-only on**

**Enforce Read Only** is on by default: "If enabled, each query will be executed in a read only transaction." Leave it on unless coworkers and apps really need to write to this database.

**5. Add an SSH tunnel if needed**

If the database is behind a firewall or in a private network, open **SSH Tunnel (Optional)**. See [SSH tunnels](#ssh-tunnels).

**6. Connect**

Click **Connect database**. Vybe tests the connection first, through the tunnel if you set one, and only saves it if the test works.

The dialog reminds you that "This database connection will apply to your whole organization." and to "Make sure that your database permissions are set up properly." Connect with a database user that only has the permissions you want Vybe to have, for example `SELECT` on the schemas your team needs.

> [!WARNING]
>
> You can't edit a database connection after you create it. To change the URL, the read-only setting or the tunnel, delete the connection and connect it again. Deleting a connection also deletes the [data queries](https://docs.vybe.build/connections/data-queries.md) that use it, and coworkers need access to the new connection.

### Read-only enforcement

With **Enforce Read Only** on, Vybe runs every query in a read-only transaction. `SELECT` queries work. `INSERT`, `UPDATE`, `DELETE` and schema changes fail, even if a coworker or an app tries them. This applies to every query through that connection.

Connections with read-only on show a **Read-only enforced** badge in the list. Connections that use a tunnel show **Secure Tunnel**.

### Amazon Redshift

"Redshift database connections currently require custom configurations. Please reach out to our support team if you would like to use Redshift in your apps." Contact [support@vybe.build](mailto:support@vybe.build) before you set one up.

The Redshift form asks for an **AWS Region**, a **Role ARN** that Vybe assumes, an optional **External ID**, a **Cluster ID** (provisioned clusters) or **Workgroup Name** (serverless), a **Database Name** and an optional **Database User**. Redshift connections have no **Enforce Read Only** and no SSH tunnel, so limit what the IAM role can do.

### Explore a database

Click a database in the list to browse its tables ("Exploring data from *name*").

## SSH tunnels

Use an SSH tunnel for a PostgreSQL or MySQL database that isn't reachable from the internet. Vybe connects to an SSH server you control, such as a bastion host, and reaches the database through it.

In the **SSH Tunnel (Optional)** section of the connect dialog:

* **Tunnel Connection URL**: the SSH server, such as `ssh://username@bastion-host:22`. You can put a password in the URL (`ssh://username:password@bastion-host:22`). URL-encode special characters.
* **Tunnel SSH Key (Optional)**: an SSH key that Vybe generated. Recommended instead of a password.

### SSH keys

Vybe generates SSH keys for you. You never upload a private key.

**1. Create a key**

Go to **Settings → Data → Databases**. Under **SSH Keys**, click **Create SSH Key**, give it a **Name** and click **Create SSH Key**. Vybe generates an Ed25519 key pair and stores the private key encrypted.

**2. Install the public key**

Click **Copy Public Key (SSH format for authorized\_keys)** and add it to `~/.ssh/authorized_keys` for the tunnel user on your SSH server. **Download Public Key (raw)** saves the key as a file instead.

**3. Use the key**

When you connect a database, enter the **Tunnel Connection URL** and pick the key under **Tunnel SSH Key (Optional)**.

SSH keys are shared across your organization, and you can use one key for several databases.

> [!NOTE]
>
> The **SSH Keys** section only appears on **Settings → Data → Databases** once your organization has at least one PostgreSQL or MySQL external database.

## How coworkers use external databases

An AI coworker needs two things to query an external database:

1. The **External Databases** capability turned on. It's on by default. You'll find it on the **Advanced** tab of the coworker's **Connections** section.
2. Access to that specific database. Each database is off for each coworker until you approve it. When a coworker needs a database, it asks for access in chat. Approve the request.

Then ask in plain language:

> How many orders were placed last month? Use the Production Database.

> Show me the top 10 customers by revenue from the analytics database.

The coworker writes the SQL, runs it ("Ran SQL query") and shows the results. Queries a coworker runs in chat time out after 10 seconds.

If no database is connected yet, the coworker can show a **Connect external database** card so you can connect one without leaving the chat.

Artifacts that a coworker publishes can show live data from PostgreSQL and MySQL databases that have **Enforce Read Only** on. Artifact queries return at most 1,000 rows and time out after 10 seconds. See [Artifacts](https://docs.vybe.build/coworkers/artifacts.md).

## How apps use external databases

Apps query external databases from their server code. The AI in the app editor writes the queries, using helpers such as `queryExternalDatabasePostgres`, `queryExternalDatabaseMySQL` and `queryExternalDatabaseRedshift`, and refers to the database by its name. The AI can also run SQL against the database while it builds, to check the data. See [Data](https://docs.vybe.build/apps/data.md).

## Organization databases

An organization database is a shared, managed Postgres database for your organization. Coworkers and apps can create tables in it, write to it and read from it.

### Create one

Go to **Connections** in the sidebar, open the **Advanced** tab and click **Create database** under **Organization Databases**. You can also use **Settings → Data → Databases**. In **Create organization database**, enter a **Name** (up to 80 characters, unique in your organization) and an optional **Description** (up to 500 characters), then click **Create**.

A coworker can also create one for you:

> Create an organization database called "Customer feedback" and add a table for survey responses.

You'll see "Created organization database "*name*"". A new database has no tables until a coworker or an app creates them.

### Browse and delete

Click a database to browse its tables. To delete one, click the trash icon (**Delete database**) next to it and confirm "Delete organization database?". This permanently deletes the database and its data.

### Coworker access

Every coworker's **Organization Databases** capability is on, at **Full access**, by default. Set it to **Read only** to block writes, or turn it off, on the **Advanced** tab of the coworker's **Connections** section. Queries appear in chat as "Queried "*name*"".

### Limits

Queries from coworkers and apps time out after 10 seconds. A query that returns more than 1,000 rows fails, so use `LIMIT`, filters or aggregates.

## Troubleshooting

> **The connection test fails or times out**
>
> Check the host, port, database name and credentials in the URL. Make sure the database accepts connections from outside your network. If it's behind a firewall or in a private network, use an [SSH tunnel](#ssh-tunnels). For questions about network access, contact [support@vybe.build](mailto:support@vybe.build).

> **The SSH tunnel fails**
>
> Check that the public key is in the tunnel user's `authorized_keys` file, and that the SSH host, port and username in the **Tunnel Connection URL** are right. Make sure the SSH server allows port forwarding (`AllowTcpForwarding` in its SSH config).

> **Queries fail with permission denied**
>
> The database user in the URL can't read those tables. Grant it `SELECT` on the schemas and tables you need.

> **Writes fail on an external database**
>
> **Enforce Read Only** is on, so writes are blocked. If you really want writes, delete the connection and connect it again with **Enforce Read Only** off.

> **The coworker can't query a database**
>
> The coworker needs access to that database, and its **External Databases** capability must be on. Ask it to request access, then approve the request.

> **An organization database query returns too many rows**
>
> Results are capped at 1,000 rows. Ask for a summary, add a `LIMIT`, or filter the query.


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