File size: 52,114 Bytes
fb510c7
05e9df5
 
 
 
44945a6
 
05e9df5
 
 
 
 
 
 
 
 
 
 
 
 
 
44945a6
05e9df5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8313cb5
44945a6
05e9df5
44945a6
 
 
 
 
05e9df5
8313cb5
 
 
 
44945a6
 
 
 
 
 
 
 
 
fb510c7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>Postgres Migration Lock check — check migration locks free</title>
<meta name="description" content="This browser tool finds migration statements in Rails, Django, or SQL that take a table-blocking Postgres lock and shows a safe rewrite.">
<style>
:root{color-scheme:light}body{margin:0;font:15px/1.55 system-ui,-apple-system,"Segoe UI",sans-serif;background:#faf9f5;color:#1a1512}
.wrap{max-width:960px;margin:0 auto;padding:28px 18px 60px}h1{font-size:26px;margin:0 0 6px}.lede{color:#4a403a;margin:0 0 16px}
textarea{width:100%;min-height:260px;font:13px/1.45 ui-monospace,Menlo,Consolas,monospace;padding:12px;border:1px solid #d9d0c4;border-radius:8px;box-sizing:border-box}
.bar{display:flex;gap:10px;align-items:center;margin:12px 0}button{font:600 15px system-ui;padding:10px 18px;border:0;border-radius:8px;background:#1a1512;color:#fff;cursor:pointer}
input[type=date]{font:14px system-ui;padding:8px;border:1px solid #d9d0c4;border-radius:6px}
table{border-collapse:collapse;width:100%;font-size:14px;margin-top:10px}th,td{text-align:left;padding:8px 10px;border-bottom:1px solid #eee;vertical-align:top}th{font-size:12px;letter-spacing:.06em;text-transform:uppercase;color:#7a6e65}
.sev.error{color:#a8551f;font-weight:700}.sev.warn,.sev.warning{color:#96691f}.ok{color:#2a6446;font-weight:600}.sum{font-weight:600}
.note{font-size:13px;color:#7a6e65;margin-top:18px}#paid{margin-top:22px;padding:14px 16px;border:1px solid #e2d8cb;border-radius:10px;background:#fffdfa}
</style>
<script data-grow-initializer="">!(function(){window.growMe||((window.growMe=function(e){window.growMe._.push(e);}),(window.growMe._=[]));var e=document.createElement("script");(e.type="text/javascript"),(e.src="https://faves.grow.me/main.js"),(e.defer=!0),e.setAttribute("data-grow-faves-site-id","U2l0ZTphZjljMzgyMC0yMmU5LTRhYjgtYTIxNS03OTRhMGY1N2ExYzM=");var t=document.getElementsByTagName("script")[0];t.parentNode.insertBefore(e,t);})();</script>
<!--yj-canon-s101--><link rel="canonical" href="https://getreadystack.com/tools/pg-migration-lock-lint"></head>
<body>
<div class="wrap">
<h1>Postgres Migration Lock check — check migration locks free</h1>
<p class="lede">Find the statements in your Rails, Django or raw SQL migrations that take a table-blocking Postgres lock - and the safe rewrite - before you deploy. Runs entirely in your browser — nothing is uploaded.</p>
<textarea id="src" spellcheck="false">-- orders: add tenancy + tighten money columns (generated, reviewed by nobody)
BEGIN;

ALTER TABLE orders ADD COLUMN tenant_id bigint NOT NULL;
ALTER TABLE orders ADD COLUMN external_ref text UNIQUE;
ALTER TABLE orders ADD COLUMN imported_at timestamptz DEFAULT now();
ALTER TABLE orders ALTER COLUMN amount_cents TYPE numeric(12,2);
ALTER TABLE orders ALTER COLUMN currency SET NOT NULL;
ALTER TABLE orders ADD CONSTRAINT orders_tenant_fk FOREIGN KEY (tenant_id) REFERENCES tenants (id);
ALTER TABLE orders ADD CONSTRAINT orders_amount_positive CHECK (amount_cents &gt; 0);
ALTER TABLE orders ADD CONSTRAINT orders_ref_uniq UNIQUE (external_ref);
ALTER TABLE orders RENAME COLUMN legacy_total TO total_cents;
ALTER TABLE orders DROP COLUMN legacy_notes;

CREATE INDEX idx_orders_tenant ON orders (tenant_id);
CREATE INDEX CONCURRENTLY idx_orders_created ON orders (created_at);
DROP INDEX idx_orders_old_ref;
REINDEX TABLE orders;
CLUSTER orders USING idx_orders_tenant;

LOCK TABLE orders;
UPDATE orders SET tenant_id = 1;
DELETE FROM order_events;
TRUNCATE order_archive;
VACUUM FULL orders;

COMMIT;</textarea>
<div class="bar"><button id="go">Check</button><label>as of <input type="date" id="today"></label></div>
<div id="out" aria-live="polite"></div>
<div id="paid"><strong>Free here:</strong> Audit the migration file you have open and name every statement that takes a blocking Postgres lock, with the safe rewrite for your framework.. <strong>In the editor:</strong> Audit every migration in the workspace in one pass and export the review as Markdown or JSON to attach to the change ticket, with a CI exit-code gate for the team. — that part asks for a licence key.</div>
<p class="note">Same engine as the VS Code extension, byte for byte.</p>
</div>
<script>var PGML_RULES = [
  {
    "id": "create_index_blocking",
    "sev": "error",
    "on": "stmt",
    "pattern": "\\bCREATE\\s+(UNIQUE\\s+)?INDEX\\b",
    "absent": "\\bCONCURRENTLY\\b",
    "msg": "CREATE INDEX holds a SHARE lock: every INSERT, UPDATE and DELETE on the table waits until the index finishes. Safe: CREATE INDEX CONCURRENTLY, outside any transaction block."
  },
  {
    "id": "drop_index_blocking",
    "sev": "error",
    "on": "stmt",
    "pattern": "\\bDROP\\s+INDEX\\b",
    "absent": "\\bCONCURRENTLY\\b",
    "msg": "DROP INDEX takes ACCESS EXCLUSIVE on the table, so reads block too. Safe: DROP INDEX CONCURRENTLY."
  },
  {
    "id": "concurrently_inside_transaction",
    "sev": "error",
    "on": "file",
    "pattern": "\\bCONCURRENTLY\\b",
    "require": "^\\s*BEGIN\\s*;|\\bSTART\\s+TRANSACTION\\b",
    "msg": "CREATE/DROP INDEX CONCURRENTLY cannot run inside a transaction block and will abort with error 25001. Safe: move it out of the BEGIN/COMMIT, one statement per migration."
  },
  {
    "id": "add_column_volatile_default",
    "sev": "error",
    "on": "stmt",
    "pattern": "\\bADD\\s+(COLUMN\\s+)?",
    "present": "\\bDEFAULT\\s+(now\\s*\\(|current_timestamp|clock_timestamp|random\\s*\\(|gen_random_uuid|uuid_generate|nextval)",
    "msg": "A volatile DEFAULT rewrites every row under ACCESS EXCLUSIVE - the fast path added in PG 11 only covers constant defaults. Safe: add the column with no default, backfill in batches, then SET DEFAULT."
  },
  {
    "id": "add_column_not_null_no_default",
    "sev": "error",
    "on": "stmt",
    "pattern": "\\bADD\\s+(COLUMN\\s+)?(?!CONSTRAINT\\b)[\"\\w]+[^,;()]*\\bNOT\\s+NULL\\b",
    "absent": "\\bDEFAULT\\b",
    "msg": "ADD COLUMN ... NOT NULL with no DEFAULT fails outright on a table that already has rows (23502). Safe: give it a constant DEFAULT, or add it nullable and SET NOT NULL after a validated CHECK."
  },
  {
    "id": "add_column_unique",
    "sev": "error",
    "on": "stmt",
    "pattern": "\\bADD\\s+(COLUMN\\s+)?(?!CONSTRAINT\\b)[\"\\w]+[^,;()]*\\bUNIQUE\\b",
    "msg": "UNIQUE on ADD COLUMN builds a unique index while ACCESS EXCLUSIVE is still held, so writes and reads both stop. Safe: CREATE UNIQUE INDEX CONCURRENTLY, then ADD CONSTRAINT ... USING INDEX."
  },
  {
    "id": "alter_column_type",
    "sev": "error",
    "on": "stmt",
    "pattern": "\\bALTER\\s+(COLUMN\\s+)?[\"\\w]+\\s+(SET\\s+DATA\\s+)?TYPE\\b",
    "msg": "Changing a column type rewrites the whole table and every index on it under ACCESS EXCLUSIVE. Safe: add a new column, backfill in batches, swap the reads, then drop the old column in a later deploy."
  },
  {
    "id": "set_not_null_scan",
    "sev": "warn",
    "on": "stmt",
    "pattern": "\\bSET\\s+NOT\\s+NULL\\b",
    "msg": "SET NOT NULL scans the whole table under ACCESS EXCLUSIVE. PG 12 and later skip that scan only when a validated CHECK (col IS NOT NULL) already exists. Safe: ADD CONSTRAINT ... CHECK (col IS NOT NULL) NOT VALID, VALIDATE CONSTRAINT, then SET NOT NULL."
  },
  {
    "id": "add_foreign_key_validating",
    "sev": "error",
    "on": "stmt",
    "pattern": "\\bADD\\s+(CONSTRAINT\\s+[\"\\w]+\\s+)?FOREIGN\\s+KEY\\b",
    "absent": "\\bNOT\\s+VALID\\b",
    "msg": "A validating FOREIGN KEY locks both tables (ACCESS EXCLUSIVE on the child, SHARE ROW EXCLUSIVE on the parent) while it scans. Safe: ADD CONSTRAINT ... NOT VALID, then VALIDATE CONSTRAINT in a second statement."
  },
  {
    "id": "add_check_validating",
    "sev": "error",
    "on": "stmt",
    "pattern": "\\bADD\\s+(CONSTRAINT\\s+[\"\\w]+\\s+)?CHECK\\s*\\(",
    "absent": "\\bNOT\\s+VALID\\b",
    "msg": "A validating CHECK constraint scans the table under ACCESS EXCLUSIVE. Safe: ADD CONSTRAINT ... CHECK (...) NOT VALID, then VALIDATE CONSTRAINT, which only needs SHARE UPDATE EXCLUSIVE."
  },
  {
    "id": "add_pk_or_unique_constraint",
    "sev": "error",
    "on": "stmt",
    "pattern": "\\bADD\\s+(CONSTRAINT\\s+[\"\\w]+\\s+)?(PRIMARY\\s+KEY|UNIQUE)\\s*\\(",
    "absent": "\\bUSING\\s+INDEX\\b",
    "msg": "This builds the backing index inside the ACCESS EXCLUSIVE lock. Safe: CREATE UNIQUE INDEX CONCURRENTLY first, then ADD CONSTRAINT ... USING INDEX, which only attaches the finished index."
  },
  {
    "id": "rename_breaks_running_code",
    "sev": "warn",
    "on": "stmt",
    "pattern": "\\bRENAME\\s+(COLUMN\\s+|TO\\b)",
    "msg": "The rename itself is instant, but the old pods are still sending the old name and start erroring at 42703 the moment it commits. Safe: add the new name, write to both, migrate readers, drop the old name a deploy later."
  },
  {
    "id": "drop_column_breaks_running_code",
    "sev": "warn",
    "on": "stmt",
    "pattern": "\\bDROP\\s+COLUMN\\b",
    "msg": "DROP COLUMN is metadata-only, but any SELECT * cached by the still-running old release breaks on commit. Safe: stop referencing the column in a shipped release first (Rails: ignored_columns), then drop it."
  },
  {
    "id": "vacuum_full_blocking",
    "sev": "error",
    "on": "stmt",
    "pattern": "\\bVACUUM\\s+FULL\\b",
    "msg": "VACUUM FULL holds ACCESS EXCLUSIVE for the whole rewrite and needs room for a second copy of the table. Safe: leave it out of the migration; use pg_repack or plain VACUUM."
  },
  {
    "id": "reindex_blocking",
    "sev": "error",
    "on": "stmt",
    "pattern": "\\bREINDEX\\b",
    "absent": "\\bCONCURRENTLY\\b",
    "msg": "REINDEX blocks writes on the table (and reads on the index) until it finishes. Safe: REINDEX CONCURRENTLY, available since PG 12."
  },
  {
    "id": "cluster_blocking",
    "sev": "error",
    "on": "stmt",
    "pattern": "\\bCLUSTER\\b\\s+[\"\\w]",
    "msg": "CLUSTER holds ACCESS EXCLUSIVE while it rewrites the table in index order - nothing reads it meanwhile. Safe: do not put CLUSTER in a migration."
  },
  {
    "id": "truncate_in_migration",
    "sev": "error",
    "on": "stmt",
    "pattern": "\\bTRUNCATE\\b",
    "msg": "TRUNCATE takes ACCESS EXCLUSIVE and deletes rows no backfill can bring back. Safe: DELETE in batches with a WHERE, or move the cleanup out of the migration."
  },
  {
    "id": "explicit_lock_table",
    "sev": "warn",
    "on": "stmt",
    "pattern": "\\bLOCK\\s+(TABLE\\s+)?[\"\\w]",
    "msg": "LOCK TABLE defaults to ACCESS EXCLUSIVE, the strongest mode there is. Safe: name the weakest mode you actually need (IN SHARE UPDATE EXCLUSIVE MODE) and set a lock_timeout."
  },
  {
    "id": "unbounded_backfill",
    "sev": "error",
    "on": "stmt",
    "pattern": "\\bUPDATE\\s+[\"\\w.]+\\s+SET\\b",
    "absent": "\\bWHERE\\b",
    "msg": "An UPDATE with no WHERE takes a row lock on every row in one transaction and blocks writers behind it for the whole run. Safe: loop over primary-key ranges, committing each batch."
  },
  {
    "id": "delete_unbounded",
    "sev": "warn",
    "on": "stmt",
    "pattern": "\\bDELETE\\s+FROM\\s+[\"\\w.]+",
    "absent": "\\bWHERE\\b",
    "msg": "DELETE with no WHERE writes a dead tuple for every row and holds them all in one transaction. Safe: delete in batches with a WHERE, or use a partition drop."
  },
  {
    "id": "no_lock_timeout",
    "sev": "error",
    "on": "file",
    "pattern": "\\b(ALTER\\s+TABLE|CREATE\\s+(UNIQUE\\s+)?INDEX)\\b",
    "require": ";",
    "absent": "lock_timeout",
    "msg": "No lock_timeout in this migration. If the DDL queues behind one long SELECT, every query that arrives after it queues behind the DDL - that is the outage, not the DDL itself. Safe: SET lock_timeout = '3s'; and retry."
  },
  {
    "id": "ddl_and_backfill_same_transaction",
    "sev": "warn",
    "on": "file",
    "pattern": "\\b(UPDATE|INSERT\\s+INTO)\\b",
    "require": "^\\s*BEGIN\\s*;[\\s\\S]*\\bALTER\\s+TABLE\\b",
    "msg": "A backfill in the same transaction as the DDL keeps the ACCESS EXCLUSIVE lock for as long as the backfill runs. Safe: one transaction for the DDL, a separate batched job for the data."
  },
  {
    "id": "rails_add_index_blocking",
    "sev": "error",
    "on": "line",
    "pattern": "\\badd_index\\b",
    "absent": "algorithm:\\s*:concurrently",
    "msg": "add_index builds the index with a SHARE lock and blocks writes. Safe: add_index ..., algorithm: :concurrently, plus disable_ddl_transaction! on the migration class."
  },
  {
    "id": "rails_add_reference_index",
    "sev": "error",
    "on": "line",
    "pattern": "\\badd_(reference|belongs_to)\\b",
    "absent": "index:\\s*false|algorithm:\\s*:concurrently",
    "msg": "add_reference creates its index the blocking way by default. Safe: add_reference ..., index: false, then add_index with algorithm: :concurrently."
  },
  {
    "id": "rails_change_column",
    "sev": "error",
    "on": "line",
    "pattern": "\\bchange_column\\s*[( ]",
    "msg": "change_column emits ALTER COLUMN TYPE, which rewrites the table under ACCESS EXCLUSIVE. Safe: new column, batched backfill, swap readers, drop the old one later."
  },
  {
    "id": "rails_change_column_null",
    "sev": "warn",
    "on": "line",
    "pattern": "\\bchange_column_null\\b",
    "msg": "change_column_null(false) emits SET NOT NULL and scans the table. Safe: add a CHECK ... NOT VALID, validate it, then set the column NOT NULL."
  },
  {
    "id": "rails_remove_column",
    "sev": "warn",
    "on": "line",
    "pattern": "\\bremove_columns?\\b",
    "msg": "Removing a column breaks the release that is still running and still selecting it. Safe: ship self.ignored_columns += [...] first, then remove the column in the next deploy."
  },
  {
    "id": "rails_rename",
    "sev": "warn",
    "on": "line",
    "pattern": "\\brename_(column|table)\\b",
    "msg": "A rename breaks every pod of the old release the instant it commits. Safe: add the new name, write to both, move readers, drop the old name in a later migration."
  },
  {
    "id": "rails_add_foreign_key",
    "sev": "error",
    "on": "line",
    "pattern": "\\badd_foreign_key\\b",
    "absent": "validate:\\s*false",
    "msg": "add_foreign_key validates existing rows while holding locks on both tables. Safe: add_foreign_key ..., validate: false, then validate_foreign_key in a second migration."
  },
  {
    "id": "rails_concurrently_needs_disable_ddl",
    "sev": "error",
    "on": "file",
    "pattern": "algorithm:\\s*:concurrently",
    "absent": "disable_ddl_transaction!",
    "msg": "algorithm: :concurrently inside Rails' automatic transaction aborts with 25001. Safe: add disable_ddl_transaction! at the top of the migration class."
  },
  {
    "id": "django_add_index_blocking",
    "sev": "error",
    "on": "line",
    "pattern": "migrations\\.AddIndex\\(",
    "msg": "AddIndex emits a plain CREATE INDEX and blocks writes. Safe: AddIndexConcurrently from django.contrib.postgres.operations, with atomic = False on the Migration class."
  },
  {
    "id": "django_alter_field",
    "sev": "error",
    "on": "line",
    "pattern": "migrations\\.AlterField\\(",
    "msg": "AlterField can emit ALTER COLUMN TYPE or SET NOT NULL - both scan or rewrite the table under ACCESS EXCLUSIVE. Safe: run sqlmigrate on it first and split the change across two deploys."
  },
  {
    "id": "django_rename",
    "sev": "warn",
    "on": "line",
    "pattern": "migrations\\.Rename(Field|Model)\\(",
    "msg": "A rename breaks the web workers still running the old code. Safe: add the new field, write to both, move readers, then remove the old field."
  },
  {
    "id": "django_remove",
    "sev": "warn",
    "on": "line",
    "pattern": "migrations\\.Remove(Field|Model)\\(",
    "msg": "Removing a field breaks the old release that is still selecting it. Safe: stop referencing it in a shipped release, then remove it in the next migration."
  },
  {
    "id": "django_runpython_atomic",
    "sev": "warn",
    "on": "file",
    "pattern": "migrations\\.RunPython\\(",
    "absent": "atomic\\s*=\\s*False",
    "msg": "RunPython inside an atomic migration holds every lock the schema operations took for the whole data pass. Safe: atomic = False on the Migration class and commit the backfill in batches."
  },
  {
    "id": "django_concurrently_needs_non_atomic",
    "sev": "error",
    "on": "file",
    "pattern": "(AddIndexConcurrently|RemoveIndexConcurrently)\\(",
    "absent": "atomic\\s*=\\s*False",
    "msg": "AddIndexConcurrently in an atomic migration aborts with 25001. Safe: set atomic = False on the Migration class."
  }
];</script>
<script>'use strict';
// Postgres Migration Lock Lint - one brain, used by the VS Code extension and by the free web page.
// Rules live in rules.json so the same file can be read by node or injected into the browser page.
var PGML_DOC = (typeof module !== 'undefined') ? require('./rules.json') : window.PGML_RULES;
var PGML_RULE_LIST = Array.isArray(PGML_DOC) ? PGML_DOC : PGML_DOC.rules;
var PGML_TARGET_PG = 'PostgreSQL 12-17';

// Blank out comments without moving any character, so reported line numbers stay exact.
function pgmlStrip(text) {
  function blank(m) { return m.replace(/[^\n]/g, ' '); }
  return String(text)
    .replace(/\/\*[\s\S]*?\*\//g, blank)
    .replace(/--[^\n]*/g, blank)
    .replace(/^[ \t]*#[^\n]*/gm, blank);
}

function pgmlLineAt(text, offset) {
  var n = 1;
  for (var i = 0; i < offset && i < text.length; i++) {
    if (text.charCodeAt(i) === 10) { n++; }
  }
  return n;
}

// SQL is graded per statement (a statement can span many lines); frameworks are graded per line.
function pgmlStatements(text) {
  var out = [], start = 0;
  for (var i = 0; i <= text.length; i++) {
    if (i === text.length || text.charAt(i) === ';') {
      var raw = text.slice(start, i);
      if (raw.trim()) { out.push({ text: raw, offset: start }); }
      start = i + 1;
    }
  }
  return out;
}

function pgmlCheck(text, opts) {
  opts = opts || {};
  var src = pgmlStrip(text == null ? '' : text);
  var stmts = pgmlStatements(src);
  var lines = src.split(/\r?\n/);
  var findings = [], seen = {};

  function push(rule, line) {
    var key = rule.id + '@' + line;
    if (seen[key]) { return; }
    seen[key] = 1;
    findings.push({ check: rule.id, sev: rule.sev, msg: rule.msg, line: line });
  }
  function rx(pattern, flags) { return new RegExp(pattern, flags); }

  for (var r = 0; r < PGML_RULE_LIST.length; r++) {
    var rule = PGML_RULE_LIST[r];
    var pf = rule.flags || 'i', af = 'im';
    if (rule.on === 'file') {
      if (rule.require && !rx(rule.require, af).test(src)) { continue; }
      var fm = rx(rule.pattern, pf).exec(src);
      if (!fm) { continue; }
      if (rule.absent && rx(rule.absent, af).test(src)) { continue; }
      push(rule, pgmlLineAt(src, fm.index));
    } else if (rule.on === 'line') {
      for (var i = 0; i < lines.length; i++) {
        var lm = rx(rule.pattern, pf).exec(lines[i]);
        if (!lm) { continue; }
        if (rule.absent && rx(rule.absent, af).test(lines[i])) { continue; }
        if (rule.present && !rx(rule.present, af).test(lines[i])) { continue; }
        push(rule, i + 1);
      }
    } else {
      for (var s = 0; s < stmts.length; s++) {
        var st = stmts[s];
        var sm = rx(rule.pattern, pf).exec(st.text);
        if (!sm) { continue; }
        if (rule.absent && rx(rule.absent, af).test(st.text)) { continue; }
        if (rule.present && !rx(rule.present, af).test(st.text)) { continue; }
        push(rule, pgmlLineAt(src, st.offset + sm.index));
      }
    }
  }
  findings.sort(function (a, b) {
    return (a.line - b.line) || (a.check < b.check ? -1 : a.check > b.check ? 1 : 0);
  });
  return { findings: findings, rule_count: PGML_RULE_LIST.length, target_pg: PGML_TARGET_PG };
}

var PGML_API = { engine: { check: pgmlCheck }, RULES: PGML_RULE_LIST, RULE_COUNT: PGML_RULE_LIST.length };
if (typeof module !== 'undefined' && module.exports) { module.exports = PGML_API; }
if (typeof window !== 'undefined') { window.PGMLENGINE = PGML_API; }
</script>
<script>// ⛔뼈대 — kit/scaffold.py 가 찍는다 (s143). findings [{check,sev,msg,line?}] → 글/HTML. 같은 파일이 Node 와 브라우저에서 산다.
'use strict';
function escapeHtml(s) { return String(s == null ? '' : s).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;'); }
function summaryLine(res) {
  const f = (res && res.findings) || []; const e = f.filter(function (x) { return String(x.sev || 'error').toLowerCase().startsWith('err'); }).length;
  return f.length ? (f.length + ' finding' + (f.length === 1 ? '' : 's') + ' (' + e + ' error' + (e === 1 ? '' : 's') + ')') : 'Clean — no findings.';
}
function toText(res, label) {
  const f = (res && res.findings) || [];
  const lines = ['== ' + (label || '') + ' — ' + summaryLine(res)];
  f.forEach(function (x) { lines.push('  ' + String(x.sev || 'error').toUpperCase().slice(0, 4) + '  ' + (x.line ? 'L' + x.line + '  ' : '') + (x.check || x.id || '') + '  ' + (x.msg || x.message || '')); });
  return lines.join('\n');
}
function toHtml(res) {
  const f = (res && res.findings) || [];
  if (!f.length) return '<p class="ok">' + escapeHtml(summaryLine(res)) + '</p>';
  const rows = f.map(function (x) { return '<tr><td class="sev ' + escapeHtml(String(x.sev || 'error')) + '">' + escapeHtml(String(x.sev || 'error')) + '</td><td>' + (x.line ? 'L' + escapeHtml(x.line) : '') + '</td><td><code>' + escapeHtml(x.check || x.id || '') + '</code></td><td>' + escapeHtml(x.msg || x.message || '') + '</td></tr>'; }).join('');
  return '<p class="sum">' + escapeHtml(summaryLine(res)) + '</p><table><thead><tr><th>Level</th><th>Line</th><th>Check</th><th>What</th></tr></thead><tbody>' + rows + '</tbody></table>';
}
var PGMLREPORT = { escapeHtml: escapeHtml, summaryLine: summaryLine, toText: toText, toHtml: toHtml };
if (typeof module !== 'undefined' && module.exports) module.exports = PGMLREPORT;
else window.PGMLREPORT = PGMLREPORT;
</script>
<script>
(function(){
  var src=document.getElementById('src'), out=document.getElementById('out'), go=document.getElementById('go'), today=document.getElementById('today');
  today.value=new Date().toISOString().slice(0,10);
  function run(){ try { var res=window.PGMLENGINE.engine.check(src.value,{today:today.value}); out.innerHTML=window.PGMLREPORT.toHtml(res); } catch(e){ out.innerHTML='<p class="sev error">Could not run: '+String(e.message||e)+'</p>'; } }
  go.onclick=run; if (src.value.trim()) run();
})();
</script>


<section data-yj-install="free" style="margin:2rem auto 1rem;max-width:46rem;padding:1.25rem 1.25rem;border:1px solid #cfe3d6;border-radius:12px;background:#f6fbf8;font:16px/1.6 system-ui,-apple-system,Segoe UI,sans-serif"><h2 style="margin:0 0 .4rem;font-size:1.2rem">Install free</h2><p style="margin:0 0 .8rem;color:#41505f">Free for the file open in your editor - no key, no limit. The workspace sweep and the report ask for a key.</p><a href="https://marketplace.visualstudio.com/items?itemName=ReadyStack.pg-migration-lock-lint" rel="noopener" data-yj-install-door="mp" onclick="try{navigator.sendBeacon('/api/ev',new Blob([JSON.stringify({t:'install',slug:'pg-migration-lock-lint',src:'mp',path:location.pathname})],{type:'application/json'}))}catch(e){}" style="display:inline-block;margin:0 .5rem .5rem 0;padding:.6rem 1rem;border-radius:8px;background:#0f7b3f;color:#fff;text-decoration:none;font-weight:600">VS Code Marketplace</a><a href="https://open-vsx.org/extension/readystack/pg-migration-lock-lint" rel="noopener" data-yj-install-door="ovsx" onclick="try{navigator.sendBeacon('/api/ev',new Blob([JSON.stringify({t:'install',slug:'pg-migration-lock-lint',src:'ovsx',path:location.pathname})],{type:'application/json'}))}catch(e){}" style="display:inline-block;margin:0 .5rem .5rem 0;padding:.6rem 1rem;border-radius:8px;background:#0f7b3f;color:#fff;text-decoration:none;font-weight:600">Open VSX (Cursor, VSCodium)</a><a href="https://www.npmjs.com/package/@readystack/pg-migration-lock-lint" rel="noopener" data-yj-install-door="npm" onclick="try{navigator.sendBeacon('/api/ev',new Blob([JSON.stringify({t:'install',slug:'pg-migration-lock-lint',src:'npm',path:location.pathname})],{type:'application/json'}))}catch(e){}" style="display:inline-block;margin:0 .5rem .5rem 0;padding:.6rem 1rem;border-radius:8px;background:#0f7b3f;color:#fff;text-decoration:none;font-weight:600">npm</a><a href="https://www.npmjs.com/package/@readystack/pg-migration-lock-lint" rel="noopener" data-yj-install-door="mcp" onclick="try{navigator.sendBeacon('/api/ev',new Blob([JSON.stringify({t:'install',slug:'pg-migration-lock-lint',src:'mcp',path:location.pathname})],{type:'application/json'}))}catch(e){}" style="display:inline-block;margin:0 .5rem .5rem 0;padding:.6rem 1rem;border-radius:8px;background:#0f7b3f;color:#fff;text-decoration:none;font-weight:600">MCP server (npx)</a><a href="https://hub.docker.com/r/getreadystack/pg-migration-lock-lint" rel="noopener" data-yj-install-door="docker" onclick="try{navigator.sendBeacon('/api/ev',new Blob([JSON.stringify({t:'install',slug:'pg-migration-lock-lint',src:'docker',path:location.pathname})],{type:'application/json'}))}catch(e){}" style="display:inline-block;margin:0 .5rem .5rem 0;padding:.6rem 1rem;border-radius:8px;background:#0f7b3f;color:#fff;text-decoration:none;font-weight:600">Docker Hub</a><pre style="margin:.5rem 0 0;padding:.6rem .8rem;background:#f3f5f8;border-radius:8px;font-size:.9rem;overflow:auto">ext install ReadyStack.pg-migration-lock-lint
npx @readystack/pg-migration-lock-lint &lt;file&gt;
npx @readystack/pg-migration-lock-lint --mcp</pre><p style="margin:.6rem 0 0;font-size:.92rem;color:#41505f"><a href="https://getreadystack.com/api/buy/cl/polar_cl_l6iN1uWt0FwWu7tBsczD0jWpP2vxFM54Wdwqb3KPi1G" rel="nofollow" style="color:#0f7b3f;text-decoration:underline">Team? One key for every ReadyStack linter, 5 seats, $149 once</a></p></section>
<section data-yj-alert="rule" style="margin:1rem auto 1.5rem;max-width:46rem;padding:1.1rem 1.25rem;border:1px solid #d9dee6;border-radius:12px;background:#fbfcfd;font:15px/1.55 system-ui,-apple-system,Segoe UI,sans-serif"><b style="font-size:1.05rem">Get the full rule table as a PDF</b><div style="opacity:.78;margin:.35rem 0 .8rem">All 36 rules Postgres Migration Lock Lint checks, each with its source and date, on printable pages you can hand to your team or auditor. We email it now, and once more only if a rule changes. No newsletter.</div><div style="display:flex;gap:8px;flex-wrap:wrap"><input id="yjae" type="email" placeholder="you@example.com" style="flex:1;min-width:210px;padding:11px 13px;border:1px solid rgba(140,150,165,.34);border-radius:8px;background:#fff;color:inherit"><button id="yjab" style="padding:11px 18px;border-radius:8px;border:0;cursor:pointer;background:#0f7b3f;color:#fff;font:600 15px system-ui,sans-serif">Email me the PDF</button></div><div id="yjao" hidden style="margin-top:.6rem;color:#0f7b3f">Sent. It arrives within the hour - check spam too.</div><script>(function(){var b=document.getElementById("yjab"),e=document.getElementById("yjae");if(!b||!e)return;b.addEventListener("click",function(){var v=e.value.trim();if(!/.+@.+\..+/.test(v))return;try{localStorage.setItem("yj_em","1");}catch(_){}fetch(location.origin+"/api/subscribe",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({email:v,slug:"pg-migration-lock-lint",lang:"en",source:"rule_table"+((b.closest&&b.closest("section")&&b.closest("section").getAttribute("data-yj-moved"))?"_at_result":"")})}).then(function(r){var o=document.getElementById("yjao");o.hidden=false;if(!r.ok){o.textContent="Could not save - please try again.";}}).catch(function(){var o=document.getElementById("yjao");o.hidden=false;o.textContent="Could not save - please try again.";});});})();</script><script>(function(){var e=document.getElementById("yjae"),s=e&&e.closest?e.closest("section"):null,o=document.getElementById("out");if(!s||!o)return;var d=false;function mv(ev){if(d)return;if(ev&&ev.target&&s.contains(ev.target))return;d=true;var b=o;while(b.parentNode&&b.parentNode!==document.body&&b.parentNode.tagName!=="MAIN"&&b.parentNode.tagName!=="ARTICLE")b=b.parentNode;if(!b.parentNode||b===s||b.contains(s))return;try{b.parentNode.insertBefore(s,b.nextSibling);s.setAttribute("data-yj-moved","1");}catch(_){}}document.addEventListener("input",mv,true);document.addEventListener("change",mv,true);})();</script></section>

<section data-yj-cta="paid" style="margin:3rem auto;max-width:46rem;padding:1.5rem 1.25rem;border:1px solid #d8dee9;border-radius:12px;background:#fbfcfe;font:16px/1.6 system-ui,-apple-system,Segoe UI,sans-serif"><h2 style="margin:0 0 .5rem;font-size:1.25rem">Get the complete version <span class="yj-price">$29</span></h2><p style="margin:.25rem 0 1rem;color:#41505f">This page is the working piece. The full pack has everything below.</p><p style="margin:0 0 1rem;color:#41505f">Names every statement in a Rails, Django or raw SQL migration that takes a table-blocking Postgres lock, and prints the non-blocking rewrite. 36 rules, PostgreSQL 12-17.</p><p style="margin:0 0 1rem;color:#5b6b7c;font-size:.94rem">Independent Postgres consultancies bill migration and lock review at $150/hour and up; this is one review, priced once.</p><a href="https://getreadystack.com/api/buy/cl/polar_cl_zaJ9pwhlczNQZUXiIKP3wGCzfzxe2LYQ6mMD02xD1j5" rel="nofollow" style="display:inline-block;padding:.7rem 1.3rem;border-radius:8px;background:#1b64f2;color:#fff;text-decoration:none;font-weight:600">Buy the full version — $29</a></section>
<!--yj-share-s101--><div style="margin:28px 0 8px;text-align:center"><button id="yjcp" type="button" style="font:inherit;padding:10px 18px;border:1px solid #8884;border-radius:10px;background:transparent;cursor:pointer">Copy link</button><button id="yjimg" type="button" style="font:inherit;padding:10px 18px;margin-left:8px;border:1px solid #8884;border-radius:10px;background:transparent;cursor:pointer">Save result as image</button></div><script>(function(){var b=document.getElementById("yjimg");if(!b)return;b.addEventListener("click",function(){var o=document.getElementById("out");var txt=(o&&(o.innerText||o.textContent)||"").trim();if(!txt){b.textContent="(no result yet)";setTimeout(function(){b.textContent="Save result as image";},1500);return;}var lines=txt.split(String.fromCharCode(10)).filter(function(x){return x.trim();}).slice(0,10);var W=1200,P=56,c=document.createElement("canvas");c.width=W;var lh=38,H=P*2+70+lines.length*lh+60;c.height=H;var x=c.getContext("2d");x.fillStyle="#1a1512";x.fillRect(0,0,W,H);x.fillStyle="#f3e9d2";x.font="600 34px system-ui,Segoe UI,Arial";var t=(document.title||"").split("|")[0].trim();x.fillText(t.slice(0,54),P,P+34);x.font="22px ui-monospace,Menlo,Consolas,monospace";x.fillStyle="#e8dcc4";for(var i=0;i<lines.length;i++){x.fillText(lines[i].slice(0,88),P,P+70+i*lh+22);}x.font="600 22px system-ui,Segoe UI,Arial";x.fillStyle="#c9a227";var d=location.hostname.replace("www.","");x.fillText(d,W-P-x.measureText(d).width,H-P+6);c.toBlob(function(bl){var u=URL.createObjectURL(bl),a=document.createElement("a");a.href=u;a.download=(t||"result").replace(/[^a-z0-9]+/gi,"-").toLowerCase()+"-"+d+".png";document.body.appendChild(a);a.click();setTimeout(function(){URL.revokeObjectURL(u);a.remove();},2000);},"image/png");});})();</script><script>(function(){var b=document.getElementById("yjcp");if(!b)return;var t=b.textContent;b.addEventListener("click",function(){var u=location.href.split("#")[0];function d(){b.textContent="Link copied";setTimeout(function(){b.textContent=t;},1800);}if(navigator.clipboard&&navigator.clipboard.writeText){navigator.clipboard.writeText(u).then(d,function(){prompt("",u);});}else{prompt("",u);}});})();</script><div class="yj-home-find"><div class="yj-lgbar"><a href="/" class="yj-lg on">EN</a><a href="/de/" class="yj-lg">DE</a><a href="/ja/" class="yj-lg">JA</a><a href="/es/" class="yj-lg">ES</a><a href="/pt/" class="yj-lg">PT</a></div><section class="yj-find"><h2>Find a tool</h2><input id="yjq" type="search" autocomplete="off" placeholder="Type a product name, format or task"><div id="yjr"></div></section><style>.yj-lgbar{position:absolute;top:14px;right:18px;display:flex;gap:6px;z-index:60}.yj-lg{font:600 12px/1 system-ui,sans-serif;padding:6px 9px;border-radius:4px;text-decoration:none;color:#8b96a3;border:1px solid rgba(140,150,165,.28)}.yj-lg:hover{color:#e8eaed;border-color:rgba(160,175,195,.6)}.yj-lg.on{color:#0e1116;background:#cfd6de;border-color:#cfd6de}.yj-find{max-width:760px;margin:34px auto 8px;padding:0 20px}.yj-find h2{font:600 20px/1.3 system-ui,sans-serif;margin:0 0 10px}#yjq{width:100%;box-sizing:border-box;padding:13px 15px;font:400 15.5px system-ui,sans-serif;border:1px solid rgba(140,150,165,.34);border-radius:8px;background:rgba(255,255,255,.04);color:inherit}#yjq:focus{outline:none;border-color:#7FD1C4}#yjr{margin-top:10px;display:flex;flex-direction:column;gap:6px}#yjr a{display:flex;justify-content:space-between;gap:12px;padding:11px 14px;border:1px solid rgba(140,150,165,.22);border-radius:6px;text-decoration:none;font:400 14.5px/1.4 system-ui,sans-serif;color:inherit}#yjr a:hover{border-color:#7FD1C4}#yjr .pr{font:600 13px system-ui,sans-serif;color:#5fbf9a;white-space:nowrap}</style><script>(function(){var q=document.getElementById("yjq"),r=document.getElementById("yjr"),D=null;function load(){if(D)return Promise.resolve(D);return fetch("/search-index.json").then(function(x){return x.json();}).then(function(j){D=j;return j;}).catch(function(){D=[];return D;});}function esc(t){return String(t).replace(/[&<>"]/g,function(c){return {"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;"}[c];});}function run(){var v=q.value.trim().toLowerCase();if(v.length<2){r.innerHTML="";return;}load().then(function(j){var w=v.split(/\s+/),o=[];for(var i=0;i<j.length&&o.length<12;i++){var t=j[i].t.toLowerCase();var ok=true;for(var k=0;k<w.length;k++){if(t.indexOf(w[k])<0){ok=false;break;}}if(ok)o.push(j[i]);}r.innerHTML=o.length?o.map(function(x){return "<a href=\""+esc(x.u)+"\">"+"<span>"+esc(x.t)+"</span>"+(x.p?"<span class=\"pr\">$"+x.p+"</span>":"")+"</a>";}).join(""):"";});}q.addEventListener("input",run);q.addEventListener("focus",load);})();</script></div>


<script data-yj="yj-view-beacon">(function(){try{var p=location.pathname;var k='yjv:'+p;if(sessionStorage.getItem(k))return;sessionStorage.setItem(k,'1');fetch('/api/ev',{method:'POST',keepalive:true,headers:{'Content-Type':'application/json'},body:JSON.stringify({path:p,lang:"en",ref:(document.referrer||''),src:(function(){try{return (new URLSearchParams(location.search).get('ref')||'').replace(/[^a-z_]/g,'').slice(0,12)}catch(e){return ''}})()})}).catch(function(){});}catch(e){}})();</script>

<script data-yj="yj-use-beacon">(function(){try{var o=document.getElementById('out');if(!o)return;var p=location.pathname,k='yju:'+p,sent=false;function fire(){if(sent||sessionStorage.getItem(k))return;if(!(o.textContent||'').replace(/\s+/g,'').length)return;sent=true;sessionStorage.setItem(k,'1');fetch('/api/ev',{method:'POST',keepalive:true,headers:{'Content-Type':'application/json'},body:JSON.stringify({path:p,lang:"en",t:'use',src:(function(){try{return (new URLSearchParams(location.search).get('ref')||'').replace(/[^a-z_]/g,'').slice(0,12)}catch(e){return ''}})()})}).catch(function(){});}var mo=new MutationObserver(function(){fire();if(sent)mo.disconnect();});mo.observe(o,{childList:true,characterData:true,subtree:true});}catch(e){}})();</script>
<section data-yj="yj-facts-v1" style="max-width:920px;margin:48px auto 0;padding:0 20px;font-family:system-ui,sans-serif"><style>.yj-article p{font:400 15.5px/1.7 system-ui,sans-serif;color:#26313b;margin:0 0 12px;max-width:72ch}.yj-article h2,.yj-article h3,.yj-article h4{font:600 17px/1.35 system-ui,sans-serif;color:#1b1f24;margin:22px 0 8px}.yj-article table{border-collapse:collapse;margin:10px 0 16px;font:14px/1.45 system-ui,sans-serif}.yj-article th,.yj-article td{border:1px solid #e2e6ea;padding:6px 10px;text-align:left}.yj-article th{background:#f4f6f8}.yj-article pre{background:#0f1720;color:#e6edf3;padding:12px 14px;border-radius:8px;overflow:auto;font:13px/1.5 ui-monospace,Menlo,monospace}.yj-article code{font:13px ui-monospace,Menlo,monospace;background:#f1f3f5;padding:1px 4px;border-radius:3px}.yj-article pre code{background:none;padding:0}.yj-article ul,.yj-article ol{font:15px/1.6 system-ui,sans-serif;color:#26313b}</style><p style="font:400 13px/1.5 system-ui,sans-serif;color:#6b7680;margin:0 0 14px"><time datetime="2026-09-14">Updated 2026-09-14</time> · ReadyStack</p><script type="application/ld+json">{"@context":"https://schema.org","@type":"WebPage","dateModified":"2026-09-14","author":{"@type":"Organization","name":"ReadyStack"}}</script><h2 style="font:600 21px/1.3 system-ui,sans-serif;margin:0 0 6px;color:#1b1f24">Worked example</h2><p style="font:400 14.5px/1.5 system-ui,sans-serif;margin:0 0 16px;color:#5b6570">Real numbers from this tool, line by line.</p><div class="yj-article"><p><img src="https://getreadystack.com/img/promo/sku68909_result_card.jpg" alt="Postgres Migration Lock Lint" loading="lazy" style="max-width:100%;border-radius:6px"></p>
<p>22 findings in a 20-statement migration. That is what a Rails engineer on a live orders table gets back from the file an assistant wrote in four seconds.</p>
<p>The migration is unremarkable. Add a tenant_id column, tighten amount_cents to numeric(12,2), add a foreign key to tenants, add a unique constraint on external_ref, build an index on tenant_id, rename legacy_total, drop legacy_notes, backfill the new column, clear an events table. Twenty statements between BEGIN and COMMIT. Nothing in it is wrong SQL. Every statement runs. That is the problem: the lock behaviour is not in the text.</p>
<p>Sixteen of the 22 findings are at error severity, meaning writes stop or the statement aborts outright. ALTER COLUMN amount_cents TYPE numeric(12,2) rewrites the whole table and every index on it while holding ACCESS EXCLUSIVE. CREATE INDEX without CONCURRENTLY holds SHARE, so reads continue and every INSERT, UPDATE and DELETE waits for the build. ADD CONSTRAINT ... FOREIGN KEY without NOT VALID takes ACCESS EXCLUSIVE on the child table and SHARE ROW EXCLUSIVE on the parent while it scans existing rows. ADD COLUMN tenant_id bigint NOT NULL with no default does not block at all - it fails, SQLSTATE 23502, because the table already has rows. And CREATE INDEX CONCURRENTLY, the correct form, aborts with 25001 when it is sitting inside the BEGIN/COMMIT the generator wrapped everything in.</p>
<p>The finding that matters most is the one that is not a statement. There is no lock_timeout anywhere in the file. A DDL statement that cannot get its lock does not fail; it waits. And while it waits at the head of the lock queue, every query that arrives after it waits too, including the plain SELECTs that were perfectly compatible with whatever is already running. One analytics query holding a read lock plus one ALTER TABLE behind it is enough to make a healthy table unreadable. SET lock_timeout = &#x27;3s&#x27; turns that outage into a retry.</p>
<p>Version matters and the text does not tell you the version. ADD COLUMN x int DEFAULT 0 rewrote the table on PostgreSQL 10 and has been instant since 11, so flagging it now is noise - the rule set leaves it alone. SET NOT NULL skips its table scan on 12 and later, but only when a validated CHECK (x IS NOT NULL) already exists, which generated migrations almost never add first. REINDEX CONCURRENTLY exists from 12. Advice written before those releases is still what most of this code is imitating. PostgreSQL 14 receives its final minor release in November 2026, so a lot of teams are writing their 14-to-17 upgrade migrations right now.</p>
<p>The free tools each see one half of the problem. strong_migrations reads the Rails DSL and nothing else. squawk parses raw SQL and nothing else. Neither reads a Django operations list, where AddIndex, AlterField and a RunPython backfill inside an atomic migration carry exactly the same locks. Both run in CI, after the migration is already written, already committed, already in a pull request with three approvals.</p>
<p>Postgres Migration Lock Lint reads the file in the editor. 36 rules, one message each, naming the lock mode, the SQLSTATE where there is one, and the rewrite. Raw .sql, Rails ActiveRecord::Migration, Django migrations.Migration. The same schema change, split so nothing blocks - constant default, CHECK NOT VALID then VALIDATE, unique index built CONCURRENTLY then attached USING INDEX, a batched backfill with a WHERE - returns zero findings.</p>
<p>Free tier: the file you have open, all 36 rules. The same rules run in the browser on pasted text, with nothing uploaded, at getreadystack.com/tools/pg-migration-lock-lint.</p></div><h2 style="font:600 19px/1.3 system-ui,sans-serif;margin:30px 0 10px;color:#1b1f24">15 seconds — what it actually does</h2><video controls muted playsinline preload="none" poster="/img/promo/sku68909_result_card.jpg" style="width:100%;max-width:360px;border-radius:10px;display:block;margin:0 auto"><source src="/media/sku68909_short.mp4" type="video/mp4"></video><h2 style="font:600 21px/1.3 system-ui,sans-serif;margin:34px 0 6px;color:#1b1f24">Questions people ask</h2><details style="border-bottom:1px solid #e6e9ed;padding:10px 0"><summary style="cursor:pointer;font:600 15px/1.4 system-ui,sans-serif;color:#1b1f24">What does Postgres Migration Lock Lint actually do?</summary><p style="margin:8px 0 2px;font:400 14.5px/1.6 system-ui,sans-serif;color:#33404b">It reads a migration file and names every statement that takes a lock Postgres will not share, such as ACCESS EXCLUSIVE on a table rewrite or SHARE on a plain CREATE INDEX. 36 rules, PostgreSQL 12-17. On the bundled 20-statement sample migration it returns 22 findings, 16 of them at error severity; the hand-split version of the same schema change returns 0 findings.</p></details><details style="border-bottom:1px solid #e6e9ed;padding:10px 0"><summary style="cursor:pointer;font:600 15px/1.4 system-ui,sans-serif;color:#1b1f24">Who is this for?</summary><p style="margin:8px 0 2px;font:400 14.5px/1.6 system-ui,sans-serif;color:#33404b">Rails and Django engineers who deploy to a Postgres database that has real traffic, and anyone reviewing raw .sql migrations written by an assistant. It is aimed at the person who runs the deploy and gets paged when a table stops answering, not at a greenfield project where every table is empty.</p></details><details style="border-bottom:1px solid #e6e9ed;padding:10px 0"><summary style="cursor:pointer;font:600 15px/1.4 system-ui,sans-serif;color:#1b1f24">Why do free tools not cover this?</summary><p style="margin:8px 0 2px;font:400 14.5px/1.6 system-ui,sans-serif;color:#33404b">strong_migrations reads only the Rails DSL, squawk reads only raw SQL, and both run in CI after the migration is already in a pull request. Neither reads a Django operations list. This runs on the file in your editor, across all three formats, before the branch exists, and it knows which forms became safe in PostgreSQL 11 and 12.</p></details><details style="border-bottom:1px solid #e6e9ed;padding:10px 0"><summary style="cursor:pointer;font:600 15px/1.4 system-ui,sans-serif;color:#1b1f24">What is free and what needs the licence key?</summary><p style="margin:8px 0 2px;font:400 14.5px/1.6 system-ui,sans-serif;color:#33404b">Free: the migration file you have open, checked against all 36 rules, with the full message and the safe rewrite. No key, no limit on how often. The full version adds scope and ownership: every migration in the workspace in one pass, the review exported as Markdown or JSON for the change ticket, and an exit code for CI.</p></details><details style="border-bottom:1px solid #e6e9ed;padding:10px 0"><summary style="cursor:pointer;font:600 15px/1.4 system-ui,sans-serif;color:#1b1f24">What does the alternative cost?</summary><p style="margin:8px 0 2px;font:400 14.5px/1.6 system-ui,sans-serif;color:#33404b">Independent Postgres consultancies bill migration and lock review at $150 an hour and up, and an incident review costs more than that once on-call time is counted. This is $29 once,. The free tier covers the file you are editing right now at no cost at all.</p></details><details style="border-bottom:1px solid #e6e9ed;padding:10px 0"><summary style="cursor:pointer;font:600 15px/1.4 system-ui,sans-serif;color:#1b1f24">Why not just ask ChatGPT or another AI chat?</summary><p style="margin:8px 0 2px;font:400 14.5px/1.6 system-ui,sans-serif;color:#33404b">A general AI chat answers from training data with a cutoff date, cannot read your repository and names no rule version. Postgres Migration Lint - locks and downtime (ALTER TABLE, C checks the file you open against 36 rules from a rule set dated 2026-09-20, and points at the exact line. For a filing, an audit or a client you need that dated result on your own files.</p></details><script type="application/ld+json" data-yj="yj-faq-ld">{"@context": "https://schema.org", "@type": "FAQPage", "mainEntity": [{"@type": "Question", "name": "What does Postgres Migration Lock Lint actually do?", "acceptedAnswer": {"@type": "Answer", "text": "It reads a migration file and names every statement that takes a lock Postgres will not share, such as ACCESS EXCLUSIVE on a table rewrite or SHARE on a plain CREATE INDEX. 36 rules, PostgreSQL 12-17. On the bundled 20-statement sample migration it returns 22 findings, 16 of them at error severity; the hand-split version of the same schema change returns 0 findings."}}, {"@type": "Question", "name": "Who is this for?", "acceptedAnswer": {"@type": "Answer", "text": "Rails and Django engineers who deploy to a Postgres database that has real traffic, and anyone reviewing raw .sql migrations written by an assistant. It is aimed at the person who runs the deploy and gets paged when a table stops answering, not at a greenfield project where every table is empty."}}, {"@type": "Question", "name": "Why do free tools not cover this?", "acceptedAnswer": {"@type": "Answer", "text": "strong_migrations reads only the Rails DSL, squawk reads only raw SQL, and both run in CI after the migration is already in a pull request. Neither reads a Django operations list. This runs on the file in your editor, across all three formats, before the branch exists, and it knows which forms became safe in PostgreSQL 11 and 12."}}, {"@type": "Question", "name": "What is free and what needs the licence key?", "acceptedAnswer": {"@type": "Answer", "text": "Free: the migration file you have open, checked against all 36 rules, with the full message and the safe rewrite. No key, no limit on how often. The full version adds scope and ownership: every migration in the workspace in one pass, the review exported as Markdown or JSON for the change ticket, and an exit code for CI."}}, {"@type": "Question", "name": "What does the alternative cost?", "acceptedAnswer": {"@type": "Answer", "text": "Independent Postgres consultancies bill migration and lock review at $150 an hour and up, and an incident review costs more than that once on-call time is counted. This is $29 once,. The free tier covers the file you are editing right now at no cost at all."}}, {"@type": "Question", "name": "Why not just ask ChatGPT or another AI chat?", "acceptedAnswer": {"@type": "Answer", "text": "A general AI chat answers from training data with a cutoff date, cannot read your repository and names no rule version. Postgres Migration Lint - locks and downtime (ALTER TABLE, C checks the file you open against 36 rules from a rule set dated 2026-09-20, and points at the exact line. For a filing, an audit or a client you need that dated result on your own files."}}]}</script><div id="yj-ask" style="margin:36px 0 0;padding:18px 18px 16px;border:1px solid #e2e6ea;border-radius:10px;background:#fbfbfc"><h2 style="font:600 19px/1.3 system-ui,sans-serif;margin:0 0 4px;color:#1b1f24">Ask about this tool</h2><p style="font:400 13.5px/1.5 system-ui,sans-serif;margin:0 0 12px;color:#5b6570">One question, answered by the person who built it. Your email only if you want the answer sent.</p><form onsubmit="return yjAsk(event)" style="display:grid;gap:8px"><textarea name="question" required minlength="10" maxlength="2000" rows="3" placeholder="Your question" style="font:14px/1.5 system-ui,sans-serif;padding:10px;border:1px solid #cfd6dd;border-radius:6px"></textarea><div style="display:flex;gap:8px;flex-wrap:wrap"><input type="email" name="email" placeholder="Email (optional)" style="flex:1;min-width:200px;font:14px system-ui,sans-serif;padding:9px 10px;border:1px solid #cfd6dd;border-radius:6px"><button type="submit" style="font:600 14px system-ui,sans-serif;padding:9px 18px;border:0;border-radius:6px;background:#1b1f24;color:#fff;cursor:pointer">Send</button></div><p id="yj-ask-msg" style="font:13px system-ui,sans-serif;margin:2px 0 0;color:#0a6238;min-height:1em"></p></form><script>function yjAsk(e){e.preventDefault();var f=e.target,m=document.getElementById("yj-ask-msg");m.style.color="#0a6238";fetch(location.origin+"/api/ask",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sku:68909,slug:"pg-migration-lock-lint",lang:"en",question:f.question.value,email:f.email.value,page:location.pathname})}).then(function(r){if(!r.ok)throw 0;m.textContent="Thanks \u2014 noted. Answers land on this page and, if you left an email, in your inbox.";f.question.value="";}).catch(function(){m.style.color="#a8551f";m.textContent="Could not send. Please try again in a minute.";});return false;}</script></div></section><section class="yj-related" style="max-width:920px;margin:56px auto 40px;padding:0 20px"><h2 style="font:600 21px/1.3 system-ui,sans-serif;margin:0 0 6px;color:#1b1f24">Same job, next tool</h2><p style="font:400 14.5px/1.5 system-ui,sans-serif;margin:0 0 20px;color:#5b6570">Free in the browser. The full version is a one-time licence.</p><div style="display:grid;grid-template-columns:repeat(auto-fill,minmax(250px,1fr));gap:14px"><a class="yj-rel-c" href="https://getreadystack.com/tools/personal-data-map-dsar-audit"><span class="yj-rel-t">Personal Data Map: find every column a GDPR subject access request has to reac</span><span class="yj-rel-p">$29</span></a><a class="yj-rel-c" href="https://getreadystack.com/tools/robots-txt-ai-crawler-audit"><span class="yj-rel-t">AI Crawler Rules - robots.txt Audit for AI Search</span><span class="yj-rel-p">$29</span></a><a class="yj-rel-c" href="https://getreadystack.com/tools/accessibility-statement-lint"><span class="yj-rel-t">Accessibility Statement Lint (EU model)</span><span class="yj-rel-p">$29</span></a><a class="yj-rel-c" href="https://getreadystack.com/tools/bulk-sender-lint"><span class="yj-rel-t">Bulk Sender Lint - the Gmail, Yahoo and Outlook.com rules, checked in your mai</span><span class="yj-rel-p">$29</span></a><a class="yj-rel-c" href="https://getreadystack.com/tools/devicetree-config-language-pack"><span class="yj-rel-t">DeviceTree Config Audit: 23 dtc-Style Rules, 50 Snippets</span><span class="yj-rel-p">$29</span></a><a class="yj-rel-c" href="https://getreadystack.com/tools/en301549-lint"><span class="yj-rel-t">EN 301 549 Lint — European Accessibility Act rules, with the clause number, in</span><span class="yj-rel-p">$29</span></a></div><style>.yj-rel-c{display:flex;flex-direction:column;gap:8px;padding:15px 16px;border:1px solid #e2e6ea;border-radius:6px;text-decoration:none;background:#fff}.yj-rel-c:hover{border-color:#b9c2cb;background:#fafbfc}.yj-rel-t{font:500 14.5px/1.42 system-ui,sans-serif;color:#1b1f24}.yj-rel-p{font:600 13px system-ui,sans-serif;color:#0a6238}</style></section></body>
</html>