Skip to main content
CRUCIBLE
Legacy Reference Archive: This 44-chapter book reference has been distilled into Academy A01 (8 Executable Modules) with Tier-Adaptive Productive Failure, Kore/Puck voice, and live Firecracker labs.
Open Academy A01 →
COURSE 0 · SERVER BUILDING & LIFECYCLE MASTERY

Zero-to-Production Linux, Containers, Networking & Recovery

PROGRESS: 0 / 72 (0%)0/44L · 0Q · 0VM
TRK 02 · 6 SPECIALIST SERVER TRACKS · 838 WORDS (5 MIN)

PostgreSQL data-service track

From your Crucible Linux workspace, first create the example's environment using its locked dependencies, then run the script through that environment: The script chooses free ports, creates private directories, generates fixture passwords and starts clusters named.

FULL WAR-ROOM →
INTERACTIVE REQUEST FLOW · CLICK ANY HOP TO INSPECT LIVE

Production Request Path: HTTPS Edge -> App -> PgBouncer -> Postgres

Trace every hop from a browser TLS 1.3 connection to an indexed PostgreSQL row lookup.

HTTPSQLPooledNGINX EdgeTLS 1.3 · :8443 / :443FastAPI Worker127.0.0.1 :8000PgBouncer PoolTX Mux · :6432PostgreSQL 15B-Tree · :5432
SELECTED LAYER · NGINX EDGE
Terminates HTTPS, enforces timeouts and rate limits, and reverse-proxies clean HTTP to loopback.
Common failure: HTTP 502 Bad Gateway when upstream keepalive_timeout is shorter than proxy idle timeout.
$ nginx -t

Audience: operator who understands SQL transactions and the API/worker exercise. Prerequisites: native PostgreSQL client/server utilities on PATH, age, and the reference Python environment. Environment: two owned temporary clusters bound to loopback, using synthetic data. Expected outcome: prove that committed application state and identity survive a database process restart and an encrypted logical restore. Consult proof/postgres-recovery.json after your live VM verification run; this procedure does not imply a remote deployment.

Adapt all twelve phases

PhaseData-service decision and evidence
1 FrameworkClassify source of truth, logical databases, schemas, owners and consumers.
2 BeginnerExplain committed rows, transactions, constraints, indexes, roles and connections.
3 ArchitectureDefine consistency, write rate, data growth, recovery-point and recovery-time objectives.
4 ProvisionSeparate durable storage, cluster initialization, network exposure and application rollout.
5 FoundationRestrict DB network access; distinguish migration owner, runtime role and backup identity.
6 ServiceApply versioned schema, tune bounded connections/timeouts, test tenant queries and constraints.
7 Go liveValidate application connectivity and representative transaction behavior with runtime privileges.
8 OperateMonitor free space, connections, query latency, locks, long transactions, backups and restore freshness.
9 ChangeTest indexes, schema changes, extensions and version upgrades with representative data and lock measurements.
10 RecoverRestore independently, verify behavior/permissions and measure recovered point and usable service time.
11 Migrate/retireControl writers, reconcile final changes, verify consumers moved, then retain/revoke/delete per policy.
12 AssessAnother operator restores without access to the old host and explains the actual loss window.

Execute the isolated reference drill

From your VM workspace directory (~/playground), first create the example's environment using its locked dependencies, then run the script through that environment:

bash
cd ~/playground/automation-service
uv sync --frozen
uv run python ../../pg-xray

The script chooses free ports, creates private directories, generates fixture passwords and starts clusters named primary/recovery in its owned workspace. It migrates the primary database, seeds a tenant credential, completes a job, checks that the runtime role cannot create a table, restarts PostgreSQL and reads the result again. It then encrypts a custom-format dump with a generated age recipient, decrypts it, compares digests, restores into the second cluster and validates the result through the application. A corrupted ciphertext must fail decryption. Cleanup stops only the clusters the script created and removes their temporary state.

Expected output is a JSON receipt whose checks are true. A nonzero exit is a failure, even if a dump file existed. Capture the command exit and receipt; never replace a failed receipt with a stale prior run result. Missing executables, port conflicts and incompatible tools require resolving the actual environment problem, not weakening the assertions.

Understand the restoration contract

A logical dump is a consistent database snapshot, not a recording of every subsequent change. Custom-format archives are consumed by pg_restore. A standalone database dump does not carry every cluster-wide identity or external object; restore roles and permissions deliberately. The fixture uses --no-owner --no-acl and recreates the required application access in its controlled environment; a production procedure must explicitly handle ownership/grants. See [PostgreSQL SQL dump](https://www.postgresql.org/docs/current/backup-dump.html) and [pg_restore](https://www.postgresql.org/docs/current/app-pgrestore.html).

For production recovery, first identify the last verified backup, source version, extensions, encoding, ownership mapping and key location. Restore to a clean separate target; avoid --clean against an existing production database. Trust the backup's source and inspect untrusted archives: restore can execute database code contained in the archive. Keep external dispatchers disabled until side effects have been reconciled.

Count checks alone are insufficient. Verify primary keys, representative values, constraints, runtime permissions, latest expected business timestamp and an authenticated application transaction. Record the gap between the last required committed event and the recovered event as the observed loss window. Measure usable service recovery from the agreed start event, including access to artifacts, credentials, keys and network routing.

Advance beyond this fixture

The drill does not test continuous WAL archiving, point-in-time recovery, replicas, failover fencing, cross-region loss or a lost Mac. Add these only after defining the required contract. A replica can reproduce an accidental delete and does not replace retained backups. A failover design must prevent two primaries accepting conflicting writes. A physical backup's compatibility assumptions differ from a logical dump.

For performance, gather slow-query evidence and plans before adding indexes or replicas. Record pool limits across every API/worker replica so total connections stay bounded. Test long transactions and lock waits in staging. Monitor vacuum progress, dead tuples and storage growth according to the selected PostgreSQL version and workload; a generic tuning number is not a substitute for measurement.

A migration has a cutover point. Pause or fence writes, take the final consistent transfer, validate the destination, switch clients and observe errors and data consistency. Define whether rollback is still possible after the destination accepts writes. Retirement requires application-consumer confirmation, independent retained backups and revoked old connection identities before deleting the exact database/storage resources.

ACTIVE-RECALL MASTERY CHECKPOINT · TRK 02

Lock in what you just learned (3 quick questions)

PASS 2/3 FOR +30 XP
Q1.What happens in PostgreSQL when long-running idle in transaction sessions stay open on a write-heavy table?
Q2.Why pair continuous WAL archiving / point-in-time recovery (PITR) with periodic base backups for critical Postgres databases?
Q3.Why verify query plans with EXPLAIN (ANALYZE, BUFFERS) after adding an index?
Answered 0 / 3