prefer-lz4-toast-compression
Use lz4 TOAST compression instead of pglz on PostgreSQL 14+ for better performance.
- operation
- Columns
- lock taken
- no table lock
- remediation
- Fixed by --fix
- category
- Types & schema style
What triggers it
ALTER TABLE ... ALTER COLUMN ... SET COMPRESSION pglz (the AT_SetCompression subcommand with a pglz value), or SET default_toast_compression = 'pglz' as a VariableSetStmt — checked only when ctx.pgVersion is 14 or higher.
What does not
Any migration targeting PostgreSQL below 14 returns immediately, before the statement is inspected. SET COMPRESSION lz4 (or anything other than pglz) is skipped by the loop, as is SET default_toast_compression to anything other than 'pglz', and ALTER TABLE statements with no commands.
Where it applies
Applies to PostgreSQL 14 and later. It works on the SQL text alone — no database connection needed.
The lock, and what it blocks
None named — this is a metadata-only change. SET COMPRESSION doesn't rewrite existing TOASTed values, it only changes which algorithm is used for values written from here on, so there's nothing to block.
Why it matters
PostgreSQL 14 introduced lz4 as an alternative TOAST compression method. lz4 is 3-5x faster for both compression and decompression compared to pglz, with only slightly worse compression ratios.
Unsafe, and safe
Flagged
ALTER TABLE users ALTER COLUMN bio SET COMPRESSION pglz;
Safe alternative
ALTER TABLE users ALTER COLUMN bio SET COMPRESSION lz4;
What it assumes
Assumes the column actually stores TOAST-heavy data worth compressing — lz4 vs pglz makes no practical difference on a column that rarely stores values over the TOAST threshold, and the rule fires the same way regardless of column size or write volume.
What the CLI prints
⚠ [MP077] WARNING (line 1) Column "bio" on "users" uses pglz compression. Use lz4 on PG 14+ for 3-5x faster compression/decompression. Safe alternative: ALTER TABLE users ALTER COLUMN bio SET COMPRESSION lz4; Why: PostgreSQL 14 introduced lz4 as an alternative TOAST compression method. lz4 is 3-5x faster for both compression and decompression compared to the default pglz, with only slightly worse compression ratios. For JSONB, TEXT, and BYTEA columns with frequent reads/writes, lz4 significantly reduces CPU overhead. Docs: https://migrationpilot.dev/rules/mp077
Generated by running the CLI's own formatter over the flagged example above, so it is the text the tool actually produces. A real run also reports the other rules that fire on the same statement; those blocks are left out here.
Turning it off
For one statement, put a comment on the line before it:
-- migrationpilot-disable MP077 ALTER TABLE users ALTER COLUMN bio SET COMPRESSION pglz;
For the whole project, in .migrationpilotrc.yml — by name or by id:
rules:
MP077: false
# or keep it, and downgrade it
rules:
MP077:
severity: warningTry it
Open this rule's flagged example in the playground. It runs in your browser — edit it and watch the finding appear and disappear.
Run MP077 in the playground