Skip to main content
Get pgvet running on your SQL files in just a few steps.
1

Install pgvet

Install using Go:
go install github.com/mnafees/pgvet@latest
The first build takes ~3 minutes due to CGO compilation. See the installation guide for details.
2

Create a sample SQL file

Create a file called test.sql with some SQL that has common issues:
test.sql
-- Sample queries with issues pgvet will catch
SELECT * FROM users;

SELECT id, email FROM users LIMIT 10;

SELECT * FROM posts 
WHERE author_id NOT IN (SELECT user_id FROM banned_users);

UPDATE users SET last_login = NOW();
3

Run pgvet

Run pgvet on your SQL file:
pgvet test.sql
You’ll see output like:
test.sql:2:8: warning: [select-star] SELECT * in outermost query is fragile — list columns explicitly
test.sql:4:39: warning: [limit-without-order] LIMIT without ORDER BY produces non-deterministic results (except LIMIT 1)
test.sql:7:6: warning: [select-star] SELECT * in outermost query is fragile — list columns explicitly
test.sql:7:28: error: [not-in-subquery] NOT IN (SELECT ...) is broken when the subquery can return NULLs — use NOT EXISTS instead
test.sql:10:1: warning: [update-without-where] UPDATE without WHERE updates every row in the table
4

Fix the issues

Update your SQL to fix the problems:
test.sql
-- Fixed queries
SELECT id, email, created_at FROM users;

SELECT id, email FROM users ORDER BY created_at DESC LIMIT 10;

SELECT * FROM posts 
WHERE NOT EXISTS (
  SELECT 1 FROM banned_users WHERE user_id = posts.author_id
);

UPDATE users SET last_login = NOW() WHERE id = 123;
5

Verify the fixes

Run pgvet again to confirm all issues are resolved:
pgvet test.sql
Clean output means no issues were found. The exit code will be 0.

Common workflows

# Check all SQL files in a directory recursively
pgvet sql/
pgvet migrations/

Understanding exit codes

pgvet uses standard exit codes:
  • 0: No issues found (clean)
  • 1: Issues found (warnings or errors)
  • 2: Usage error or parse failure
This makes it easy to integrate with CI systems:
# Fail the build if any issues are found
pgvet migrations/ || exit 1

# Allow warnings, fail only on parse errors
pgvet migrations/ ; test $? -ne 2

Output format

By default, pgvet outputs issues in a compiler-style format:
filename:line:col: severity: [rule-name] message
For example:
queries.sql:3:8: warning: [select-star] SELECT * in outermost query is fragile
Use --format json for structured output that’s easier to parse programmatically.

Next steps

Command Line

Learn all command-line flags and options

Rules Reference

Browse all built-in rules and examples

CI Integration

Set up pgvet in GitHub Actions, GitLab CI, and more

Custom Rules

Write your own custom analysis rules
Start by running pgvet on your existing SQL files with default settings. You can always fine-tune the rule selection later based on your team’s needs.

Build docs developers (and LLMs) love