17 rulesPG001 to PG017

Migration checks for Postgres teams

Engineering teams get it in the pull request: pgguard reads the SQL, names the statements that lock, rewrite or break a live table, and fails the build before the deploy does.

Run it on a migration, now

This is the checker itself, not a recording of it. Paste a migration or take one of the four below, and the window answers with the findings, the reason Postgres behaves that way, the rewrite, and the exit code CI would have taken.

Runs the same engine the Action runs. Nothing is stored: the SQL is parsed in the request and thrown away.

pgguardwaiting

Press Scan this migration. The findings appear here, with the statement, the reason Postgres behaves that way and the rewrite that avoids it.

What you just used is free forever

No account, no card, no limit worth mentioning

  • All 17 rules, on raw SQL, Prisma and Django
  • The scanner here, and the Action in your pipeline on one repository
  • Findings posted on the pull request, build failed at your threshold
  • No database connection, no credentials, no code leaves your pipeline

The Action reads the migration files a pull request changes and nothing else: no clone, no repository access, no connection to a database. The rule reference says exactly what each of the seventeen looks for, so nothing here is a black box.

What a local run cannot do

$29 a project a month · the hosted part

  • It remembers. Every scan is kept, so a repository reads as pass, fail, pass across months instead of one run in a log that rotates away.
  • It tells you. A critical finding reaches Slack and email the moment it lands, not when somebody opens the Actions tab.
  • It is one place. Every repository, every branch, one overview, rather than a workflow file per team to keep in step.
  • It is not your problem. New rules arrive without a dependency bump, and the version that ran each scan is recorded with it.

Scan history, per repository

A scan lands here the moment the Action finishes, with the commit, the branch and each finding it posted on the pull request.

pgguard · payments/apiScan history

Runs

add-user-email4f1c9a2 · 3 findings · 1 critical · 1 high · 1 medium
main8b92e73 · no dangerous patterns
maindb63a4d · no dangerous patterns
index-concurrently25b9be5 · 1 finding · 1 high
main1ed2efa · no dangerous patterns
db/migrate/0005_add_user_email.sqlcommit 4f1c9a21 file, 2 statements
criticalPG0013:19

email is NOT NULL with no DEFAULT on existing table users.

ALTER TABLE users ADD COLUMN email text NOT NULL
highPG0024:1

Index built without CONCURRENTLY on users.

CREATE INDEX idx_users_email ON users (email)
mediumPG0143:1

ALTER TABLE runs on users with no lock_timeout set first.

ALTER TABLE users ADD COLUMN email text NOT NULL

✗ fail — 3 findings, 1 critical, 1 high, 1 medium

17

rules, each with the reason and the safe rewrite

3

migration formats: raw SQL, Prisma and Django

0

runtime dependencies, and no database connection

Three steps to a guarded repository

  1. Step 1: read a migration here

    Paste the one you are about to merge and see what comes back. No account, no database connection, nothing to install.

    pgguard scanpgguard 0.1.0
    0005_add_user_email.sql2 statements
    criticalPG0013:19

    email is NOT NULL with no DEFAULT on existing table users.

    ALTER TABLE users ADD COLUMN email text NOT NULL
    highPG0024:1

    Index built without CONCURRENTLY on users.

    CREATE INDEX idx_users_email ON users (email)
    mediumPG0143:1

    ALTER TABLE runs on users with no lock_timeout set first.

    ALTER TABLE users ADD COLUMN email text NOT NULL

    ✗ fail — 3 findings, 1 critical, 1 high, 1 medium

  2. Step 2: add the GitHub Action

    It scans the migrations a pull request changes and writes the findings into the review as a comment.

    payments/api · pull request #482Checks 1 failing
    pgguard commented 2 minutes ago

    pgguard found 3 issues in 1 migration file

    criticalPG001email is NOT NULL with no DEFAULT on existing table users.
    highPG002Index built without CONCURRENTLY on users.
    mediumPG014ALTER TABLE runs on users with no lock_timeout set first.

    ✗ pgguard / migrations — failing at threshold high

  3. Step 3: read the scan history

    Every scan the Action posts is kept, so a repository’s history reads as pass, fail, pass.

    pgguard · payments/apiScan history

    Runs

    add-user-email4f1c9a2 · 3 findings · 1 critical · 1 high · 1 medium
    main8b92e73 · no dangerous patterns
    maindb63a4d · no dangerous patterns
    index-concurrently25b9be5 · 1 finding · 1 high
    main1ed2efa · no dangerous patterns
    db/migrate/0005_add_user_email.sqlcommit 4f1c9a21 file, 2 statements
    criticalPG0013:19

    email is NOT NULL with no DEFAULT on existing table users.

    ALTER TABLE users ADD COLUMN email text NOT NULL
    highPG0024:1

    Index built without CONCURRENTLY on users.

    CREATE INDEX idx_users_email ON users (email)
    mediumPG0143:1

    ALTER TABLE runs on users with no lock_timeout set first.

    ALTER TABLE users ADD COLUMN email text NOT NULL

    ✗ fail — 3 findings, 1 critical, 1 high, 1 medium

4 of the 17 rules

Each finding names the statement, says what Postgres does with it, and prints the rewrite that avoids the lock. The other thirteen are in the rule reference.

critical

PG001 · Adds a NOT NULL column with no default

Postgres has no value for the rows that already exist, so the statement fails and the deploy fails with it.

pgguard scan0002_add_email.sql

critical PG001 3:19

Adds a NOT NULL column with no default

why Postgres has no value for the rows that already exist, so the statement fails and the deploy fails with it.

fix Give it a constant default in the same statement; since Postgres 11 that is metadata only.

exit 1

high

PG002 · Builds an index without CONCURRENTLY

CREATE INDEX idx_users_emailON users (email);

fixAdd CONCURRENTLY and keep the statement out of a transaction block.

critical

PG011 · Runs VACUUM FULL on a live table

VACUUM FULL order_items;

fixUse pg_repack, which does the same work without holding the table.

medium

PG016 · Backfills inside the migration transaction

migrations.RunPython(backfill)# atomic = False is not set

fixSet atomic = False and update in batches, each in its own transaction.

Reads the migrations you already write

Raw SQL, Prisma and Django, each parsed properly: a rule never fires on a statement that only appears inside a comment or a string.

Django is read as operations too, not only as raw SQL, so an AddIndex or a RunPython backfill is caught without a line of SQL in the file.

Pricing

The checker is free on one repository. The history and the alerts are the paid part.

Free

$0one repository, for as long as you want it

  • The scanner on this page, and the GitHub Action
  • All 17 rules, raw SQL, Prisma and Django
  • Findings posted on the pull request
  • The repository you connect is the one you keep
GitHub ActionsPostgreSQLRuns in your Action, reads your migrations

Team

$29a project a month, billed through Paddle

  • Everything in Free, on as many repositories as you connect
  • Scan history and the pass or fail trend per repository
  • Slack and email alerts on high-severity findings
SlackResendHigh-severity findings to Slack and email

Questions

The checker is free. What exactly am I paying for?
Not the checking. One repository is read for nothing, for as long as you want it, and the scanner on this page asks for no account at all. The paid part is what a single run cannot do: keep every scan, show how a repository has gone over the last fortnight, put a critical finding in Slack and in your inbox the minute it appears, and do all of that across every repository you have rather than one.
Does pgguard connect to my database?
No. It reads the SQL in your repository, so there is nothing to open a port for and no credentials to hand over.
What does it do with a migration it cannot parse?
It says so for that file and carries on with the rest. It never reports a file it did not read as passing.
Can I turn a rule off?
Yes. Pass --disable PG005,PG014, or set a severity of your own per rule in the config file.
Does the free plan expire?
No. One repository stays free for as long as you want it, and the scanner on this page needs no account. The repository you connect is the one that slot belongs to, so pick the one that matters.
Which Postgres versions do the rules assume?
Eleven and newer, where a constant default on ADD COLUMN stopped rewriting the whole table.