# Reduce PostgreSQL resource cost

Recipe · Bugs, speed and data · RDBR04

Measures which Postgres tables, indexes, queries, and write loops actually drive your bill, cuts the biggest measured waste first, and verifies savings.

**Use it when:** Your Postgres compute, storage, or hosting bill is climbing faster than your product's growth.

## Steps

1. [Find the true sources of database waste](https://www.atlasscope.dev/prompts/find-the-true-sources-of-database-waste): measure top storage, CPU, bloat, and unused indexes (read-only)
2. Drill into write churn or scaling queries: inspect unchanged rewrites and slow query plans (read-only)
3. Take the top measured saving first: skip speculative indexes or premature partitioning
4. Prove before-and-after savings: compare workload metrics with zero loss of correctness

## As one prompt

```text
Reduce PostgreSQL resource cost. Cut measured database waste without breaking queries or adding speculative complexity.

Run these steps one at a time. Wait for my yes after each step. Stay read-only during Steps 1, 2, and 4 — never edit production data, indexes, or queries until I approve Step 3.

Step 1 (measure waste — read-only): Measure which tables, indexes, queries, and maintenance tasks consume the most storage, CPU, and write I/O (unused indexes, bloat, dead tuples, full scans). Bring back: table/index sizes, top statements, index usage counts, EXPLAIN plans, and estimated savings. Stop if usage and cost are already small and flat.

Step 2 (churn & scaling — read-only, run only what Step 1 points to): Measure unchanged row rewrites in write-heavy jobs, and inspect EXPLAIN ANALYZE plans for queries growing badly with row count. Bring back: write-churn share and query plans with realistic row counts.

Step 3 (apply top measured fix): After I approve, implement only the highest-saving measured fix. No speculative indexes or premature partitioning.

Step 4 (verify): Report before-and-after query plans, write/storage figures, and confirmation that query results remain identical.

Start your report in plain English: what you found, what it means, and whether I need to do anything. Put files, lines and commands underneath.
```

Source: https://www.atlasscope.dev/prompts/reduce-postgresql-resource-cost-rdbr04
