Database hosting, backups and restores
Choose managed Postgres, tell logical dumps from point-in-time recovery, and run a restore drill, because a backup you never restored is only a guess.
Environments, domains and TLSDesigning the schema from featuresSeed data and the dev database workflow
Database hosting, backups and restores
The player loads from youtube-nocookie.com when you press play. Nothing reaches YouTube before that.
Not started
What you'll learn
- A managed Postgres trades some control for patching, backups and failover handled by someone else, which is the right default for a small team.
- A logical backup such as pg_dump captures data at one moment, while point-in-time recovery replays the write-ahead log and lets you restore to just before a mistake.
- A backup only counts once you have restored it somewhere and checked the data, so schedule a restore drill rather than trusting a green backup job.
- Define how much data you can lose (recovery point) and how long you can be down (recovery time) before choosing a backup setup.
- Keep backups in a different place and under different credentials from the database they protect, so one mistake or breach cannot remove both.
Why the database is different
Everything else in Taskboard can be rebuilt. The client is files from vite build. The API is a container built from git. If a host disappears, you redeploy somewhere else in minutes. The database is the one tier that holds something you cannot regenerate: your users’ projects, tasks and comments.
That changes how you think about it. The question is not “is it running?” but “if it is gone, or if I just deleted the wrong rows, how do I get the data back, and how much do I lose?”
Managed or self-run
You can run Postgres yourself on a VM, or pay a provider (the major clouds, Neon, Supabase, Render, Fly and others) to run it. A managed service typically handles installing and patching Postgres, automated backups, and often a standby for failover.
For a small team the managed route is the right default, because the failure you are protecting against, losing data, is exactly what managed backups exist for, and setting up and testing your own takes real time. Self-running becomes reasonable when you need an extension or setting the provider does not allow, or when cost at scale tips the balance. Whichever you pick, ask four things:
- How are backups taken, how often, and how long are they kept?
- Can I restore to a point in time, or only to the last backup?
- How do I connect: public address, private network, TLS required?
- What are the connection limits? (A serverless API with many instances can exhaust a small plan; see connection pooling.)
Two kinds of backup
Logical backup. A tool such as pg_dump reads the database through SQL and writes out its schema and data. It is portable, easy to inspect, and works across Postgres versions. It captures one moment, and a large database takes a long time to dump and restore.
Physical backup plus WAL archiving. A base backup copies the data files, and the server continuously archives its write-ahead log (WAL), the journal of every change. To restore, you load the base backup and replay the log up to a chosen time. That is point-in-time recovery (PITR): the way to get back to 14:02, just before someone ran the bad delete.
Most managed services do the second behind a button labelled “restore to a point in time”, and you may also want occasional logical dumps you hold yourself, for portability and for a copy outside the provider.
A restore drill
A backup is a claim. A restore is the proof. I ran the logical version end to end on a scratch Postgres 14.25 cluster with Taskboard’s schema and 1,000 tasks:
pg_dump -Fc tb -f tb.dump # compressed archive, 11 KB here
psql tb -c "delete from tasks" # simulate the mistake: 0 rows left
createdb tb_restore
pg_restore -d tb_restore tb.dump
psql tb_restore -tc "select count(*) from tasks" # 1000
The restored copy had all 1,000 rows, and the live database still had its (deliberately emptied) state, because I restored into a separate database. I used the Postgres 14 client tools; your version will print its own version numbers, and flags are as documented for pg_dump.
Notice what I did not do: I did not touch the original. A restore drill goes to a new database, then you check it:
- Row counts for the main tables match expectations.
- The app starts against the copy and a signed-in page loads.
- The newest row you expect is there, which shows how recent the backup actually is.
Do this once now, and put it on a calendar, quarterly at least. The failures a drill finds are mundane and fatal in a real emergency: the backup job has been failing quietly for weeks, the dump excludes a schema, the credentials to the backup storage expired, or nobody remembers the command.
How much loss and how much downtime
Two numbers decide the setup:
- Recovery point objective (RPO): how much recent data you can lose. A nightly dump means up to 24 hours. Continuous WAL archiving means seconds.
- Recovery time objective (RTO): how long you can be down. Restoring a 200 GB dump may take hours. A promoted standby takes seconds to minutes.
For Taskboard, losing a day of task edits would be unpleasant but survivable. Losing a customer’s paid invoices would not be. Pick RPO and RTO per app, write them down, then check that your setup meets them. See also the failover discussion in availability patterns and failover.
Protect the backups too
- Different place. If backups live on the same volume or in the same account as the database, one mistake or breach removes both. Keep a copy elsewhere.
- Different credentials. The app’s database user should not be able to delete backups.
- Encrypted, and secrets handled. A dump contains every user’s data. Treat it like the database itself.
- Retention. Decide how long you keep them and whether privacy rules require deleting a user’s data from old backups too.
Schema changes are the other way to hurt a database on purpose. Take a fresh backup or snapshot before a risky migration, and read schema migrations and change management and the next lesson on changing a live schema safely.
What the video covers
Prateek Goel’s video, “PostgreSQL Backups and Point-in-Time Recovery: pg_dump, pg_basebackup, WAL Archiving, Restore Tests”, is about eight minutes long and about a month old. Its title lists exactly the tools and topics above, including restore testing. It is from a small channel, and I could not read a transcript, so I cannot vouch for its depth or accuracy beyond what the title and description promise. Coded Intuition’s PITR explainer is linked as a second view of the log-replay idea.
Where this fits
You can now host the database and prove you can recover it. The riskiest moment for it is a deploy that changes the schema while users are still online, which is next: zero-downtime deploys and schema changes.
Check yourself
What does pg_dump -Fc produce, and how do you load it?
A compressed custom-format archive of the schema and data at the moment the dump began, loaded with pg_restore into a database you create first.
How is point-in-time recovery different from a nightly dump?
A dump gives you the state at one moment per night. Point-in-time recovery uses a base backup plus the archived write-ahead log to rebuild the database to any chosen second, such as just before a bad delete.
Why restore into a different database during a drill?
So you test the backup without touching the live data, and so you can compare row counts and run the app against the copy.
What are recovery point and recovery time?
The recovery point is how much recent data you can afford to lose, and the recovery time is how long the app can be down while you restore. They decide how often to back up and what tooling you need.
Go deeper
Notes
Notes are saved to your account.
Everything else on this page works without one — progress and bookmarks keep themselves in this browser and come with you when you sign in. Notes are the one thing worth not trusting to a browser you might clear.
Your notes could not be loaded.