neon-postgres-egress-optimizer
Diagnose and fix excessive Postgres egress (network data transfer) in a codebase.
Skill by neondatabaseOfficial
Install
Works with Claude Code, Claude apps, Codex, Cursor, Gemini CLI, GitHub Copilot, VS Code, OpenCode, Goose, Windsurf. Read the repository before you give any tool access to your data.
npx agentmarket install skill/neondatabase-neon-postgres-egress-optimizer-10e8fd
Asks which of your tools to add it to (Claude Code, Codex, Cursor, VS Code, Windsurf, Gemini CLI, Claude Desktop) and shows the change first. See https://agentmart.dev/cli.
Get the weekly diff
The weekly diff: one email a week with new agent tools, notable updates and grade changes, plus security alerts for tools you follow. Double opt-in, one-click unsubscribe.
About
Use cases: backend, data
Reviews
Write a reviewNo reviews yet. Installed it? Reviews come from verified installers only. How reviews work
Permissions: not checked yet.
What's inside
- Skill name
neon-postgres-egress-optimizer- Description
- 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 explicitly mention egress or data transfer.
- License
- Apache-2.0
- Metadata
- parent: neon · source: https://github.com/neondatabase/agent-skills/tree/main/skills/neon-postgres-egress-optimizer
- Instructions
- 252 lines in SKILL.md · view on GitHub
Files (1)
- SKILL.md
SKILL.md (first lines)
**FIRST**: Use the parent `neon` skill for a Neon overview, getting started with Neon, Neon development best practices, and more. If the `neon` skill is not installed, fetch it from https://neon.com/docs/ai/skills/neon/SKILL.md or install it with: ```bash neon skills -s neon -y ``` # Postgres Egress Optimizer Guide the user through diagnosing and fixing application-side query patterns that cause excessive data transfer (egress) from their Postgres database. Most high egress bills come from the application fetching more data than it uses. Work the four steps in order: **diagnose** which queries transfer the most data, **analyze** the codebase behind them, **fix** the anti-patterns, then **verify** nothing broke and the transfer actually dropped. ## Step 1: Diagnose Identify which queries transfer the most data. The primary tool is the `pg_stat_statements` extension. ### Check if pg_stat_statements is available ```sql SELECT 1 FROM pg_stat_statements LIMIT 1; ``` If this errors, the extension needs to be created: ```sql CREATE EXTENSION IF NOT EXISTS pg_stat_statements; ``` On Neon the extension is available by default, but it may still need this CREATE EXTENSION step. ### Handle empty stats Stats are cleared when a Neon compute scales to zero and restarts. If the stats are empty or the compute recently woke up: 1. Reset the stats to start a clean measurement window: `SELECT pg_stat_statements_reset();` 2. Let the application run under representative traffic for at least an hour. 3. Return and run the diagnostic queries below. If the user has stats from a production database, use those. If they have no access to production stats, proceed to Step 2 and analyze the codebase directly — code-level patterns are often sufficient to identify the worst offenders. ### Diagnostic queries Run these to identify the top egress contributors. Focus on queries that return many rows, return wide rows (JSONB, TEXT, BYTEA columns), or are called very frequently. **Queries returning the most total rows:** ```sql SELECT query, calls, rows AS total_rows, rows / calls AS avg_rows_per_call FROM pg_stat_statements WHERE calls > 0 ORDER BY rows DESC LIMIT 10; ``` **Queries returning the most rows per execution** (poorly scoped SELECTs, missing pagination): ```sql SELECT query, calls, rows AS total_rows, rows / calls AS avg_rows_per_call FROM pg_stat_statements WHERE calls > 0 ORDER BY avg_rows_per_call DESC LIMIT 10; ``` **Most frequently called queries** (candidates for caching): ```sql SELECT query, calls, rows AS total_rows, rows / calls AS avg_rows_per_call FROM pg_stat_statements WHERE calls > 0 ORDER BY calls DESC LIMIT 10; ``` **Longest running queries** (not a direct egress measure, but helps identify problem queries during a spike): ```sql SELECT query, calls, rows AS total_rows, round(total_exec_time::numeric, 2) AS total_exec_time_ms FROM pg_stat_statements WHERE calls > 0 ORDER BY total_exec_time DESC LIMIT 10; ``` ### Interpret the results Rank findings by estimated egress impact: - **High row count + wide rows** = biggest egress. A query returning 1,000 rows where each row includes a 50KB JSONB column transfers ~50MB per call. - **Extreme call frequency** on even small queries adds up. A query called 50,000 times/day returning 10 rows each = 500,000 rows/day. - **Cross-reference with the schema** to identify which columns are wide. Look for JSONB, TEXT, BYTEA, and large VARCHAR columns. ## Step 2: Analyze the Codebase For each query identified in Step 1, or for each database query in the codebase if no stats are available, check: - Does it select only the columns the response needs? - Does it return a bounded number of rows (LIMIT/pagination)? - Is it called frequently enough to benefit from caching? - Does it fetch raw data that gets aggregated in application code? - Does it use a JOIN that duplicates parent data across child rows? ## Step 3: Fix Apply the appropriate fix for each problem found. Below are the most common egress anti-patterns and how to fix them. ### Unused columns (SELECT \*) **Problem:** The query fetches all columns but the application only uses a few. Large columns (JSONB blobs, TEXT fields) get transferred over the wire and discarded. **Fix:** Name only the columns the response needs. **Before:** ```sql SELECT * FROM products;
From neondatabase/agent-skills, Apache-2.0.
More from neondatabase/agent-skills
- 0.782score
neon
neondatabaseOfficial
Overview of Neon, a complete set of cloud backend primitives around Lakebase Postgres: Auth, Object Storage, Functions, the AI Gateway, and Realtime.
SkillAFreshness: A★ 105Claude Code +9 - 0.782score
neon-postgres
neondatabaseOfficial
Guides and best practices for working with Lakebase Postgres on Neon: connections, pooled vs direct, schema migrations, branching, autoscaling, scale-to-zero…
SkillAFreshness: A★ 105Claude Code +9 - 0.782score
neon-realtime
neondatabaseOfficial
Neon Realtime makes any SQL query live.
SkillAFreshness: A★ 105Claude Code +9 - 0.776score
neon-ai-gateway
neondatabaseOfficial
One API and one credential for frontier and open-source LLMs and embedding models, built into your Neon branch and powered by Databricks.
SkillAFreshness: A★ 105Claude Code +9 - 0.776score
neon-object-storage
neondatabaseOfficial
S3-compatible object storage that branches with your database, so each branch gets its own copy of the files and the rows that point at them.
SkillAFreshness: A★ 105Claude Code +9 - 0.772score
neon-functions
neondatabaseOfficial
Long-running, serverless Node.js HTTP functions deployed onto your Neon branch, with DATABASE_URL injected automatically and compute that runs next to your…
SkillAFreshness: A★ 105Claude Code +9 - 0.736score
neon-auth
neondatabaseOfficial
Add authentication to a new app.
SkillBFreshness: B★ 105Claude Code +9 - 0.730score
neon-postgres-egress-optimizer
neondatabaseOfficial
Diagnose and fix excessive Postgres egress (network data transfer) in a codebase.
SkillBFreshness: B★ 105Claude Code +9 - 0.730score
neon-postgres-branches
neondatabaseOfficial
Choose and create the right Neon branch type for testing and development.
SkillBFreshness: B★ 105Claude Code +9 - 0.536score
score-eval
neondatabaseOfficial
No description from the publisher yet.
SkillDFreshness: D★ 105Claude Code +9
Signals
- Stars
- 105
- Forks
- 23
- Open issues
- 17
- Last commit (this folder)
- Sep 16, 2026 (1 month ago)
From GitHub (fetched Oct 24, 2026).
Details
- License
- Apache-2.0
- Repository
- github.com/neondatabase/agent-skills
- First seen
- Oct 24, 2026
- Last checked
- Oct 24, 2026
- Source
- GitHubgithub-graphql
Same skill elsewhere
Copies of this SKILL.md published by others; search shows only one of them.
- 0.730score
neon-postgres-egress-optimizer
neondatabaseOfficial
Diagnose and fix excessive Postgres egress (network data transfer) in a codebase.
SkillBFreshness: B★ 105Claude Code +9 - 0.336score
neon-postgres-egress-optimizer
intelogroup
Diagnose and fix excessive Postgres egress (network data transfer) in a codebase.
SkillAFreshness: AClaude Code +9 - 0.330score
neon-postgres-egress-optimizer
andrelandgraf
Diagnose and fix excessive Postgres egress (network data transfer) in a codebase.
SkillCFreshness: C★ 22Claude Code +9
More from neondatabase
- 0.782score
neon
neondatabaseOfficial
Overview of Neon, a complete set of cloud backend primitives around Lakebase Postgres: Auth, Object Storage, Functions, the AI Gateway, and Realtime.
SkillAFreshness: A★ 105Claude Code +9 - 0.782score
neon-postgres
neondatabaseOfficial
Guides and best practices for working with Lakebase Postgres on Neon: connections, pooled vs direct, schema migrations, branching, autoscaling, scale-to-zero…
SkillAFreshness: A★ 105Claude Code +9 - 0.782score
neon-realtime
neondatabaseOfficial
Neon Realtime makes any SQL query live.
SkillAFreshness: A★ 105Claude Code +9 - 0.776score
neon-object-storage
neondatabaseOfficial
S3-compatible object storage that branches with your database, so each branch gets its own copy of the files and the rows that point at them.
SkillAFreshness: A★ 105Claude Code +9 - 0.776score
neon-ai-gateway
neondatabaseOfficial
One API and one credential for frontier and open-source LLMs and embedding models, built into your Neon branch and powered by Databricks.
SkillAFreshness: A★ 105Claude Code +9 - 0.772score
neon-functions
neondatabaseOfficial
Long-running, serverless Node.js HTTP functions deployed onto your Neon branch, with DATABASE_URL injected automatically and compute that runs next to your…
SkillAFreshness: A★ 105Claude Code +9
Cite this page
neon-postgres-egress-optimizer skill. Agent Mart. https://agentmart.dev/skills/neondatabase-neon-postgres-egress-optimizer-10e8fd (last updated 2026-10-24)