AI agents can write a PostgreSQL migration in seconds. Production still needs guardrails so they never ship one on their own.
I’m all in on AI. It has bailed me out more times than I can count. But today, a human still needs to make the call on what reaches production. This post is the written version of my SRE Day NY 2026 talk: an agent-assisted PostgreSQL workflow where the agent does the fast, parallel experimenting and a human has the final word.
Out of IDs, and the obvious fix locks the table
Take a table called sensor_readings. Its primary key is id integer (int4), and it holds roughly 2.1 billion rows, about 2 TB. An int4 tops out at 2,147,483,647. At that ceiling, the next INSERT fails, and ingestion stops fleet-wide.
The obvious fix is one line, and any agent will write it:
ALTER TABLE sensor_readings ALTER COLUMN id TYPE bigint;
Here is what that line does in production:
- It takes an
ACCESS EXCLUSIVElock: no reads, no writes. - It rewrites the whole table, every index (including the one on
id) and every foreign key. - On a table of about 2 billion rows, that can mean hours of downtime.
The SQL is correct. Shipping it is the outage. Agents can write this ALTER; production needs guardrails so they never ship it.
The pattern: the agent proposes, a human decides
The agent is a fast, parallel experimenter. It never gets the final word.

A human brings the problem. The agent proposes up to four options; each is tested in isolation for real evidence, and a human picks one. Only then does a gated pipeline touch production.
Five rules hold it together:
- Everything is coded. No manual steps, no clicking through consoles.
- Isolation first. Experiments run on ephemeral databases, never prod.
- Evidence over opinion. Lock modes and rewrites are measured, not guessed.
- Least privilege. The agent holds no production credentials.
- Humans own the irreversible. Deploys are gated and approved.
The stack
The workflow invokes the agent; the agent never runs on the runner.
| Plane | Runs | Technology |
|---|---|---|
| Pipeline | GitHub Actions jobs | AWS CodeBuild-hosted runners, IAM role auth |
| AI agent | The reasoning loop | Bedrock AgentCore Runtime (Nova Pro) |
| Databases | Permanent + ephemeral | Tiger Cloud (Postgres + TimescaleDB) via Tiger CLI: one database for the app, another for the RAG |
| Migrations | Schema changes | Liquibase |
| Infrastructure | Everything above | OpenTofu |
| Secrets | Credentials | AWS Secrets Manager, none in GitHub |
Ephemeral databases are three Tiger CLI calls, and the last one is not optional:
tiger service create --name mt-<run-id> --with-passwordtiger db uri --service-id <id> --password-storage nonetiger service delete <id> # always, even when the run fails
The flow, end to end
Every step is its own GitHub Actions workflow:
- Author. A developer adds a Liquibase changeset in a PR.
- Review. Guardrails run, and the agent returns a verdict and up to 4 options. No database is touched.
- Test. A human runs one option through a GitHub Action, on an ephemeral Tiger service.
- Decide and teach. The human records the decision, and the agent learns from it.
- Ship. Deployment is a separate, gated step.
Step 1 · Author
The migration is a Liquibase changeset, versioned in git like any other code. Liquibase applies changesets in order and records each one it ran. Opening the PR runs nothing; it only triggers the review.
--changeset dev:sensor-readings-id-bigintALTER TABLE sensor_readings ALTER COLUMN id TYPE bigint;
Step 2 · Review
The migration-review workflow takes the changesets a PR adds and asks the agent, acting as a consultant. It is tool-less on purpose and touches no database. Its answers are grounded in a RAG knowledge base of playbooks and past decisions. It posts back as a PR comment with:
- A verdict: safe or unsafe.
- A hazard assessment per statement.
- Up to 4 candidate approaches, never padded to fill the count.
- A recommendation a human may overrule.
Step 3 · Test: an ephemeral database per candidate
A human picks an option and pastes its SQL into the migration-test workflow. The app database is never read or touched. The run:
- Creates an ephemeral Tiger service and waits until it accepts connections.
- Checks out
main, the committed source of truth. - Runs
liquibase updateto build the schema from main’s changesets. - Applies the candidate SQL, capturing evidence.
- Has the agent analyze that evidence, read-only, on the same ephemeral.
- Destroys the ephemeral service. Always.
Evidence, not opinion
| Signal | Why it matters |
|---|---|
| Lock modes held | Did it take ACCESS EXCLUSIVE? |
| Full-table rewrite (yes/no) | The hours-of-downtime question |
| Elapsed time | Relative cost of each step |
| Errors | e.g. NOT NULL with no default on a populated table |
An honest caveat: the ephemeral is schema-only, so timings reflect empty tables. The lock type and the rewrite yes/no are real. Scale is a seeding decision: about 1M rows in the live demo, plus one recorded run at billion-row scale.
Who can touch what
The agent reaches production only through the pipeline, behind review and approval gates. It has no direct prod access.
| Actor | Can | Cannot |
|---|---|---|
| Agent | Read the SQL; auto-apply on an ephemeral service | Hold prod credentials, apply anything to prod, deploy |
| Pipeline runner | Create and delete ephemerals; run workflows after reviews and approvals | Auto-deploy to prod |
| PR author | Propose a changeset | Edit history on main |
| Human reviewer | Pick an option; record the decision | Approve a prod change alone: more than one engineer should sign off |
| Prod deploy | Ship human-approved changes to the Production environment | Run from any branch other than main |
The agent itself is boxed in, too: a dedicated agent_ro role, a statement timeout, a 50-row result cap and defined rollbacks. It gets full freedom only on ephemeral services. No AWS keys live in GitHub; secrets sit in AWS Secrets Manager and are read at run time through IAM roles.
Decide, teach, ship, and roll back
Step 4 · Decide and teach
The human records the decision. In my repo, each decision is logged in a Markdown file at agent/knowledge/decisions/<date>-<slug>.md that captures the SQL reviewed, the verdict, the chosen approach, and the rationale. Commit it, and a GitHub Actions workflow runs rag-ingest, which reads the Markdown and adds it to the RAG knowledge base so future reviews can retrieve it. Every call a human makes becomes context for the agent’s next review.
Step 5 · Ship
Nothing deploys from a PR. Deployment is a separate, manually triggered workflow. Images are tagged with the git SHA, and Liquibase tags the database with the same SHA. Rollback is to a tag (preferred) or by a count of changesets. SHAs work, but they’re hard for humans to read and compare, so I want to move to a better versioning scheme. That’s still a work in progress.
Monitoring and rollback: where it actually stands
This part is designed, with the pieces started. Here is the honest status:
| Piece | Status |
|---|---|
| Rollback by DB tag | Available (app-migrate rollback) |
| Rollback criteria script (lock waits, errors over a window) | Written, not yet wired in |
| Datadog dashboards, monitors, phase events | Strategy still to design |
The blueprint
Strip away the specific tools and six principles remain. They work with any agent, any CI system, and any Postgres host:
- Isolate. Give every experiment its own ephemeral database.
- Constrain. Least-privilege roles, read-only tools, timeouts, budgets.
- Measure. Detect locks and rewrites with evidence, not intuition.
- Gate. Humans approve every change that reaches production.
- Make it reversible. Immutable history, tagged deploys, rollback criteria.
- Close the loop. Record decisions so the agent improves.
Accelerate the work. Keep the authority.
The code behind this workflow is now live at thepostgresguy/agentic-dataops (coming soon). Thanks to Datadog for hosting SRE Day NY, the SRE Day group for the opportunity to speak, AWS for cloud credits through the AWS Community Builders program, and Tiger Cloud for the trial.

Leave a Reply