Choosing an Agent Database: A Connection Is Not Readiness
Suppose I move a personal research tool from my laptop to a cloud host. Its web page loads and SELECT 1 works, but yesterday's report is missing. The application may have connected successfully to the wrong database, rather than failed to generate the report.
This is a design exercise using synthetic databases and research tasks, not a production migration claim.
Decide the data lifecycle first
| Situation | Starting point | Additional responsibilities |
|---|---|---|
| Single host, modest contention, fixed disk | SQLite | File path, backups, concurrent writes and recovery |
| Multiple workers and application instances | PostgreSQL | Connections, transactions, migrations and recovery |
| Serverless web with persistent workers | Managed PostgreSQL | Short-lived client pools, worker data source and execution budgets |
SQLite is not just for teaching. It removes a separate database service but requires persistent storage and a supported concurrency model. PostgreSQL can coordinate several processes; copying tables alone does not migrate a system. Report identities, task state, authorization, effect receipts and historical readback must survive the move.
Three connection modes are not three databases
A PostgreSQL provider can expose direct, session-pooled and transaction-pooled connections. For example, Supabase's connection guide recommends transaction pooling for short-lived functions. Its shared transaction pool cannot preserve session state across transactions and restricts named prepared statements. Prefer a direct connection for migrations and backup or restore; if using session pooling, verify the tool and network path support the required session semantics.
Application-side pooling and provider-side pooling are separate. Twenty warm instances each reserving ten connections imply a potential 200 client connections, not ten. This is a capacity estimate, not measured utilization. Limit per-instance connections first and increase them based on observed contention rather than masking exhaustion with reconnects.
Ask the right readiness question
Design a deployment identity table writable by the migration role and readable by the application, alongside a schema-migration ledger. This is a synthetic SQL contract, not a reproduction of an existing project:
SELECT environment_id FROM deployment_identity;
SELECT version FROM schema_migrations;Compare the returned unique environment identity and required migration set with trusted configuration for this release. Validate TLS certificates and hostnames. An identity marker does not replace credentials and network isolation, and a mismatch must not cause the application to rewrite the marker.
| Check | Expected result |
|---|---|
| Liveness | HTTP process responds independently of external database availability |
| Readiness | Intended database, required migrations and necessary application reads |
| User path | Read the original task and report IDs; have the worker claim a synthetic task |
Isolate staging credentials and databases. Separate migration and application roles; a readiness check does not need administrator privileges. Return generic health states rather than connection strings or internal hostnames.
An acceptance test designed to fail
Prepare two isolated databases with the same schema but distinct environment markers. Connect to the correct one and record a report ID. Point the application to the other one: readiness should fail even though SELECT 1 succeeds. Then remove a required migration marker, revoke read access and restart the worker, observing distinct failure states. No private holdings are needed.
Open ETF Agent already has hosted PostgreSQL documentation. The table names and interface above are independent designs, not implementation claims. Further self-hosting and observability work is in the application roadmap; preserve task identity across the durable job queue.