pgfence for VS Code
Postgres migration safety: real-time lock mode analysis, risk scoring, and safe rewrite suggestions directly in your editor.
Features
Diagnostics - Inline warnings and errors for dangerous migration patterns:
- Lock mode escalation (ACCESS EXCLUSIVE, SHARE, etc.)
- Risk levels (SAFE, LOW, MEDIUM, HIGH, CRITICAL)
- Policy violations (missing
lock_timeout, CONCURRENTLY inside transaction, etc.)
Safe Rewrite Quick Fixes - One-click fixes that replace dangerous patterns with safe expand/contract sequences. No other tool provides this.
Hover Information - Hover over any flagged statement to see:
- Exact lock mode acquired
- What operations are blocked (reads, writes, DDL)
- Risk level and safe alternatives
Status Bar - At-a-glance error/warning count for the current workspace.
Requirements
pgfence must be installed in your project or globally:
# In your project (recommended)
npm install -D @flvmnt/pgfence
# Or globally
npm install -g @flvmnt/pgfence
The extension automatically discovers the LSP server from:
- Workspace
node_modules/@flvmnt/pgfence
- Global npm installation
Configuration
| Setting |
Default |
Description |
pgfence.minPostgresVersion |
14 |
Minimum PostgreSQL version to assume (affects which operations are instant) |
pgfence.requireLockTimeout |
true |
Require SET lock_timeout in every migration |
pgfence.requireStatementTimeout |
true |
Require SET statement_timeout in every migration |
pgfence.statsFilePath |
"" |
Path to pgfence-stats.json for size-aware risk scoring |
pgfence.trace.server |
"off" |
Trace LSP server communication (for debugging) |
Commands
- pgfence: Show Output - Open the pgfence output channel
- pgfence: Restart Server - Restart the LSP server
What pgfence detects
pgfence analyzes 37 migration patterns including:
ADD COLUMN ... NOT NULL without DEFAULT (ACCESS EXCLUSIVE)
CREATE INDEX without CONCURRENTLY (SHARE lock, blocks writes)
ALTER COLUMN TYPE (full table rewrite)
ADD CONSTRAINT ... FOREIGN KEY without NOT VALID
DROP TABLE, TRUNCATE (CRITICAL risk)
- Missing
lock_timeout / statement_timeout policies
CREATE INDEX CONCURRENTLY inside a transaction (will fail)
- And 30+ more patterns
Like pgfence?
If pgfence helps keep your migrations safe, give it a star on GitHub. It helps others discover the project.
Links
License
MIT