# State 005 Learning Guide

> For the complete documentation index, see [llms.txt](https://deploy-preview-472--lucky-concha-f3599f.netlify.app/llms.txt).

## Position In Learning Graph

*   Previous state(s): [004-containerized-compose-runtime](https://deploy-preview-472--lucky-concha-f3599f.netlify.app/docs/learning/state-004-containerized-compose-runtime.md)
*   Dotted-line parent(s): none
*   Next state(s): [006-messaging-nats-replacement](https://deploy-preview-472--lucky-concha-f3599f.netlify.app/docs/learning/state-006-messaging-nats-replacement.md)

## Convergence Metadata

*   Convergence state: `no`
*   Convergence level: `none`
*   Lineage role: `canonical`
*   Nearest previous convergence: `none`
*   Nearest next convergence: `none`

## Rendered Code

*   Generated branch: [code/generated-state-005-postgres-database-replacement](https://github.com/finos/traderX/tree/code/generated-state-005-postgres-database-replacement)
*   Authoring branch (spec source): [main](https://github.com/finos/traderX/tree/main)

## Code Comparison With Previous State

*   Compare against `004-containerized-compose-runtime`: [code/generated-state-004-containerized-compose-runtime...code/generated-state-005-postgres-database-replacement](https://github.com/finos/traderX/compare/code%2Fgenerated-state-004-containerized-compose-runtime...code%2Fgenerated-state-005-postgres-database-replacement)

## Plain-English Code Delta

*   **Added:** PostgreSQL runtime initialization pack (`postgres-init/initialSchema.sql`) for deterministic baseline schema and seed data.
*   **Added:** Postgres-specific smoke checks (readiness + baseline data presence).
*   **Changed:** Runtime database engine changes from H2 server process to PostgreSQL container.
*   **Changed:** Service datasource wiring for:
*   **Changed:** `account-service`
*   **Changed:** `position-service`
*   **Changed:** `trade-processor`
*   **Changed:** Account sequence ID generation query changes to PostgreSQL sequence syntax.

## Run This State

```bash
./scripts/start-state-005-postgres-database-replacement-generated.sh
```

## Canonical Spec Links

*   State spec pack: [/specs/postgres-database-replacement](https://deploy-preview-472--lucky-concha-f3599f.netlify.app/specs/postgres-database-replacement.md)
*   Architecture: [/specs/postgres-database-replacement/system/architecture](https://deploy-preview-472--lucky-concha-f3599f.netlify.app/specs/postgres-database-replacement/system/architecture.md)
*   Flows / topology: [/specs/postgres-database-replacement/system/runtime-topology](https://deploy-preview-472--lucky-concha-f3599f.netlify.app/specs/postgres-database-replacement/system/runtime-topology.md)
*   Research: [link](https://deploy-preview-472--lucky-concha-f3599f.netlify.app/specs/postgres-database-replacement/research.md)
*   Data model: [link](https://deploy-preview-472--lucky-concha-f3599f.netlify.app/specs/postgres-database-replacement/data-model.md)
*   Quickstart: [link](https://deploy-preview-472--lucky-concha-f3599f.netlify.app/specs/postgres-database-replacement/quickstart.md)
*   State ADR: [link](https://deploy-preview-472--lucky-concha-f3599f.netlify.app/docs/adr/006-state-005-use-postgres-for-database-replacement.md)
