You can follow along right in your browser. When you click "Start Now," Katacoda will load a Docker Compose
environment with two container images representing a PostgreSQL 13 server with
the Pagila database loaded (named pg)
and a backup server for Barman (named backup).
Once you see a barman@backup prompt, you can follow the steps below.
Clicking Start Now will load an interactive terminal in this window
Something terrible has happened to our example database! This should list all the tables:
All the data is gone!
Ok, I just didn't populate the data for this step, in order to demonstrate a total loss. Fortunately, we still have a backup!
Let's instruct Barman to ssh into the database server and restore the backup.
Connect to pg and shut down the database cluster:
Back up the corrupt data directory, just in case something goes wrong. Then delete the corrupt data.
Barman handles connecting to the destination server, but we do have to provide a valid path on that server. In this example, the PostgreSQL cluster lives in /var/lib/postgresql/data and we're asking Barman to overwrite it with the backup.
Restart the server:
Now we should be able to reconnect to the database:
...And re-run the query we started out with:
Ok, so far so good - but, we're missing the update we wrote to this data! Remember, that wasn't in the base backup, it was in a partial WAL file... Fortunately, Barman still has it and knows how to use it.
Let's try this recovery process again:
Connect to pg and shut down the database cluster:
Back up the corrupt data directory, just in case something goes wrong. Then delete the corrupt data.
Instruct Barman to connect to pg and restore the latest backup with the --get-wal option - this triggers WAL fetching, including partial WAL files, during the recovery process.
Restart the server:
about those errors...
You may notice two lines starting with "ERROR:" mid-way through the recovery log. They're fine - that's just PostgreSQL scanning to make sure it has the most recent timeline.
By going through this recovery, we've actually created a new timeline - in fact, if you were to run through the four steps above again, you'd see that now 00000002.history is found and PostgreSQL goes looking for 00000003.history... Try it!
This demonstration barely scratches the surface of what is possible with Barman, but hopefully it has provided you with a taste of its capabilities! For more details, visit https://pgbarman.org/