Chuyển đến nội dung
Skillpedia
Cơ sở dữ liệu48k · #5285

neon-postgres-egress-optimizer

Skill này làm gì

Agent này giúp tìm và sửa các vấn đề khiến cơ sở dữ liệu gửi nhiều dữ liệu qua mạng hơn mức cần thiết. Điều này có thể giúp giảm chi phí truyền tải dữ liệu.

Khi nào nên dùng

  • ✓Khi hóa đơn cơ sở dữ liệu cao hơn dự kiến.
  • ✓Khi bạn thấy chi phí truyền tải dữ liệu bất thường.
  • ✓Khi cần tối ưu các truy vấn lấy quá nhiều dữ liệu.

Liên kết skill

https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/neon-postgres-egress-optimizer/SKILL.md

Sao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.

Cách dùng

Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.

Tin nhắn có sẵn để dán

Hãy dùng skill này để giúp tôi: https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/neon-postgres-egress-optimizer/SKILL.md Đọc tệp SKILL.md tại liên kết đó và làm theo hướng dẫn cho việc của tôi.
Bạn muốn AI tự tìm những skill như thế này?Cài MCP Skillpedia miễn phí: chỉ một dòng, và AI sẽ tìm trong 15.000+ skill trước mỗi việc.Cài đặt trong 1 phút →

Ví dụ cách nhờ AI

“Hóa đơn cơ sở dữ liệu của tôi quá cao, bạn có thể giúp tôi tối ưu không?”

5 skill mới mỗi tuần. Đọc chỉ 1 phút.

Cách hoạt động

Agent phân tích truy vấn nào gửi nhiều dữ liệu nhất và đề xuất cách tối ưu, như lấy ít cột hơn, thêm giới hạn kết quả hoặc dùng bộ nhớ đệm.

Nội dung kỹ thuật (SKILL.md gốc)

Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.

Postgres Egress Optimizer

When to Use

Use this skill when you need 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...

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.

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

SELECT 1 FROM pg_stat_statements LIMIT 1;

If this errors, the extension needs to be created:

CREATE EXTENSION IF NOT EXISTS pg_stat_statements;

On Neon, it is available by default but may 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:

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):

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):

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):

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 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.

Before:

SELECT * FROM products;

After:

SELECT id, name, price, image_urls FROM products;

Missing pagination

Problem: A list endpoint returns all rows with no LIMIT. This is an unbounded egress risk — every new row in the table increases data transfer on every request. Flag this regardless of current table size.

…

Câu hỏi thường gặp

Làm sao để biết tôi có vấn đề 'egress' không?

Nếu bạn trả nhiều tiền hơn dự kiến cho việc truyền tải dữ liệu từ cơ sở dữ liệu, hoặc các truy vấn của bạn trả về quá nhiều dữ liệu cho ứng dụng, thì bạn có thể đang gặp vấn đề này.

“Egress” là gì?

'Egress' là lượng dữ liệu rời khỏi cơ sở dữ liệu để đến ứng dụng của bạn. Trả phí cho lượng dữ liệu lớn có thể làm tăng chi phí.

pg_stat_statements là gì?

Đây là công cụ trong cơ sở dữ liệu PostgreSQL giúp xác định truy vấn nào đang chạy và lượng dữ liệu mỗi truy vấn truyền tải.

Chi tiết

Mô tả gốc của tác giả

Diagnose and fix excessive Postgres egress (network data transfer) in a codebase.

repo: sickn33/agentic-awesome-skills

Độ phổ biến

Sao GitHub
48k
Vị trí xếp hạng
#5285
Giấy phép
MIT
Cập nhật
15/10/2026

Skill này có hữu ích không?

0

Đăng nhập để bình chọn.

Bình luận

  • …

Thêm skill từ kho mã này

Skill tương tự