# Postgres Migration Lock Check with Safe Rewrites

> Reviews Postgres SQL migrations for lock and downtime risk before they hit a busy table: names the lock, says what live traffic feels, and hands back a safe multi-step rewrite. Stdlib lint script with file:line output and a CI exit code.

Postgres Migration Lock Check with Safe Rewrites is a paid AI agent skill on Agensi by Signal Over Noise, in Data & Databases. It loads into your AI agent through the Agensi MCP server, always in its latest approved version.

- Price: $12 (one-time purchase)
- Creator: [Signal Over Noise](https://www.agensi.io/creators/jammin411)
- Category: [Data & Databases](https://www.agensi.io/skills/data-databases)
- Version: 1.0.0
- Last updated: 2026-12-01
- Security: scan passed (2026-12-01); every new listing is also reviewed by a person
- Listing: https://www.agensi.io/skills/postgres-migration-lock-check-with-safe-rewrites
- Tags: database, postgres, sql, migrations, devops, dba

## About this skill

A migration that runs in two seconds on staging can stop every write on a 40 GB production table, or queue all reads behind one ALTER that is waiting on a report query. Most of these outages come from a short list of statements, and each has a known safe pattern.

**What you get**

- A review method: establish Postgres version, table size, and whether your runner wraps files in a transaction, then judge each statement by the lock it takes.
- A rule table of 20+ checks: CREATE INDEX without CONCURRENTLY (and CONCURRENTLY inside a transaction), volatile ADD COLUMN defaults, type changes that rewrite, SET NOT NULL, FK and CHECK without NOT VALID, UNIQUE without USING INDEX, drops and renames of live columns, missing lock_timeout, unbatched backfills, VACUUM FULL, CLUSTER, REINDEX.
- Version facts stated plainly: constant defaults are metadata-only since PG 11, the CHECK-then-SET NOT NULL shortcut needs PG 12.
- A stdlib Python lint script: comment, string, and dollar-quote aware, file:line output, suppressions that require a reason, exit 1 on high findings.
- A worked example: five migrations, full output, the written review, and a four-file rewrite that lints clean.

**What it does not do**

It does not connect to your database, measure table sizes, check MySQL, or judge whether a backfill's logic is correct.

## Requires

- Python 3.10+

Migrations as plain .sql files (render ORM migrations to SQL first)

## Known limitations

Requires Python 3.10+. No support for MySQL or SQLite. Lexer skips DDL inside dollar-quoted function bodies. Cannot verify table sizes or row counts without user input.

## How to use this skill

1. Connect your AI agent to Agensi once: add the MCP server https://mcp.agensi.io/mcp/auth and sign in with your Agensi account (OAuth, no API key). Steps for Claude, ChatGPT, Claude Code, Codex, Cursor, VS Code and other agents: https://www.agensi.io/docs/mcp-setup
2. Ask your agent: "Use the Postgres Migration Lock Check with Safe Rewrites skill from Agensi" and describe your task.
3. Buy it on the listing or let your agent ask you first; your agent then loads it from Agensi when it needs it. Every paid skill has a money-back guarantee: https://www.agensi.io/docs/money-back-guarantee

## Frequently asked questions

### How does this skill help me prevent database downtime?

This skill helps you avoid production outages by identifying SQL statements that cause heavy locking or full table rewrites. It provides a systematic review of your Postgres migrations and generates a multi-step deployment plan to keep your application online during schema changes.

### What information or software do I need to provide for a review?

You need to provide your Postgres version, the size or traffic levels of the affected tables, and whether your migration tool wraps files in transactions. You also need a Python 3.10+ environment to run the provided linting script against your SQL files.

### What specific outputs will I receive after the analysis?

The skill delivers a formal verdict, a list of specific rule violations with file and line numbers, and a corrected SQL deployment plan. This plan is split into separate phases like expansion, concurrent indexing, and validation to ensure safety.

### Are there specific types of database changes this skill cannot review?

It does not check for data correctness, general query performance, or DDL hidden inside function bodies. It is also not suitable for non-Postgres databases like MySQL or SQLite, as their locking behaviors are different.

### How should I prompt my agent to start a migration safety check?

You can ask your agent to review a specific pull request for locking problems or ask if a migration is safe to run on a specific busy table. Be sure to include your SQL migration files and mention your Postgres version for the best results.

---

Source: [Agensi](https://www.agensi.io), the marketplace of skills for AI agents. Any MCP-compatible agent (Claude, ChatGPT, Claude Code, Codex, Cursor, VS Code and more) connects at https://mcp.agensi.io/mcp/auth and signs in with an Agensi account; setup for every agent: https://www.agensi.io/docs/mcp-setup. Append .md to any skill, guide or docs address on agensi.io for its markdown version.
