What am I paying for that the workload does not need?
Most database bills are large for the same few reasons. This page lists them, shows how to find each one with a query, and gives a safe order for cutting. The bill is a result of the design, so the design is where the savings are.
The decision is not "spend less". It is to know what each line of the bill buys, and to size the reserve deliberately, not out of fear. A database that is too small fails loudly. A database that is too big fails quietly, on the invoice.
Where your bill goes
The starting numbers are an example, not a benchmark. Replace them with the lines from your own monthly invoice. The largest line is drawn in orange.
| Line | What it buys | What usually inflates it |
|---|---|---|
| Compute | CPU and memory for the primary and every replica | Sized for the fear. Extra replicas. Connections held open. |
| Storage | Table and index files, logs, undo | Old data, unused indexes, bloat, long transactions. |
| I/O | Provisioned IOPS and throughput, or pay-per-request | Scans that should be lookups. A cache that is too small. |
| Backups | Snapshots and archived logs for point-in-time recovery | Retention nobody reviewed. Copies kept in several regions. |
| Network | Traffic between zones, regions and the internet | Replicas in other regions. Applications in another zone than the primary. |
| Everything that is not production | Dev, test, staging and forgotten copies | Full-size copies that run all night and all weekend. |
The commands below are the standard ones for each engine. Run them on a replica when you can, and read the numbers over a full business cycle, not one quiet afternoon.
Someone picked the size for the worst day they could imagine, and nobody went back to check.
-- PostgreSQL cache hit ratio SELECT sum(blks_hit)::float / nullif(sum(blks_hit) + sum(blks_read), 0) FROM pg_stat_database;
The fixStep down one size, not three. Keep enough room for the failover case. See "What breaks when you cut too hard" below.
Provisioned I/O is billed whether the disk uses it or not.
-- MySQL: how often the buffer pool misses SHOW GLOBAL STATUS LIKE 'Innodb_buffer_pool_read%';
The fixLower the provisioned figure to the peak plus 30 percent. Raise it again when the peak grows.
Every replica is a full copy of the data at full price. A replica that serves no reads and is not your failover target is pure cost.
-- PostgreSQL, on the primary SELECT client_addr, state FROM pg_stat_replication;
The fixRemove it, or keep exactly one replica as the failover target, sized like the primary.
Each unused index costs disk, cache space and a write on every change to the table.
-- PostgreSQL
SELECT relname, indexrelname, idx_scan
FROM pg_stat_user_indexes WHERE idx_scan = 0
ORDER BY pg_relation_size(indexrelid) DESC LIMIT 20;
-- MySQL
SELECT * FROM sys.schema_unused_indexes;
-- MongoDB
db.orders.aggregate([{ $indexStats: {} }])The fixDrop them one at a time, with the definition saved so you can recreate it.
Old rows, old logs and old events sit on fast, expensive storage and drag every scan and every backup with them.
-- PostgreSQL SELECT relname, pg_size_pretty(pg_total_relation_size(oid)) FROM pg_class WHERE relkind = 'r' ORDER BY pg_total_relation_size(oid) DESC LIMIT 10; -- MongoDB db.events.totalSize()
The fixPartition by time and drop whole partitions instead of running a huge DELETE. In MongoDB, use a TTL index. Archive what the law requires you to keep.
PostgreSQL runs one process per connection. A thousand mostly idle connections cost memory that is then bought as a bigger instance.
SELECT state, count(*) FROM pg_stat_activity GROUP BY state ORDER BY 2 DESC;
The fixPut a pooler in front, such as PgBouncer, and lower the number of server connections.
Each step makes the next one safer. Committing to a one or three year price is last because it locks in a size, so it should lock in the size you reached after the other steps.
The database bill doubled in a month and the traffic did not. Name the first three things you would check, in order.
Write your answer down first. Then open mine.
1. Storage and backups: table and index growth (bloat counts), snapshot retention, and logs kept longer than anyone meant. In PostgreSQL, pg_total_relation_size on the largest tables; in the bill, storage and backup lines.
2. I/O: a new report, export or missing index that scans a big table every few minutes. On I/O-billed storage, such as Aurora Standard, that shows up directly as cost.
3. Data transfer: a new replica in another zone or region, or an application now reading across zones. Replication traffic is billed every day, quietly.
Then instance size changes. Cost Explorer grouped by usage type usually points at one of these in a few minutes.
The same mechanism, sharding and partitioning, caches and memory, elsewhere on the site: in real incidents, in measurements, and in designs.
How do I run it in production? What to check when it is slow or broken, where it runs and what it costs, how big it must be, pooling, backups, security, upgrades and other changes made safely.