Databases
A Postgres database that the app receives without any setup.
Dedicated databases
A dedicated database is a Postgres instance of its own, used by one app. It needs the Pro plan.
| Size | Memory | Storage | Price a month |
|---|---|---|---|
small | 1 GB | 20 GB | $13 |
medium | 2 GB | 20 GB | $24 |
large | 4 GB | 40 GB | $48 |
$ shim db create --dedicated small $ shim db status
Creating one takes several minutes. You can press Ctrl-C while it waits; creation carries on. You can also create it from the Database section of the app in the dashboard, or with the database key in shim.toml.
Starter databases
A starter database is free and ready in about a minute. It is a small Postgres database that sleeps when unused, so the first query after a quiet spell is slower. The app reaches it over the internet with TLS and a password, not over the private network that dedicated databases use. Anyone who learns the connection string can connect from anywhere, so keep sensitive data in a dedicated database.
$ shim db createAn app has at most one database.
The connection strings are automatic
The app receives two variables, DATABASE_URL and DATABASE_URL_UNPOOLED. The app needs nothing copied. To connect from your own machine, see Connecting from your machine.
Shim sets both as secrets. They cannot be set, changed or removed while the database exists, and they are gone when the database is deleted.
If the app already has a variable of its own with either name, remove it before you create the database, for example with shim env unset DATABASE_URL_UNPOOLED.
Pooled and direct connections
On a starter database, DATABASE_URL goes through a connection pooler (PgBouncer in transaction mode) that accepts up to 10,000 client connections. DATABASE_URL_UNPOOLED connects to Postgres directly. Every running copy of the app holds its own connections, and a starter database allows only about 100 direct connections, so use DATABASE_URL for normal queries.
In transaction mode, each transaction can run on a different Postgres connection. These do not work through DATABASE_URL:
- Session-level
SETandRESET, for exampleSET search_path. UseSET LOCALinside a transaction instead. LISTENandNOTIFY.- SQL-level
PREPAREandDEALLOCATE. Prepared statements that the driver makes do work. - Session-level advisory locks.
WITH HOLDcursors.- Temporary tables that outlive a transaction.
LOAD.
Statements that cannot run inside a transaction block, such as CREATE INDEX CONCURRENTLY, also need DATABASE_URL_UNPOOLED.
Use DATABASE_URL_UNPOOLED for schema migrations, for anything in the list above, and for long sessions. Migration tools commonly take advisory locks, so run migrations with DATABASE_URL_UNPOOLED. Keep the direct connection short-lived: open it, migrate, close it. Do not use it to handle requests.
A dedicated database has no pooler. DATABASE_URL and DATABASE_URL_UNPOOLED hold the same connection string, so the same app code works with either kind of database.
An app whose starter database was created before pooling was added switches to the pooled DATABASE_URL the next time it is deployed or its variables change.
Connecting from your machine
With a starter database, the owner of the app can open a session or run a script from a laptop. shim db psql starts psql on the direct connection. The password is handed to psql through its environment, so it does not appear in the process list or in your shell history. Anything after -- goes to psql.
$ shim db psql $ shim db psql -- -c "select count(*) from users" $ shim db psql < seed.sql
shim db url prints the direct connection string, for tools that need one. It is the same string the app receives as DATABASE_URL_UNPOOLED. Treat it like a password: prefer passing it straight into a command over pasting it, and rotate it if it ends up somewhere it should not be.
$ DATABASE_URL="$(shim db url)" npx prisma migrate deployThe Database section of the dashboard has a Reveal connection string button that does the same. The string is shown for one minute and is not kept after that.
Only the owner of the app can do this, signed in to the dashboard or the CLI. Every reveal is recorded with who asked and when, never with the value, and reveals are limited to 30 an hour for each app. The connection string cannot be read while the password is being rotated or the database is being restored.
A dedicated database is private
A dedicated database sits in the app's private network. It cannot be reached from the internet or from your laptop, so shim db url, shim db psql and shim db dump refuse it and say why. Connecting from outside would need a tunnel into that network, which Shim does not offer yet. Only the app can connect, so run migrations and one-off scripts from the app itself.
Migrations
Run schema migrations on the direct connection, DATABASE_URL_UNPOOLED. Migration tools take session-level advisory locks and run statements that the pooler does not support. There are two ways to do it:
- When the app starts: have the start command migrate with
DATABASE_URL_UNPOOLEDand then serve requests. This works with both kinds of database and is the only way with a dedicated one. - From your machine or CI, with a starter database:
DATABASE_URL="$(shim db url)" <your migration command>.
Several copies of an app can start at once. Use a migration tool that takes a lock, which most do, so that only one copy migrates.
Rotating the password
$ shim db rotateRotating replaces the database password, stores the new connection strings, and restarts the app on them. You do not redeploy or change anything. The command waits and reports when the app is running on the new password; the Rotate password button in the dashboard does the same.
The old password stops working, so anything outside the app that still holds an old connection string must fetch a new one. Expect a few seconds of failed queries while the app restarts. With a dedicated database the change takes a minute or two.
Rotation is refused while a deploy is releasing, and only one database operation runs at a time. If it is interrupted, Shim carries on from where it stopped. It is limited to 5 an hour for each app.
Backups and restore
Your own backups
$ shim db dump > backup.sql $ shim db dump -- --format=custom --file=backup.dump
shim db dump runs pg_dump on your machine against a starter database, on the direct connection. It refuses to write a backup to the terminal. pg_dump cannot dump a server newer than itself, so the command checks your version first and tells you which PostgreSQL client tools to install. Anything after -- goes to pg_dump. Load a plain SQL backup with shim db psql < backup.sql.
A starter database keeps only a few hours of history, so a regular dump is the only backup that reaches further back.
Restore a starter database to a time
$ shim db restore --to 2h $ shim db restore --to 2026-12-01T09:30:00Z
A starter database can be put back to how it was at any moment in the last 6 hours, as long as that is after it was created. --to takes a time with a zone, or how long ago: 45m or 2h. The command names the app and the time and asks you to confirm; the dashboard has the same under Restore to a time.
Everything written after that moment is lost. Open connections are cut, the password is replaced, and the app restarts on the new connection strings by itself. Shim keeps the state from just before the latest restore as a safety copy, and replaces it at the next restore. That copy counts toward the storage limit. Restores are limited to 3 an hour for each app.
Dedicated databases
Amazon RDS backs a dedicated database up automatically and keeps 7 days of history, so it can be brought back to any minute in that window. shim db status and the dashboard show the latest moment it can be restored to. Restoring is not self-serve yet: a restore creates a new instance and the app has to be moved onto it, so contact support with the time you need. The backups are deleted together with the database.
Usage and limits
shim db status and the Database section of the dashboard show the Postgres version, the region, whether the compute is running, how much storage is used, and how close the database is to its limits. The numbers are measured every hour and again when you look, so they can be a few minutes old.
| Starter database | Limit | At the limit |
|---|---|---|
| Storage | 1 GB | Writes fail, deletes included, until you free space by dropping or truncating tables. Reads and dumps keep working. No data is deleted. |
| Compute | 100 compute hours a month at 0.25 CPU | The database is suspended and connections fail until the monthly period resets. |
| Connections | 10,000 through DATABASE_URL, about 100 direct | New connections are refused. |
| History for restore | 6 hours | Older moments cannot be restored. |
A starter database is suspended after 5 minutes without connections and wakes on the next one. Time spent suspended does not use compute hours. Shim warns in the dashboard and in shim db status from 80% of the storage or compute limit.
A dedicated database has the storage of its size, runs all the time, and has no compute limit. Shim shows its storage, CPU and open connections. A full disk stops the database, so delete data before it fills, or move to a larger size.
Node and the database certificate
A starter database uses a publicly trusted certificate (Let's Encrypt). The connection string works as it is, and node-postgres checks the certificate with no extra setup. Drivers built on libpq check it only when you change sslmode to verify-full.
A dedicated database presents a certificate signed by Amazon's RDS certificate authority. Node does not trust that authority by default, so node-postgres rejects the connection. Add Amazon's certificate bundle to the image and tell Node to trust it:
ADD https://truststore.pki.rds.amazonaws.com/global/global-bundle.pem /etc/ssl/rds-global-bundle.pem RUN chmod 644 /etc/ssl/rds-global-bundle.pem ENV NODE_EXTRA_CA_CERTS=/etc/ssl/rds-global-bundle.pem
With these lines in the Dockerfile, node-postgres checks the certificate with no ssl option:
const { Pool } = require("pg");
const pool = new Pool({ connectionString: process.env.DATABASE_URL });In other languages, point the Postgres driver's root certificate setting at the same file. For drivers built on libpq, that setting is sslrootcert.
Deleting destroys the data
$ shim db deleteThe command asks you to type the app's name. All data in the database is destroyed and cannot be recovered. To change the size, delete the database and create a new one; the data does not carry over.
Deleting the app's entry from shim.toml does not delete the database.