Skip to content
pols.so docs
Esc
↑↓navigate↵open⌘Jpreview
On this page

pols db

Make and manage PostgreSQL databases

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

pols db [flags]
pols db [command]

Subcommands

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

Flags

-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

pols db backups DATABASE [flags]

Flags

-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

pols db duplicate DATABASE NAME [flags]

Examples

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

Flags

-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

pols db get DATABASE [flags]

Flags

-h, --help   help for get

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

pols db link DATABASE SITE [flags]

Examples

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

Flags

    --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

pols db ls [flags]

Flags

-h, --help   help for ls

pols db new

Make a database and wait until it is ready

Usage

pols db new NAME [flags]

Examples

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

Flags

-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

pols db restore BACKUP NAME [flags]

Examples

pols db backups writa
pols db restore dbb_k3f9a2b8c1d0 writa-restored

Flags

-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

pols db rm DATABASE [flags]

Flags

-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

pols db rotate DATABASE [flags]

Flags

-h, --help   help for rotate

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

pols db unlink SITE [flags]

Flags

-h, --help   help for unlink

The global flags work with this command too.