Goal: create three backup formats and prove each can restore the supplied inventory.
A logical backup is a recipe for rebuilding objects. The setup supplies inventory with 2,000 deterministic products, 8,000 reviews, and 10,000 stock movements; the baked datasets stay intact. These commands run at the Linux shell. -U postgres selects the administrative SQL role, -d the database, and -f the destination file. Check both tool versions: expect PostgreSQL 19.0.
Goal: establish the data baseline before taking backups.
Use COUNT(*) on each table, not n_live_tup, which is a statistics estimate. Expect products 2,000, reviews 8,000, movements 10,000. UNION ALL combines labelled counts; ordering makes the output stable.
The one-shot psql -c client executes the quoted SQL and returns to the shell. -v ON_ERROR_STOP=1 sets a psql variable so SQL errors stop the client instead of letting a script continue. -U postgres and -d beer_db select the administrative SQL role and source database.
Goal: recognise the plain format as executable SQL text.
Dump only inventory, then read its first 15 lines. Success is normally silent. The header names the server/client versions; the generated \restrict token is a psql safety mechanism, not a password to copy. Plain format is the default and is restored through psql -f.
Goal: capture the same schema in a format pg_restore can select from.
-Fc means custom format. It compresses table data by default and is a useful option when selective restoration matters. It is not pg_dump’s default format. A silent command is normal; later listing and restoration test what was captured.
Goal: observe compression without assuming a fixed ratio.
wc -c prints byte counts and filenames; its total is the sum of both files. Expect both to be nonempty and the custom archive to be smaller for this repetitive fixture. Sizes vary with timestamps and software versions. This is a local size observation, not a universal compression guarantee.
Goal: establish a local timing baseline.
-Fd creates a new directory; its name must not already exist. -j 1 uses one worker. Bash time reports elapsed real time and CPU user/sys time. Observe the result without expecting a fixed number. The small fixture keeps this a mechanism demonstration.
Goal: compare the same data with four workers.
-j 4 opens a leader connection plus four worker connections. Directory format supports parallel dumping; custom and plain do not. Compare real with the prior step: four workers need not be faster in this constrained lab, and a table is not split across workers.
Goal: verify the filter selected products, not its sibling tables.
--table=inventory.products filters the dump itself. List its contents and notice products table/data entries, with no reviews or movements. A table filter does not automatically include every dependency, such as the containing schema; plan the destination accordingly.
Goal: check the expected object list before attempting a restore.
pg_restore --list reads the table of contents without a database connection. Find all three TABLE DATA entries plus sequences and constraints. A readable list proves the header/catalog can be read; it does not read every data block or prove a complete, usable recovery.
Goal: prove this format reconstructs the captured schema and data.
Create a separate empty database, then restore. ON_ERROR_STOP=1 makes psql stop on SQL errors; --exit-on-error does the same for pg_restore. Count all three tables and inspect products’ price total: expect 2,000 / 8,000 / 10,000 and 99,000.00. These checks prove this fixture’s recovery; matching counts alone would not prove arbitrary data equality.
Goal: prove this format reconstructs the captured schema and data.
Create a separate empty database, then restore. ON_ERROR_STOP=1 makes psql stop on SQL errors; --exit-on-error does the same for pg_restore. Count all three tables and inspect products’ price total: expect 2,000 / 8,000 / 10,000 and 99,000.00. These checks prove this fixture’s recovery; matching counts alone would not prove arbitrary data equality.
Goal: prove this format reconstructs the captured schema and data.
Create a separate empty database, then restore. ON_ERROR_STOP=1 makes psql stop on SQL errors; --exit-on-error does the same for pg_restore. Count all three tables and inspect products’ price total: expect 2,000 / 8,000 / 10,000 and 99,000.00. These checks prove this fixture’s recovery; matching counts alone would not prove arbitrary data equality.