---
title: "pols db"
description: "Make and manage PostgreSQL databases"
---

<!-- Generated by scripts/reference.mjs from the pols CLI's --help. Do not edit; run `npm run reference:sync`. -->

A database is PostgreSQL 17 in a sandbox of its own, whose disk keeps the data
for as long as the database exists. It serves the database app, owned by the
role app, on port 5432 to the sandboxes pols lets in and no other: those of
the server apps linked to it (pols db link), which get its connection URL as
DATABASE\_URL from their next deploy on. It never goes to standby and is
billed as sandbox time; databases are for orgs that pay, not trial orgs.
Every night it is backed up (pols db backups); pols db restore makes a new
database from a backup, pols db duplicate one from a database as it is now.

## Usage

```text
pols db [flags]
pols db [command]
```

## Subcommands

| Command | Description |
| --- | --- |
| [`pols db backups`](#pols-db-backups) | List a database's backups |
| [`pols db duplicate`](#pols-db-duplicate) | Make a new database as a copy of a database now |
| [`pols db get`](#pols-db-get) | Show a database |
| [`pols db link`](#pols-db-link) | Give a site's server app the database's connection URL |
| [`pols db ls`](#pols-db-ls) | List the org's databases |
| [`pols db new`](#pols-db-new) | Make a database and wait until it is ready |
| [`pols db restore`](#pols-db-restore) | Make a new database from a backup |
| [`pols db rm`](#pols-db-rm) | Delete a database, its sandbox and all of its data |
| [`pols db rotate`](#pols-db-rotate) | Give a database a new password |
| [`pols db unlink`](#pols-db-unlink) | Shut a site's app out of its database |

## Flags

```text
-h, --help   help for db
```

## pols db backups

Lists a database's nightly backups, newest first. Each is a pg\_dump, encrypted
and read back once written; a weekly check restores one into a scratch
database. Backups are kept for 7 days, also after the database is deleted:
then name it by its ID (db\_...).

### Usage

```text
pols db backups DATABASE [flags]
```

### Flags

```text
-h, --help   help for backups
```

## pols db duplicate

Makes the database NAME as a copy of the ready DATABASE as it is now, and waits
until DATABASE's data is copied into it (pg\_dump into pg\_restore). DATABASE
stays as it is and serves meanwhile. The copy gets a password of its own and no
site; link it to one to use it. NAME is DATABASE's size unless `--size`; a size
whose disk is smaller than DATABASE's data is refused.

### Usage

```text
pols db duplicate DATABASE NAME [flags]
```

### Examples

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

### Flags

```text
-h, --help          help for duplicate
    --no-wait       return at once instead of waiting until it is ready
    --size string   micro, small, default or large (default: the source's size)
```

## pols db get

Show a database

### Usage

```text
pols db get DATABASE [flags]
```

### Flags

```text
-h, --help   help for get
```

## pols db link

Links SITE, a server app built from a repository, to DATABASE. From its next
deploy on, its install, build and app get the connection URL,
postgres://app:\<password\>@\<address\>:5432/app, as DATABASE\_URL (or `--as`), and
its app may connect to the database; no other sandbox may.

### Usage

```text
pols db link DATABASE SITE [flags]
```

### Examples

```sh
pols db link writa writa-app
pols db link writa writa-app --as POLS_DATABASE_URL
pols deploys start writa-app
```

### Flags

```text
    --as string   the environment variable to get the URL as (default DATABASE_URL)
-h, --help        help for link
```

## pols db ls

List the org's databases

### Usage

```text
pols db ls [flags]
```

### Flags

```text
-h, --help   help for ls
```

## pols db new

Make a database and wait until it is ready

### Usage

```text
pols db new NAME [flags]
```

### Examples

```sh
pols db new writa
pols db new big --size small
```

### Flags

```text
-h, --help          help for new
    --no-wait       return at once instead of waiting until it is ready
    --size string   micro (1 vCPU, 1 GiB, 10 GiB disk; the default), small, default or large
```

## pols db restore

Makes the database NAME from BACKUP (an ID from pols db backups), also one of a
deleted database, and waits until the backup is restored into it. The
database a backup is of stays as it is; link the new one to a site to use it.

### Usage

```text
pols db restore BACKUP NAME [flags]
```

### Examples

```sh
pols db backups writa
pols db restore dbb_k3f9a2b8c1d0 writa-restored
```

### Flags

```text
-h, --help          help for restore
    --no-wait       return at once instead of waiting until it is ready
    --size string   micro (the default), small, default or large
```

## pols db rm

Delete a database, its sandbox and all of its data

### Usage

```text
pols db rm DATABASE [flags]
```

### Flags

```text
-h, --help   help for rm
```

## pols db rotate

Gives the database's role app a new password, which PostgreSQL takes at once
(it restarts, a few seconds), then restarts the live apps of the sites linked
to it with the new URL. The old password stops working.

### Usage

```text
pols db rotate DATABASE [flags]
```

### Flags

```text
-h, --help   help for rotate
```

## pols db unlink

Unlinks SITE from its database: its sandboxes may no longer connect, at once,
and its next deploy gets no URL. A stopped earlier version of its app still
holds the password; pols db rotate gives the database a new one.

### Usage

```text
pols db unlink SITE [flags]
```

### Flags

```text
-h, --help   help for unlink
```

The [global flags](/docs/reference/cli/#global-flags) work with this command too.
