Goal: migrate a reporting fixture with its owner into a separate cluster.
Setup made NOLOGIN role report_owner, a schema/table owned by it, three weekly totals, and a custom archive. Decode that archive to SQL with pg_restore --file, then inspect owner references. They name a role but do not define it. Grepping compressed binary data cannot establish whether a role definition was backed up.
Goal: capture role definitions separately from database objects.
pg_dumpall --globals-only writes a plain SQL script for cluster-wide roles and tablespaces, not reporting rows or configuration files. --no-role-passwords deliberately omits password hashes; this experiment verifies NOLOGIN ownership, not password migration. A successful export normally prints nothing.
Goal: verify the globals script contains the missing role and its attributes.
Expect CREATE ROLE and ALTER ROLE for report_owner, including NOLOGIN. This role owns objects but cannot authenticate. The script is executable SQL: use psql for replay, not pg_restore.
Goal: create genuinely separate role catalogs.
initdb -D builds a new data directory owned by the Linux student; -U postgres names its bootstrap SQL superuser. These are different identities. Explicit UTF8/C/trust settings make the local fixture repeatable. This is a disposable local cluster; trust is not production authentication. It does not inherit the source cluster’s role catalog.
Goal: prove the new server is the one on port 5433.
pg_ctl uses the new directory. -o passes server options: port 5433 and socket directory /tmp. -l captures startup messages; -w waits for readiness. Query its port/data_directory and report_owner existence: expect 5433, /tmp/freshcluster, false. Always specify the port/socket for secondary-cluster clients.
psql -c runs the quoted query and exits; -v ON_ERROR_STOP=1 stops on SQL errors. The port is part of selecting the server, while -d selects a database inside that server.
Goal: see why data appearing does not mean ownership recovered correctly.
Create migrated_db on port 5433 and restore without globals. The default pg_restore behavior continues after ownership SQL errors, then reports errors ignored; that is a failed/nonzero restore, not success. Expect report_owner does not exist, three data rows, and schema/table owner postgres instead of report_owner. The following catalog query shows the damage explicitly.
Immediately print $?, the prior shell command’s exit status: expect 1. Run this before another command overwrites it.
Goal: supply the referenced role while handling the existing bootstrap role deliberately.
The new cluster already has postgres from initdb. Delete only the exact CREATE ROLE postgres line from a copied script; keep its ALTER attributes and all other roles. Otherwise psql with ON_ERROR_STOP would stop at the duplicate role. Restore the adjusted globals on port 5433. This is an explicit local bootstrap adaptation, not a general merge strategy for existing production roles.
Goal: confirm attributes in the destination, not the source.
Query report_owner on port 5433: expect login=false and superuser=false. Adding a role after a failed restore does not retroactively rerun failed owner statements. The next step must retry cleanly.
Goal: prove the migration recovered both data and its owner.
Drop only the partial migrated_db on port 5433 and recreate it empty. With globals present, --exit-on-error restoration should succeed silently. Inspect all three weekly rows and both owners; expect report_owner for schema and table. Restoring globals afterward alone would not repair the previous wrong ownership.
Goal: finish with a verified migration and no secondary server running.
Use fast shutdown on the secondary directory: active transactions would be rolled back and the server shuts down cleanly. Expect server stopped; the PID file should disappear. The source on 5432 remains available.