Prompt·Workflows·DBR04

Reduce PostgreSQL resource cost

Spend less where the measurements say the money goes.

Markdown
Prompt
Reduce PostgreSQL resource cost Spend less where the measurements say the money goes.
Work through this in order and check in with me after each step. Stay read-only until I approve a change.

1. Start: Measure the top consumers first.

Find the true sources of database waste (PG13)
Measure which tables, indexes, queries and maintenance activities consume the most storage, execution time and write resources. Distinguish useful capacity from avoidable waste, including unused indexes, row churn, bloat, poor plans and excessive scans. Recommend changes based on observed workload and realistic savings, not generic optimization rules.

2. If needed: PG06 for write churn; PG14 when growth is the driver; P03 for one slow query.

Stop rewriting data that hasn't changed (PG06)
Investigate how much database write activity actually changes meaningful information. Find repeated upserts, unchanged updates, unnecessary delete-and-reinsert operations, repeated index maintenance and cascading refreshes. Measure their cost where practical and determine which writes can be eliminated without changing correctness, history or recovery behavior.

What will become expensive as the database grows? (PG14)
Use actual table sizes, row growth, query plans and workload patterns to identify the first database operations likely to become disproportionately expensive as data grows. Evaluate indexing, partitioning, pagination, aggregation and retention only where the evidence justifies them. Show what scale would trigger a change rather than optimizing everything prematurely.

Queries that grow badly (P03)
Find database queries whose cost grows disproportionately with records, tenants, or relationships. Examine execution plans, indexes, joins, pagination, and application-side filtering.

3. Change: Take the biggest measured savings first. No speculative indexes or partitions.

4. Done when: Workload figures before and after, with no loss of correctness.

Related prompts

More in Workflows.