Postgres
A PostgreSQL 16 database on one of your project's machines, with optional backups and a standby.
A Postgres database runs PostgreSQL 16 on one of your project's machines. Use it for your app's relational data. Your services reach it over the project's private network. You can reach it from your own computer over private access, and open it to chosen IP addresses outside Appentic.
Backups are an optional add-on. With them on, the database is backed up off its machine and can be restored to any point in the last 7 days. See Backups.
Create a database
- On the project's Services page, click Add next to Databases.
- Fill in the form:
- Database name
- Machine: which of the project's machines it runs on, when the project has more than one. See Machines.
- Memory: see Size.
- Public access: leave it off unless you need to connect from outside Appentic. See Public access.
- Connect: the web services, workers and cron jobs that should get
DATABASE_URL. Shown when the project has any.
- Click Create database.
The form shows the monthly fee under Price. The database's Overview shows Running when it is ready.
Connect your services
Connecting a service adds a DATABASE_URL variable to it with the full connection string. Your code reads it like any other environment variable.
- When you create the database, pick services under Connect. They get the variable once the database is ready, and redeploy to pick it up.
- Later, open the database's Settings, choose services under Connect to your services, and click Update and redeploy. Turning a service off removes the variable and redeploys it.
- When you create a web service, you can pick the database under Connect database.
DATABASE_URL appears on the project's Environment page as a managed variable, with the database under Managed by. You can reveal it there, but you change it only by connecting or disconnecting services. See Managed variables.
Connection details
Once the database is running, its Overview shows:
- Connection details: Host, Port, Database, Username and Password. Click the eye icon to show the password.
- Connection strings: Internal (Appentic services), and External (allowed IP addresses only) while public access is on.
The internal address works from every service in the project, on any of its machines and in any zone. To connect from your own computer, use private access.
Size
The Memory slider sets the database's share of its machine. The rest follows from it:
| Resource | What the database gets |
|---|---|
| CPU | The same share of the machine's CPU, guaranteed. Idle CPU on the machine is shared. |
| Storage | The same share of the machine's usable disk. This is its storage allowance. On a volume, the volume sets its storage instead. |
| Connections | 25 per 512 MB of memory, at least 20 and at most 300. |
PostgreSQL's memory settings are tuned for the size you choose.
To change the size, open Settings, move the slider under Scaling and click Update and redeploy. The database restarts briefly. You can't make it smaller if its data would fill 90% or more of the smaller storage allowance.
See Memory and sizing.
Storage
The Overview shows Storage as how much of its allowance the database uses. Appentic measures it every 5 minutes.
| Usage | What happens |
|---|---|
| 90% | The database's Events page records a warning, and you get a notification if Usage alerts is on in Notifications. |
| 100% | The database becomes Read-only. It still accepts connections and reads, but refuses writes. |
| Below 90% again | It accepts writes again by itself. |
To get out of read-only, do one of these:
- Give it more storage. Increase its memory in Settings. Its allowance grows with it.
- Add a volume. A volume gives it storage of its own, beyond the machine's disk. If it's on a volume already, grow the volume.
- Free space. Connect, run
SET default_transaction_read_only = off;on its own first, then in the same session drop orTRUNCATEtables you don't need. Deleting rows alone doesn't give the disk space back.
Backups
Backups are off when you create a database. To turn them on, open Settings and switch on Keep this database backed up under Backups. The switch shows the monthly fee. It is billed by the second, on top of the database's own fee.
With backups on:
- Changes are saved continuously to backup storage off the machine as they are written. You can restore to any moment, not only to the last full backup.
- A full backup runs daily, at a fixed time between 03:00 and 04:00 UTC.
- Backups are kept for 7 days. Older ones are removed.
The first full backup starts shortly after you turn backups on and the database is running.
Backups are kept in EU-1, including for projects in other regions.
Backups are encrypted with a key that belongs to this database alone. No other database, and nothing else in Appentic's backup storage, can read them.
Turning the switch off stops new backups and the fee. What was already backed up stays restorable for 7 days, then it is removed. If you turn backups back on within those 7 days, the earlier backups are kept. Changes made while backups were off aren't backed up.
The Backups tab
The database's Backups tab shows:
- Automatic backups: On, Off, Turning on or Turning off
- Schedule, Last successful backup and Earliest restore point
- Full backups: each one, with when it started and finished
Click Back up now to start a full backup straight away, for example before a risky migration. The tab updates when it finishes.
If changes stop reaching the backups, the tab says so and you get a notification. Earlier backups are unaffected.
Restore to a new database
A restore creates a new database in the same project from the backups. The original keeps running, unchanged.
- Open the database's Backups tab.
- Under Restore to a new database, enter a New database name.
- Under Restore to, choose The latest point, or A point in time and a date and time in UTC. You can choose any time from the earliest restore point until 5 minutes ago.
- Click Restore.
The new database appears on the project's Services page and is usually ready within a few minutes. It runs on the original's machine, with the same memory, so that machine needs room for it. It has its own password, isn't connected to any service, and starts without backups of its own.
Check its data, then connect your services to it from its Settings, and delete the old database if you no longer need it. A restored database is billed like any other.
After a database is deleted
A deleted database can't be restored, even from its backups. To keep a copy you control, restore it to a new database before you delete it.
Its backups are erased 7 days after it's deleted, and the key they're encrypted with is destroyed with them. After that, nothing of the database can be read again.
Your own copies
To keep copies outside Appentic, or for longer than 7 days, run pg_dump from a cron job and upload the file to a storage bucket or anywhere else.
Public access
To connect from your own computer, use private access where you can. The database then stays off the internet. Public access is for something you can't put on private access, such as a reporting tool hosted elsewhere.
With Public access on, the database accepts connections from outside Appentic:
- only from the addresses on its own Who can connect list
- only over TLS (
sslmode=require) - at its own public hostname, on port
5432
Each database has its own list, so two databases in a project can allow different addresses.
To set it up:
- Open the database's Settings.
- Under Public access, turn on Public access.
- Under Who can connect, click Add address. Enter a label, such as
Office, and an address. It can be a single address, like203.0.113.7, or a range, like203.0.113.0/24. - Click Save addresses.
If an entry isn't a valid address, nothing is saved and the entry is marked so you can fix it. To remove an address, click the × next to it, then click Save addresses. Changes apply within a minute.
Keep in mind:
- With no addresses on the list, nothing outside Appentic can connect, even with public access on.
0.0.0.0/0allows every address on the internet. Avoid it.- Your Appentic services always use the private network, so the list doesn't affect them.
The Overview shows the Public hostname and the External connection string while public access is on.
Rename
In Settings, under General, change the Database name and click Update. Only the name shown in the dashboard changes. The connection details stay the same.
Restart
In Settings, under Restart, click Restart database. Open connections drop for a few seconds.
Standby
A standby is a copy of the database on another machine in the same zone, kept up to date as changes happen. If the database's machine goes down, the copy takes over and your services keep connecting to the same address. There's no fee for a standby. It uses the same memory and disk on its machine as the database does on its own.
The project needs a second machine in the database's zone. Then:
- Open the database's Settings.
- Under Standby, pick a Machine.
- Click Add standby.
The standby holds the same memory and disk on its machine as the database, so that machine needs room for it. A machine that can't hold it is listed with the reason.
Once it is running, Standby shows where it is, for example On machine-2 · EU-2. When the standby takes over, the database's Events page says so and you get a notification. The database then runs on the standby's machine, and keeps its standby on the old machine once that machine is back. Its public hostname, if it has one, follows it.
With a standby on a running machine, the database keeps serving while its own machine is stopped or changed, and a restart restarts one copy at a time, so the database stays up. Its Settings always show which machine it's running on.
To remove the standby, click Remove under Standby and confirm. Without it, the database goes down whenever its machine does.
Limits:
- A database on a volume can't have a standby, because one machine holds the volume. Remove the volume first.
- You can't add a volume to a database that has a standby. Remove the standby first.
- You can't remove a machine that holds a standby.
- While the standby's machine isn't running, you can't change the database's memory or restart it. Start that machine or remove the standby first.
Stopped machines
When the database's machine is stopped, the database shows Stopped, unless a standby on a running machine keeps it serving. It comes back when you start the machine. Its data stays on the machine's disk. See Stopping and starting.
Metrics
The database's Metrics page charts CPU and memory usage over the last 24 hours. Active connections and disk usage aren't collected yet; the Overview shows how much storage it uses. See Metrics.
Delete a database
In Settings, under Danger Zone, click Delete database and confirm. This deletes the database and all its data, and can't be undone.