Skip to main content
Use a snapshot to rehearse a schema migration against a realistic PostgreSQL data directory, inspect the result, and return to the exact pre-migration disk state. The disposable rehearsal does not require a down migration.
Keep PGDATA in the sandbox root filesystem for this example. Snapshots capture the sandbox’s writable layer, but they do not capture external named or bind-mounted volumes.

Rehearse a migration

1

Create an initialized baseline

Set a temporary password in the host shell:
Start the baseline database:
Wait for initialization, then stop the database cleanly:
Stop it cleanly before taking the snapshot:
2

Snapshot the baseline

Verify the captured snapshot:
3

Apply the migration

Boot a fresh database from the snapshot:
Wait for the restored database to become ready:
Apply a sample destructive change and verify it:
Replace those statements with your real migration command and validation suite.
4

Roll back by replacing the sandbox

Stop the mutated database and boot another clean copy of the baseline under the same name:
Replace it with a fresh sandbox from the snapshot:
Wait for the clean database to become ready:
Confirm the sample table is absent:
The result should be rolled-back.
5

Clean up

Remove the database sandboxes:
Remove the snapshot:
Clear the password from the host shell: