---
title: Databases
description: Give a server app built from GitHub a PostgreSQL 17 database that keeps its data across deploys, with nightly backups, restores, duplicates and password rotation.
---

A database is PostgreSQL 17 in a sandbox of its own, whose disk keeps the data for as long as the database exists. It is made for [server apps built from GitHub](/docs/publish/github/#server-apps): each deploy of a server app gets a new sandbox, and the database is where its data lives across deploys.

```sh
pols db new writa                       # make it and wait until it is ready
pols db link writa writa-app            # give the site's app its connection URL
pols deploys start writa-app            # the next deploy gets DATABASE_URL
pols db ls
pols db backups writa
```

The same is on the Databases page of the [account pages](https://my.pols.so/account), in the [MCP server](/docs/agents/mcp/) (`database_*` tools) and in the TypeScript and [Python](/docs/agents/python/) clients' `databases`.

![The Databases page of the account pages with no databases yet, and the form to make one with a name and a size.](/docs/blume-assets/content/docs/images/databases.png)
![The Databases page of the account pages with no databases yet, and the form to make one with a name and a size. Dark theme.](/docs/blume-assets/content/docs/images/databases-dark.png)

The Databases page of the account pages.

## Making one

`pols db new NAME` (`POST /v1/databases` with `name`) makes the database and waits until it is ready. Over the API it answers at once with status `provisioning`; poll `GET /v1/databases/{database}` until it is `ready`, with its PostgreSQL `version`, or `failed`, with `error` saying why (delete a failed one and make another). The name is lowercase letters, digits and dashes, starting with a letter, at most 63 characters, and unique among your org's databases.

Each database has one database, `app`, owned by the role `app`, which is not a superuser, with a long random password. It listens on port 5432.

| Size | |
| --- | --- |
| `micro` | 1 vCPU, 1 GiB RAM, 10 GiB disk; the default, for databases only |
| `small`, `default`, `large` | as for [sandboxes](/docs/concepts/machine/#sizes) |

Pass `--size` (`size`) to choose one.

## Who can connect

A database serves only the app sandboxes of the sites linked to it: their live version, their kept versions and their running deploys. Every other sandbox, of your org or any other, cannot reach it, and it has no public address. There is no way to connect to it from your own machine or from an ordinary sandbox.

### Linking a site

`pols db link DATABASE SITE` (`PUT /v1/sites/{site}/database` with `database`) links a [server app](/docs/publish/github/#server-apps) built from a repository to a ready database of your org. A site has one database; a database can serve several sites. From the site's next deploy on, its install and build commands (so migrations can run there) and the app itself get the connection URL as `DATABASE_URL`:

```text
postgres://app:<password>@<address>:5432/app
```

- `--as NAME` (`env`) gives it under another name, such as `POLS_DATABASE_URL`, while the app still has a `DATABASE_URL` of its own. A variable the site's build variables or vault entries already set is refused.
- The URL has no `sslmode`: the traffic never leaves the host.
- The URL is never in the sandbox's environment, and the password is redacted from the deploy and app logs.
- A deploy whose database is not ready or not running fails and says so.

`pols db unlink SITE` (`DELETE /v1/sites/{site}/database`) shuts the site's sandboxes out at once, and its next deploy gets no URL. Disconnecting the site's repository does the same. A stopped earlier version of the app still holds the password: [rotate](#a-new-password) it if that matters.

## A new password

`pols db rotate DATABASE` (`POST /v1/databases/{database}/password`) gives the role `app` a new random password. PostgreSQL restarts to take it, which takes a few seconds, and the old password stops working. pols then rewrites the configuration of each linked site's live app with the new URL and restarts it. Deploys and restores that are in progress are coordinated with it, so no app goes live with an old password.

## Backups and restores

Every night, at a time of its own between 02:30 and 05:30 UTC, pols dumps each ready database (`pg_dump`), encrypts the dump and reads it back to check it. A backup that failed is tried again an hour later. Once a week, a database's new backup is restored into a scratch database and every table checked.

- `pols db backups DATABASE` (`GET /v1/databases/{database}/backups`) lists them, newest first, with their status (`running`, `verified` or `failed`), size, number of tables, and when the weekly check last restored one.
- Backups are kept for 7 days, also after the database is deleted: then name the database by its ID (`db_...`).
- `pols db restore BACKUP NAME` (`POST /v1/databases` with `name` and `from_backup`) makes a new database from a verified backup and waits until the backup is restored into it. The database the backup was taken of stays as it is: link the new one to a site to use it.

Backups are not billed.

## Duplicating one

`pols db duplicate DATABASE NAME` (`POST /v1/databases/{database}/duplicate` with `name`; on the account page, **Duplicate…** in a ready database's actions menu) makes a new database and copies the source's data into it as it is now, then waits until the copy is done. Use it for a staging copy or to try a migration on real data.

```sh
pols db duplicate writa writa-staging
pols db duplicate writa writa-big --size small
```

- The source must be `ready` and keeps serving its sites during the copy; the copy is consistent as of the moment it starts.
- The new database is made as `pols db new` makes one (the same [limits](#limits) and billing) and is of the source's size unless `--size` (`size`) says otherwise. A size whose disk is smaller than the source's data answers `409 conflict`.
- Its role `app` gets a new password of its own, never the source's, and no site is linked to it: [link](#linking-a-site) it to use it.
- Over the API it answers at once with status `provisioning` and `duplicated_from` naming the source (`db_...`); it turns `ready` once the data is copied, or `failed` with `error` saying why. `--no-wait` makes the CLI return at once too.

## Deleting one

`pols db rm DATABASE` (`DELETE /v1/databases/{database}`; on the account page by typing its name) deletes the database at once, with its sandbox, its disk and all of its data, and frees its name. Its backups stay for their 7 days. A database that sites are linked to answers `409 conflict` until you unlink them.

## How it runs and what it costs

- The database's sandbox is listed among your org's sandboxes with purpose `database`. It never goes to [standby](/docs/sandboxes/lifecycle/#standby), has no time to live, and cannot be deleted, forked or resized on its own (`409 conflict`), nor take [checkpoints](/docs/sandboxes/checkpoints/): manage it through the database.
- If its sandbox was stopped, for example for want of credit, pols starts it again within about 10 minutes once it can.
- It is billed as sandbox time: its size's RAM all the time, busy CPU, and its disk, whose whole size is reserved for it. It does not count against your sandbox [quotas](/docs/getting-started/limits/#quotas).
- PostgreSQL's minor updates come with new images for new databases.

## Limits

- Databases are for orgs that pay: a trial org gets `403 trial_limit`.
- An org may have up to 5 databases (`403 quota_exceeded`).
- Making one needs credit (`402 insufficient_credit`).
