randoneering/pgfirstaid/using-pgfirstaid
Claude Code and agent skill by randoneering/pgfirstaid
- community
Checking that the SKILL.md file is still in the repository.
Use when diagnosing PostgreSQL health, performance, or stability issues, or when asked to run a database health check, audit, or triage on a Postgres instance. Triggers on requests like "check the database", "is the db healthy", "find slow queries", "what's wrong with Postgres", "run pgFirstAid", or pre/post-deployment validation.
Install
npx vskill@latest install randoneering/pgfirstaid/using-pgfirstaidSKILL.md
The same SKILL.md was published earlier as randoneering/pgfirstaid/using-pgfirstaid.
Using pgFirstAid
Overview
pg_firstAid() returns prioritized health issues (CRITICAL → INFO) from a single Postgres function. Works on self-hosted Postgres, RDS, Aurora, Cloud SQL, Neon, Supabase, and other managed services. Results vary by environment: managed services restrict access to some system catalogs and parameter settings, so a few checks return reduced output. Run as the highest-privilege role available.
Quick Start
Self-hosted (install pgFirstAid.sql):
Managed services (install view_pgFirstAid_managed.sql):
The managed SQL creates the view, not the function, so managed callers must use the view. The view does not run pg_stat_statements checks.
Output Schema
| Column | Meaning | |
|---|---|---|
severity | CRITICAL → INFO | |
category | Table Health, Query Health, Index Health, Replication Health, Database Health, Connection Health, Security Health, System Health, System Info | |
check_name | Label | |
object_name | Schema-qualified object, or System |
issue_description explains the problem, current_value shows the measured state, recommended_action suggests a fix, documentation_link points to the Postgres docs.
Severity Workflow
| Severity | Action | |
|---|---|---|
| CRITICAL | Follow the documentation_link, propose a fix or SQL, run the Verify Before Applying steps, then apply | |
| HIGH | Follow the documentation_link, propose the SQL, include in the plan for this week | |
| MEDIUM / LOW | Batch and review. Trust the recommended_action summary | |
| INFO | Skip. Not action items |
Walk through every level from CRITICAL to INFO, even when earlier levels are empty. Always propose SQL as a draft the user signs off on, never auto-apply.
Verify Before Applying
For any proposed SQL, before signing off:
- Dry-run transactional commands in a transaction with
BEGIN; ... ROLLBACK;. Non-transactional operations (pg_terminate_backend,VACUUM FULL,REINDEX CONCURRENTLY,CREATE INDEX CONCURRENTLY, andREINDEXon partitioned tables) cannot be wrapped this way and need isolation on a staging copy instead.REINDEX INDEXandREINDEX TABLE(withoutCONCURRENTLY) are transactional and safe to wrap inBEGIN; ... ROLLBACK;. - Test on a staging copy first. Never apply CRITICAL or HIGH fixes to production untested.
- EXPLAIN to see the plan. Plain
EXPLAINdoes not execute. AddANALYZEonly inside a transaction with rollback so DML runs but does not commit. On read replicas,EXPLAINonly (no write permission needed). - Confirm affected rows with
SELECT COUNT(*)using the sameWHEREbefore any DELETE or UPDATE. - Backup before destructive ops.
pg_dumpthe affected table before DROP, TRUNCATE, or major ALTER.
Common Patterns
Common Mistakes
- Missing PK → drop table, or unused index →
DROP INDEX. No, add a PK or unique constraint. Validate index usage over a representative window first. - Skipping the
documentation_link. For CRITICAL/HIGH, follow it before proposing a fix. Therecommended_actionis a summary; the doc has version-specific edge cases the summary omits. - Skipping before/after snapshots. Capture the function or view output (
SELECT * FROM pg_firstAid()for self-hosted,SELECT * FROM v_pgfirstAidfor managed) to CSV before and after the change; compare to confirm the fix removed the finding.
When NOT to Use
- Automated fixes. pgFirstAid only reports, never modifies.
- Hot-loop monitoring. Run on a schedule, not per query.
- Cluster-wide audits. Function is per-database; loop over databases if needed.
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewNot runA model review is scheduled for the next rescan.
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/using-pgfirstaid/SKILL.md
Popularity
- 7-day trend score
- 0
Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/randoneering/pgfirstaid/using-pgfirstaid)