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 EXCLUSIVE lock: 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.

Flow diagram: a human brings a migration PR, the agent proposes up to 4 options, each is tested on an ephemeral database for real evidence, a human picks one, and a gated pipeline ships it to production. Recorded decisions feed the agent's next review.

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:

  1. Everything is coded. No manual steps, no clicking through consoles.
  2. Isolation first. Experiments run on ephemeral databases, never prod.
  3. Evidence over opinion. Lock modes and rewrites are measured, not guessed.
  4. Least privilege. The agent holds no production credentials.
  5. Humans own the irreversible. Deploys are gated and approved.

The stack

The workflow invokes the agent; the agent never runs on the runner.

PlaneRunsTechnology
PipelineGitHub Actions jobsAWS CodeBuild-hosted runners, IAM role auth
AI agentThe reasoning loopBedrock AgentCore Runtime (Nova Pro)
DatabasesPermanent + ephemeralTiger Cloud (Postgres + TimescaleDB) via Tiger CLI: one database for the app, another for the RAG
MigrationsSchema changesLiquibase
InfrastructureEverything aboveOpenTofu
SecretsCredentialsAWS 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-password
tiger db uri --service-id <id> --password-storage none
tiger service delete <id> # always, even when the run fails

The flow, end to end

Every step is its own GitHub Actions workflow:

  1. Author. A developer adds a Liquibase changeset in a PR.
  2. Review. Guardrails run, and the agent returns a verdict and up to 4 options. No database is touched.
  3. Test. A human runs one option through a GitHub Action, on an ephemeral Tiger service.
  4. Decide and teach. The human records the decision, and the agent learns from it.
  5. 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-bigint
ALTER 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:

  1. A verdict: safe or unsafe.
  2. A hazard assessment per statement.
  3. Up to 4 candidate approaches, never padded to fill the count.
  4. 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:

  1. Creates an ephemeral Tiger service and waits until it accepts connections.
  2. Checks out main, the committed source of truth.
  3. Runs liquibase update to build the schema from main’s changesets.
  4. Applies the candidate SQL, capturing evidence.
  5. Has the agent analyze that evidence, read-only, on the same ephemeral.
  6. Destroys the ephemeral service. Always.

Evidence, not opinion

SignalWhy it matters
Lock modes heldDid it take ACCESS EXCLUSIVE?
Full-table rewrite (yes/no)The hours-of-downtime question
Elapsed timeRelative cost of each step
Errorse.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.

ActorCanCannot
AgentRead the SQL; auto-apply on an ephemeral serviceHold prod credentials, apply anything to prod, deploy
Pipeline runnerCreate and delete ephemerals; run workflows after reviews and approvalsAuto-deploy to prod
PR authorPropose a changesetEdit history on main
Human reviewerPick an option; record the decisionApprove a prod change alone: more than one engineer should sign off
Prod deployShip human-approved changes to the Production environmentRun 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:

PieceStatus
Rollback by DB tagAvailable (app-migrate rollback)
Rollback criteria script (lock waits, errors over a window)Written, not yet wired in
Datadog dashboards, monitors, phase eventsStrategy 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:

  1. Isolate. Give every experiment its own ephemeral database.
  2. Constrain. Least-privilege roles, read-only tools, timeouts, budgets.
  3. Measure. Detect locks and rewrites with evidence, not intuition.
  4. Gate. Humans approve every change that reaches production.
  5. Make it reversible. Immutable history, tagged deploys, rollback criteria.
  6. 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