Skip to content
dbexplore

Cost

What cold data costs

For anyone who suspects most of a database is never read, and needs to know how to find out, what it costs and what moving it would really save.

What cold data costs: bands of time since last read, reading last use from Postgres statistics, what moving it saves, and where the inference fails.

Reference page, revised in place. Last updated .

Paying active prices for data nobody touches

Tables accumulate. An events table grows for years, an audit table is written and never queried, a migration leaves a copy of the old data behind. The bill treats every byte alike, whether it was read this morning or has not been read since the person who created it left. Three questions follow. Which data is cold, what does keeping it cost, and what would a cheaper home actually save? The third has a less obvious answer than the first two, because it depends on how the platform charges for storage.

Bands of time since last use

Cold is a relative word, so a working definition helps. A band is a stretch of time since the data was last touched, and each step down trades slower or costlier retrieval for cheaper keeping.

Several bands cover most estates, and the names are yours to choose. Data read or written within days belongs on the fastest storage there is. Data touched in recent weeks is still queried, but not by the hot path. Data untouched for months is a candidate for review and for a cheaper volume. Data that has gone most of a year untouched can tolerate delay on the rare reads. And data kept only because something requires it means a restore, not a query, to get back.

The cut-offs between the bands are yours to choose, and they should be longer than your longest business cycle. A table read once a year for an audit is not cold in the way a table nobody has ever read is.

Reading when data was last touched

PostgreSQL keeps cumulative counters per table in pg_stat_all_tables, with pg_stat_user_tables as the user-tables subset. They have long carried seq_scan and idx_scan, which count scans since the statistics started. PostgreSQL 16 added last_seq_scan and last_idx_scan to those views and last_idx_scan to pg_stat_all_indexes and pg_stat_user_indexes. The manual defines each as the time of the last such scan, based on the most recent transaction stop time. They do not exist on PostgreSQL 15 and earlier, where the only option is to sample the counters on a schedule and note when they change.

The columns record reads. There is no matching timestamp for writes. The n_tup_ins, n_tup_upd and n_tup_del counters show that writes happen but not when, so the last write is found by sampling them, or from a timestamp column the application keeps. For size, pg_total_relation_size returns a table’s disk use including its indexes and TOAST data, which is the figure to set against a band. An index on a cold table is cold too, and is part of what moves. How to find indexes that nothing scans is in unused and missing indexes.

Three properties decide whether a timestamp can be believed.

A null means no scan since the counters started. It does not mean never. The manual says the statistics survive a clean shutdown, including that of a physical replica, and that all counters are reset after an unclean one: an immediate shutdown, a crash, starting from a base backup or point-in-time recovery. Calling pg_stat_reset() also zeroes them for the current database. In a test on PostgreSQL 18, a clean restart kept the values and an immediate stop followed by a start cleared them.

Each server keeps its own. A scan on a standby is counted on the standby and not on the primary. In the same test, two scans run on a hot standby appeared there and the primary still showed none. A table read only by reporting on a replica looks idle if only the primary is checked.

Maintenance and backups count as reads. In that test, plain VACUUM and ANALYZE left the scan counters alone. VACUUM FULL, REINDEX, CREATE INDEX, COPY and pg_dump each registered a sequential scan. A nightly logical dump therefore makes every table in it look warm, which is why the last-scan time of a table that is dumped regularly says little. The counters cannot say who did the reading, so for a table that is dumped regularly, use query-level statistics to find what the application itself reads.

What moving data does to the bill

The same move saves different amounts on different platforms.

On a provisioned managed service, storage is allocated and charged as allocated. The Amazon RDS documentation states that the amount of storage for a DB instance cannot be reduced once allocated, and its pricing page says storage is charged as provisioned. Moving cold data out of an RDS volume therefore saves nothing until the data lands on a smaller volume, which means a new instance. Google Cloud SQL does allow storage to be shrunk by hand, but its documentation says the operation needs downtime and restarts the instance. On both, the saving arrives as one planned event, not a gradual decline.

On a consumption-metered service, storage follows use. Amazon Aurora’s documentation says the charge is for space in use, and that on versions with dynamic resizing, when data is removed, for example by dropping or truncating a table, the allocated space decreases to match. Dropping or archiving a cold table lowers the bill directly. Deleting rows from a table that stays in place is different: the space is reused inside the table first, and the autovacuum and bloat guide explains why it is not simply handed back.

On self-hosted Postgres, the manual describes tablespaces as a way to place a table of rarely used archive data on a less expensive, slower disk, and lists moving seldom-used partitions to cheaper media as a benefit of partitioning. The saving exists only where such a disk is really cheaper and the old capacity can be retired.

Copies multiply all of it. A standby or streaming replica of the whole server holds every cold table too, as the manual says it can be done only for the entire database server, and backups keep it for the retention window.

A worked example

The figures are invented. A database holds 4,000 GB, and a review of last-scan times over a window longer than the business cycle finds that 2,500 GB has gone most of a year or more untouched. Suppose active storage costs $0.10 per GB-month and an archive tier $0.02. Moving the cold bytes saves 2,500 times $0.08, or $200 a month on one copy. With a primary and two replicas holding the same bytes, that is $600, if each copy can move. On a provisioned platform, add the cost and risk of the resize that has to happen before any of it appears on an invoice, and the engineer time of the migration.

Where the inference fails

An absence of scans is evidence, not proof. The window may be shorter than the business cycle. The statistics may have been reset by a crash. A replica may be the only reader. A table may be cold while its newest partition is hot, so the analysis needs to run per partition. Statistics say nothing about foreign keys, or about a job that runs once a year and will fail loudly if the table is gone. And retrieval has a price of its own, in latency, in restore time and in the engineering hours to bring a frozen table back. Treat the list as a set of candidates for a human decision, not as a deletion list.

Put every Postgres you run on autopilot.

We onboard teams in small batches. Tell us about your fleet and we will reach out when a seat opens. One email, no drip campaign.