Linux Labs

Web stack / Stage 8 of 9

A dump and a verified restore

Not running Starting usually ~20 s
Leave the lesson

Step 1 of 7 · on a machine · 5 min

A dump on a live database

What you will learn

  • Read what a PostgreSQL dump holds: tables, rows, counters and keys.
  • Take a dump of a database and restore it into a new database without touching the working one.
  • Compare a restored copy with the original by its rows and its counter.

Yesterday evening someone took a dump of the shop database: the file ~/backup/shop.dump. Today a colleague decided to check that the dump works and restored it straight into shop: the tables are there, so nothing can break.

Repeat the check, then do what the shop does every minute: add an order. You have your own student role in PostgreSQL, with no password needed. “Start” launches the server and prepares the database and the dump.

Exercise · look

Restore the dump over the live database

In ~/backup, restore yesterday's dump straight into the shop database, count the orders and add a new one.

First, predict

What will pg_restore do to the shop database?

Now start the exercise, run the command and compare your prediction with the output.

Sign in and start The machine is available after signing in
Check yourself 1 question

How many orders were left in orders after pg_restore?

  • No duplicates got in: the primary key stopped COPY with duplicate key … Key (id)=(1) already exists.

  • CREATE TABLE failed with already exists: the table is the same one, and count(*) showed 6.

  • count(*) showed 6: pg_restore did not replace any rows, and its COPY failed on the very first id.

All 6 of today's orders stayed in orders because the dump's COPY did not get through.

Ubuntu 24.04
Loading…