Goal: recover a supplied inventory backup into isolated databases and verify its scope.
Setup created 2,000 products and 8,000 reviews, took a custom dump, and made recovery_db.inventory. Drop only this lesson fixture’s products. CASCADE also drops the reviews foreign-key constraint; it does not delete the reviews table or its 8,000 rows. The following query proves that distinction. The baked beer tables are untouched.
These commands run at the Linux shell. psql -U postgres -d beer_db -c executes quoted SQL as the administrator and returns to the shell; -v ON_ERROR_STOP=1 stops that client on SQL errors.
Goal: confirm the backup contains the lost table and its dependencies.
List the custom archive. Notice products TABLE, TABLE DATA, SEQUENCE, DEFAULT, and primary-key CONSTRAINT entries; reviews has separate entries. The archive is independent of the table we just dropped. Entry numbers and catalog IDs are identifiers, not counts or restore guarantees.
Goal: observe exactly what pg_restore’s table filter restores.
The target schema already exists because --table=products does not select its schema entry. --exit-on-error rejects the first SQL failure. Expect a silent success for table definition and rows. This filter does not automatically select separate sequence/default/constraint entries; inspect that limitation next.
Goal: distinguish recovering data from restoring the full table behavior.
Expect 2,000 products with IDs 1–2,000 and price total 99,000.00. Then inspect the sequence, primary key, and id default: all should be absent for this pg_restore table selection. to_regclass returns NULL for an absent object; EXISTS produces t/f. A successful count is not proof that generated IDs or uniqueness were restored.
Goal: recover products together with its sequence, default, and primary key.
Write --list output to a file. sed deletes lines containing product_reviews, retaining schema and products-related dependencies. Restore that list into a newly created recovery_filtered, avoiding duplicate-object/data errors from reusing recovery_db. This preserves archive order; reordering is reference-only. --use-list reads selections from the file, not SQL.
Goal: restore both tables and verify the result after timing it.
Use a fresh database and restore the unfiltered archive. -j controls workers for custom/directory archives. Compare elapsed real time across the two runs; this small constrained lab is not a benchmark and parallel need not win. Expect 8,000 reviews and 2,000 products, with the products values verified independently.
Goal: restore both tables and verify the result after timing it.
Use a fresh database and restore the unfiltered archive. -j controls workers for custom/directory archives. Compare elapsed real time across the two runs; this small constrained lab is not a benchmark and parallel need not win. Expect 8,000 reviews and 2,000 products, with the products values verified independently.
Goal: prove the filtered restore restored sequence state as well as rows.
Insert a labelled temporary product without an id. Expect id 2,001, proving the serial default and restored sequence work. BEGIN/ROLLBACK remove the test row; sequence advancement is not rolled back. The final product count stays 2,000. The original beer_db products remains missing: moving validated data back into a live database is outside this isolated-recovery lab.