Backup and restore
Overview
A backup is useful only if it can be restored to the required state. Logical backups capture schema and data as logical objects; physical backups capture database storage using engine-supported consistency procedures. PostgreSQL pg_dump is a logical database backup; roles and other cluster-global objects require separate coverage. Keep encrypted, access-controlled, off-site or isolated copies and test restores.
First example
SELECT id,balance FROM ad_account ORDER BY id;Observed SQLite result (rows in JSON):
[ [ 1, 100 ], [ 2, 200 ]]How it works
The account totals below form a small restore contract; totals alone cannot prove identical records. The host lab uses SQLite backup API and iterdump into separate files, checks exact rows and integrity, then changes the source to demonstrate that a backup does not follow subsequent writes. Do not copy a live database file blindly, especially with WAL.
Practical example
PRAGMA integrity_check;Observed SQLite result (rows in JSON):
[ [ "ok" ]]Practice and mistakes
Practice: define a restore checklist including row identity, constraints, schema, integrity and application smoke tests. Hint: compare ordered rows, not just counts. Check: balances 100 and 200. Mistake: declaring recovery successful just because a backup file exists.
PostgreSQL 17 example — NOT RUN
SELECT current_database(),pg_database_size(current_database());Expected result, not executed: "Database size is not backup size or restore verification."