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

> ## Agent Instructions
> Unkey is two separate products. Compute builds, deploys, and runs apps behind a gateway. API Management issues API keys, enforces rate limits, manages identities and permissions, and reports usage. Say which product a page belongs to; a reader can use either without the other.
> Every Unkey API endpoint is an HTTP POST to https://api.unkey.com/v2/{service}.{procedure} with a root key in the Authorization: Bearer header. Root keys are workspace scoped.
> Error codes have the form err:{system}:{category}:{specific} and each has a page at /errors/{system}/{category}/{specific}.
> The word environment means production or preview in Compute. Rate limiting has four meanings on this site; the glossary lists them.

# PlanetScale environment variables

> The variables Unkey sets for each connected PlanetScale database, and the read-only replica URL.

When you connect an environment, the dashboard suggests names based on the database name. A name that would start with a digit or with `UNKEY` gets a `DB_` prefix. For a database named `orders`:

| Variable | Engine | Value |
| - | - | - |
| `ORDERS_URL` | All | The read-write URL. On Postgres, it goes through PgBouncer on port 6432. On Neki, it connects directly on port 5432. |
| `ORDERS_UNPOOLED_URL` | Postgres only | The same credential, straight to the server on port 5432. Use it for clients that need session features PgBouncer doesn't support. |
| `ORDERS_READONLY_URL` | All, when turned on | A URL that reads from the branch's replicas. Its suggested name comes from the read-write name: `ORDERS_URL` becomes `ORDERS_READONLY_URL`. See [Read-only replica URL](#read-only-replica-url). |

Every URL verifies TLS: Postgres and Neki URLs use `sslmode=verify-full`, and Vitess URLs set `rejectUnauthorized`.

You can change the names before you save. A name must:

* follow the same rules as any [environment variable](https://www.unkey.com/docs/compute/configure/environment-variables.md#limits) key.
* not be `UNKEY` or start with `UNKEY_`. Those are [reserved for Unkey](https://www.unkey.com/docs/compute/configure/environment-variables.md#variables-unkey-injects).
* not end with `_HOST`. App connections use those names.
* not already be used in the environment, by one of your variables or by another connection.

## Read-only replica URL

Turn on the read-only URL to send reads to the branch's replicas. Each deployment then gets one more credential, with read access only. On Postgres and Neki, it connects directly on port 5432, not through PgBouncer.

To turn it on, open **Manage connection** for the database's connection to your app, from the app's **Connections** page or the database's page. In the environment's **Read-only URL** row, click **Add**. To turn it off, click **Remove**. Like connecting, this redeploys live production. Turning it off doesn't redeploy: running deployments keep the URL until they stop.

If production's branch has no replica the URL can reach, its row shows **Set up in PlanetScale** instead, which opens the branch in PlanetScale. You can turn it on only when the branch has a replica the URL can reach:

| Engine | Replicas the URL reaches |
| - | - |
| Vitess | HA replicas and read-only replicas |
| Postgres | HA replicas only. PlanetScale needs one host per read-only replica, which one URL can't cover |
| Neki | Read-only replicas when the branch has them, HA replicas otherwise |


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