Back to Skills

neon-postgres-egress-optimizer

Diagnose and fix excessive Postgres egress (network data transfer) in a codebase. Use when a user mentions high database bills, unexpected data transfer costs, network transfer charges, egress spikes, "why is my Neon bill so high", "database costs jumped", SELECT * optimization, query overfetching, reduce Neon costs, optimize database usage, or wants to reduce data sent from their database to their application. Also use when reviewing query patterns for cost efficiency, even if the user doesn't

81stars12forksUpdated 7/27/2026

Security Assessment

Safe(95/100)
Security Score95/100

About neon-postgres-egress-optimizer

Postgres Egress Optimizer is a diagnostic skill for finding and fixing application-side query patterns that cause excessive data transfer (egress) from a Postgres database, which is a common driver of surprise database bills. Its premise is that most high egress comes from applications fetching more data than they use, so it guides the user through a disciplined four-step method: diagnose which queries transfer the most data, analyze the codebase behind them, fix the anti-patterns, and verify that nothing broke and the transfer actually dropped. It is a child of the parent neon skill, which it points the agent to first.

For diagnosis it uses the read-only pg_stat_statements extension, with queries that rank statements by total rows returned, rows per execution, call frequency, and total execution time, plus guidance on handling empty stats after a Neon compute scales to zero. It teaches how to interpret results by combining row counts with column width (JSONB, TEXT, BYTEA) to estimate real egress impact. The fix section catalogs the common anti-patterns — SELECT * fetching unused wide columns, missing pagination on list endpoints, high-frequency queries on static data that should be cached, and application-side aggregation that transfers whole tables to compute a small summary — each with a before/after example and, where relevant, pushing work into SQL. A verify step confirms correctness and measures the reduction.

It is aimed at application developers, backend engineers, and cost-conscious teams who see egress spikes, high Neon bills, or want to review query patterns for cost efficiency. The main prerequisite is access to run diagnostic SQL (ideally against production stats) and the codebase to analyze.

FAQ

How does it find the queries responsible for high egress?

It uses the pg_stat_statements extension and ranks queries by total rows returned, rows per execution, call frequency, and total execution time, then cross-references column widths to estimate which queries move the most data.

What if pg_stat_statements has no data?

Stats are cleared when a Neon compute scales to zero and restarts. The skill has you reset the stats, let the app run under representative traffic for at least an hour, then re-run the diagnostics. If you can't access production stats, it analyzes the codebase directly.

What anti-patterns does it fix?

SELECT * pulling unused wide columns, missing pagination on list endpoints, high-frequency queries on rarely-changing data that should be cached, and application-side aggregation that transfers entire tables to compute a small summary. Each comes with a before/after example.

Does it make destructive changes to my database?

No. The diagnostic step is read-only (querying pg_stat_statements and resetting its stats). The fixes are edits to application query patterns and code, which you review, followed by a verification step to confirm nothing broke.

Is it specific to Neon?

It is written for Neon (a child of the neon skill and aware of Neon compute scale-to-zero behavior), but the diagnostic queries and egress anti-patterns apply to Postgres generally.

Install neon-postgres-egress-optimizer

Download and extract the skill files to your .claude/skills/ directory.

Quick Setup:

  1. Copy the skill folder to .claude/skills/
  2. Claude will automatically detect and use the skill