Supabase and PostgresDatabase and Postgresreference
Postgres statistics counters: stats_reset, idx_scan and what resets them
A Postgres cumulative counter says how many times something happened since it was last zeroed, and the view rarely says when that was or why. A report built on idx_scan, n_live_tup, pg_stat_statements or pg_stat_checkpointer reads the counter and assumes a window. This page collects the measured cases where that assumption fails: what clears the counters, what survives which maintenance command, how soon after traffic a counter can be read, and a size figure that no relation accounts for. It is a different kind of record from the collation version, which is also a stored value that says less than it appears to.
TL;DR
- A clean restart keeps cumulative stats and an unclean start resets them:
pg_stat_checkpointer.stats_resetwas unchanged acrossdocker restart(SIGINT, fast shutdown) and jumped to the restart instant afterSIGKILL, identically onsupabase/postgres17.6.1.136 andpostgres17.11-alpine (CR01).1 - The log does not always say which. A postmaster-only SIGKILL (kill signal) 0.4 to 0.5 s into the shutdown checkpoint left both logs clean on 17.4, 17.11 and 18.6; the stats were kept on 17.4 and 17.11 and reset on 18.6. Killing every Postgres process on 17.11 reset them and logged
not properly shut down; automatic recovery in progressat the next start (CR01 stop-timing table). - A managed restart’s stop was the clean shape from the counters:
stats_resetkept on 3 of 3 restarts of a Micro project in ap-southeast-1, with 43.3 to 75.9 s from the first stop line to the new postmaster start (platform-downtime D01, 2026-10-13). idx_scansurvivedREINDEX,REINDEX CONCURRENTLY(new index OID (object identifier), counters kept),VACUUM FULLand a clean restart, and read 0 afterDROP INDEXplusCREATE INDEX, after create-concurrently-and-rename, afterpg_stat_reset_single_table_countersand after crash recovery (HP03c, HP03d). PlainEXPLAINdoes not count a scan;EXPLAIN (ANALYZE)does (HP03a).- A stats reset clears
n_live_tupand all four vacuum and analyze timestamps together, so “0 live rows with no vacuum on record” is the reset signature and “0 live rows with a vacuum on record” a genuinely empty table (notes, postgres:17-alpine 17.11). - A counter read soon after traffic can undercount: the
pg_stat_user_tablesdeltas for one table read 7 / 1 / 7 (inserts, updates, deletes) 3 s after a burst and 10 / 3 / 10 after 15 s (EA02c). pg_stat_slrurow names are lower case with underscores on 17.11 and CamelCase on 15.19, andpg_stat_reset_shared('slru')does not exist on 15.19 whilepg_stat_reset_slru(NULL)works on both (MX00).- A healthy
pg_database_sizeminus the sizes of all relation forks was about 158 to 163 KB on PG 15 to 19 (notes), so a larger remainder is a file no relation owns, a candidate for orphaned files and not a proof of them.
Which do I pick
Section titled “Which do I pick”| What you see | Read it as | Check |
|---|---|---|
stats_reset moved to a restart time | An unclean start, or a manual reset; not proven by the timestamp | The next-start log: not properly shut down on 17.x (CR01). On 18.x a clean-looking log was also seen with the stats lost |
idx_scan is 0 on an index | The index may be young, rebuilt by drop and create, or reset; it may also serve shapes that cannot use it | pg_stat_database.stats_reset, last_idx_scan, and the index OID against its age (HP03c) |
idx_scan is 0 after a scheduled REINDEX | Not caused by the REINDEX; the counter survived it | A drop and create, or a create-concurrently-and-rename, in the maintenance script (HP03c) |
n_live_tup is 0 on a large table | A reset counter if no vacuum or analyze is on record; empty if one is | The four timestamps in pg_stat_user_tables (notes) |
| A table’s counters look low after a load | The read may be too early | Read again after 15 s or more (EA02c) |
pg_database_size is far above the sum of relation sizes | Files no relation owns, or an uncommitted rewrite | A remainder above about 163 KB is a candidate list to inspect (notes) |
Restarts and stats_reset (CR01)
Section titled “Restarts and stats_reset (CR01)”Two throwaway PG 17 containers: supabase/postgres:17.6.1.136 (the tag the self-hosted compose file pinned at the time, with its command:, environment: and healthcheck: blocks) and postgres:17.11-alpine. Per target: 3 CHECKPOINT, read pg_stat_checkpointer, a clean restart (docker restart, whose stop signal is SIGINT on both tags, Postgres’s fast shutdown), read again, 2 more CHECKPOINT, an unclean restart (docker kill -s SIGKILL, then docker start), read again. 4 pass, 0 fail, 0 skip, in two runs with the same result.
| Target | Restart mode | stats_reset before | stats_reset after | Changed | num_requested after |
|---|---|---|---|---|---|
| supabase | clean | 2026-10-01 06:37:07.994094+00 | 2026-10-01 06:37:07.994094+00 | false | 5 |
| supabase | unclean | 2026-10-01 06:37:07.994094+00 | 2026-10-01 06:37:19.694786+00 | true | 1 |
| vanilla | clean | 2026-10-01 06:37:07.96934+00 | 2026-10-01 06:37:07.96934+00 | false | 5 |
| vanilla | unclean | 2026-10-01 06:37:07.96934+00 | 2026-10-01 06:37:22.461344+00 | true | 1 |
Both images behave identically at the image and entrypoint layer. The PostgreSQL documentation says the same: a clean shutdown stores a permanent copy of the statistics so they survive restarts, and starting from an unclean shutdown (an immediate shutdown, a crash, a base backup, point-in-time recovery) resets all statistics counters.1 The supabase container’s command sets log_min_messages=fatal, so its server log could not confirm the fast-shutdown sequence that vanilla’s log showed (received fast shutdown request, checkpoint starting: shutdown immediate, checkpoint complete, database system is shut down, then database system was shut down at at the next boot); only its counters behave the same. On vanilla the unclean start logged database system was interrupted, then database system was not properly shut down; automatic recovery in progress.
Killing during the shutdown checkpoint (2026-10-01)
Section titled “Killing during the shutdown checkpoint (2026-10-01)”A later shape dirtied about 2 GB of shared_buffers with an UPDATE, sent the postmaster SIGINT (fast mode) and then SIGKILL 0.4 to 0.5 s later while the shutdown checkpoint was still writing (it takes 1.6 to 2.6 s here). Containers stayed alive on sleep infinity with Postgres under pg_ctl, so killing the postmaster did not tear down the namespace; both signals went in one docker exec so exec latency could not delay the SIGKILL. Two runs per row.
| Version | Killed | Stop-side log | Next start | Stats |
|---|---|---|---|---|
17.4 (postgres:17.4-alpine) | postmaster only | checkpoint complete from the surviving checkpointer, no database system is shut down | database system was shut down at | kept |
17.11 (postgres:17.11-alpine) | postmaster only | same | same | kept |
18.6 (postgres:18-alpine) | postmaster only | same | same | reset |
| 18.6 (bare cluster, system binaries) | postmaster only | same | same | reset |
| 17.11 | every Postgres process (pkill -9 postgres) | checkpoint starting, no complete | shutdown was interrupted, not properly shut down; automatic recovery in progress | reset |
| 17.11 | nothing (clean pg_ctl stop) | database system is shut down | was shut down at | kept |
- On PG 17 a postmaster-only kill mid-checkpoint keeps the stats with both logs clean; on 18.6 the same shape logs clean and loses them. Why the versions differ was not read from the source.
- On 17 the only shape here that reset the stats is the whole-process kill, and it is visible in the next start’s log. So on a 17.x project a
stats_resetthat moved to a restart time should come with that startup line; if the startup log sayswas shut down at, look for something other than the stop path (an explicitpg_stat_reset_shared, a restore). - The first bare-cluster attempt on 18.6 is where an earlier “clean logs plus a reset” note came from; it holds for 18 only. In that attempt zsh did not word-split
kill -9 $PM $KIDS, so only the postmaster died.
On the managed platform, the lab’s platform-downtime D01 (three POST /restart runs, 2026-10-13, Micro, ap-southeast-1) recorded the stop and boot lines Postgres writes to postgres_logs beside stats_reset: stop fast on 1 of 3 runs by D01’s patterns (received fast shutdown request); on all 3, terminating connection due to administrator command and the database system is shutting down were logged; the next boot was not logged on any run; stats_reset was kept on 3 of 3. That is the clean-stop shape, read from the counters only: the shutdown checkpoint, database system is shut down, was shut down at and not properly shut down did not reach postgres_logs, so the grace period is not readable there. First stop line to new postmaster start: 75.9, 44.7 and 43.3 s. The earlier managed observation that prompted CR01, a stats_reset at a restart whose log read “fast shutdown request”, was not reproduced locally; the stop path of the managed platform is not observable from a container.
What a reset clears besides the counters (notes)
Section titled “What a reset clears besides the counters (notes)”From pg-analyser’s notes, run on postgres:17-alpine (17.11) on 2026-09-03 and not re-run here:2
- A stats reset clears
n_live_tupand all four vacuum and analyze timestamps together, and any laterVACUUMorANALYZEre-countsn_live_tupfrom its own scan. So “0 live rows with a vacuum or analyze on record” is a genuinely empty table and “0 live rows with none” is the reset signature. pg_class.reltuplesis not decisive: it survives a reset, but a vacuum that skipped all-visible pages leaves it as an extrapolation (a queue table read 2,946 while empty).- Postgres resets all cumulative stats on any unclean start, so one wipe can make 20 or more busy tables read as “never vacuumed”. The pg_stat_statements age, the checkpointer
stats_resetand a nullpg_stat_databasereset marker on a hosted project all pointed at one wipe 10 days earlier in those notes.
idx_scan across maintenance (HP03)
Section titled “idx_scan across maintenance (HP03)”Run on pgvector/pgvector:0.8.7-pg17 (PostgreSQL 17.12, pgvector 0.8.7) with an HNSW (Hierarchical Navigable Small World) index items_hnsw on a table of 100,000 vectors. Counters were read from a second connection after the workload connection ran pg_stat_force_next_flush(). Each row is preceded by 5 scans; the idx_scan and OID cells of run A and run D agree.
| Operation | idx_scan before to after | Index OID | last_idx_scan | pg_stat_database.stats_reset |
|---|---|---|---|---|
REINDEX INDEX | 85 to 85 | same (16721) | kept | never to never |
REINDEX INDEX CONCURRENTLY | 90 to 90 | changed (16721 to 16778) | kept | never to never |
DROP INDEX, then CREATE INDEX of the same name | 95 to 0 | changed (16778 to 16779) | null | never to never |
CREATE INDEX CONCURRENTLY a twin, DROP INDEX the old, RENAME the twin | 5 to 0 | changed (16779 to 16780) | null | never to never |
VACUUM FULL of the table | 5 to 5 | same (16780) | kept | never to never |
pg_stat_reset_single_table_counters('items_hnsw') | 10 to 0 | same | null | never to 2026-12-03 06:48:33 UTC (Coordinated Universal Time) |
Every row changed the file (relfilenode_changed yes) except the counter reset. REINDEX CONCURRENTLY swaps in a new index with a new OID and kept the counters; the manual create-concurrently-and-rename route created a new index with zeroed counters. The single-table reset moved the database’s stats_reset from never to its own time; the other rows did not. Restarts, items_hnsw before and after: a clean SIGINT fast shutdown and start kept 5 and a partial index’s 4, with stats_reset unchanged and no recovery in the log; a SIGKILL of the container and start read 10 to 0 (the partial index 4 to 0), stats_reset back to never, with crash recovery in the log. After the crash-recovery start every counter read 0.
- HP03a, 20 executions per shape: plain
EXPLAINof a query added 0 toidx_scan;EXPLAIN (ANALYZE)of the same query added 20. A shape that cannot use the index (aMATERIALIZEDCTE (common table expression) returning the distance, anOFFSET 0subquery,ORDER BY 1 - distance) leftidx_scanunchanged, so an index that serves such queries and no others reads 0 while the table is being scanned sequentially. That result belongs to the HNSW plan shapes in the lab experiment; the counter behaviour in the table does not depend on them. - Documented in pg-analyser’s notes, on PG 13 to 19 throwaway containers (2026-12-03, no lab artifact):
REINDEXandREINDEX CONCURRENTLYdo not resetidx_scan, and onlyDROPplusCREATEdoes; a scheduledREINDEXtherefore does not make an index look unused, while a scheduled drop and create does.2 The counter is per server, so a replica counts its own scans, and it gives no index age. - Not measured in HP03: PostgreSQL 18 and later, a replica’s counters,
idx_scanafter a failover or a hosted project’s maintenance restart, and the effect ofpg_upgradeon counters.
Reading a counter soon after traffic (EA02c)
Section titled “Reading a counter soon after traffic (EA02c)”In the extension-acl experiment (local Docker, supabase/postgres 17.11.0.018 with PostgREST 14.18) the module issued 10 inserts (4 API (application programming interface) requests and 6 seeds), 3 updates and 10 deletes (4 API requests and 6 cleanup rows) against one table whose pg_stat_user_tables counters read 8500 / 0 / 0 (n_tup_ins, n_tup_upd, n_tup_del) before. Read 3 s after the last write the deltas were 7 / 1 / 7; read 15 s after they were 10 / 3 / 10. Idle pooled backends flushing late is the likely cause of the 3 s gap; the run did not isolate it, so a counter read soon after a write can undercount. The HP03 reads above ran pg_stat_force_next_flush() on the workload connection before reading from a second connection; whether that closes the gap EA02c saw was not tested.
pg_stat_slru names and reset functions (MX00)
Section titled “pg_stat_slru names and reset functions (MX00)”pg_stat_slru counts the simple least-recently-used (SLRU) caches, and its row names differ by major version on the four images MX00 read: commit_timestamp, multixact_member, multixact_offset, notify, other, serializable, subtransaction, transaction on 17.11 (stock and supabase), and CommitTs, MultiXactMember, MultiXactOffset, Notify, other, Serial, Subtrans, Xact on 15.19. Anything that matches rows by name, an alert or a detector, needs both spellings.1 pg_stat_reset_shared('slru') does not exist on 15.19 (ERROR: unrecognized reset target: "slru"); pg_stat_reset_slru(NULL) works on all four. The multixact use of these counters is in Postgres MultiXact SLRU contention.
The database size gap (notes)
Section titled “The database size gap (notes)”From pg-analyser’s notes, 2026-12-03, checked on throwaway containers and on three hosted Postgres 17.6 projects, not re-run here:2
- A healthy
pg_database_sizeminus all relation forks (shared catalogs excluded) was about 158 to 163 KB on PG 15 to 19: 158,867 bytes on all three hosted projects and 161,459 on asupabase/postgres:17.12.0.006container afterpgbench. It did not grow with 120,000 relations. kill -9of aVACUUM FULLbackend left a 151 MB file that no relation owns after crash recovery. An uncommitted rewrite’s new file matches the same shape, so a large remainder is a candidate for orphaned files and not a proof of them.
What was not measured
Section titled “What was not measured”- Managed-platform stop paths beyond the three D01 restarts: the signal sent, the grace period, and whether a slow shutdown checkpoint can be interrupted. The CR01 restarts ran on near-idle clusters whose shutdown checkpoint finished in well under a second, so “preserves stats” holds for an unhurried clean stop.
- Why 18.6 loses the stats after a postmaster-only kill that 17.4 and 17.11 keep; the source was not read.
idx_scanon PG 18 and later, on a replica, after a failover and afterpg_upgrade; the PG 13 to 19REINDEXclaim has no lab artifact.- A counter read at times between 3 s and 15 s after writes, and the cause of the 3 s undercount.
- The size-gap figures on hosted projects other than the three; no lab experiment covers the size gap.
Reading the numbers
Section titled “Reading the numbers”- Version, image and platform are named on each row: 17.6.1.136 and 17.11 for CR01, 17.4, 17.11 and 18.6 for the stop-timing table, PG 17.12 for HP03, 17.11.0.018 for EA02c, 15.19 and 17.11 for MX00.
- The restart tests are one or two runs per row on a near-idle container; the stop-timing table is two runs per row. They show which behaviours exist, not their frequency.
- The notes sections carry no module id because no lab artifact exists for them; they stand on pg-analyser’s records and should be re-run before a decision rests on them.
What to do about it
Section titled “What to do about it”| Practice | Evidence | Module |
|---|---|---|
Check the startup log before reading a moved stats_reset as a crash | On 17.x a reset came with not properly shut down; a postmaster-only kill kept the stats on 17.4 and 17.11, lost them on 18.6 with clean logs | CR01 |
Compare idx_scan with stats_reset, last_idx_scan and the index OID | A REINDEX kept the counter; drop and create, create-concurrently-and-rename and a single-table reset zeroed it | HP03c |
Read idx_scan 0 on a shape-bound index as undecided | A shape that cannot use the index leaves idx_scan unchanged | HP03a |
Use EXPLAIN (ANALYZE) knowing it counts a scan | Plain EXPLAIN: 0; EXPLAIN (ANALYZE): +20 for 20 executions | HP03a |
| Wait 15 s before reading table counters after a burst | 7 / 1 / 7 at 3 s, 10 / 3 / 10 at 15 s | EA02c |
Match pg_stat_slru rows by both spellings across majors | Lower case with underscores on 17.11, CamelCase on 15.19; one reset function missing on 15.19 | MX00 |
| Read 0 live rows plus no vacuum on record as a reset | The reset clears n_live_tup and the four timestamps together | pg-analyser notes, no lab record |
| Treat a size remainder above about 163 KB as files to inspect | About 158 to 163 KB on healthy PG 15 to 19; a 151 MB orphan after a killed VACUUM FULL | pg-analyser notes, no lab record |
Reproducing
Section titled “Reproducing”The CR01 rig is experiments/checkpointer-reset (make local-up, make local-probe, make local-down); the stop-timing table’s scripts were session scratch and are re-created from its table. HP03 is make probe ONLY=HP03 in experiments/hnsw-plan-shapes; EA02c and MX00 run in their own experiments.
Evidence
Section titled “Evidence”| Claim | Status | How it was checked |
|---|---|---|
Clean restart keeps and SIGKILL resets pg_stat_checkpointer, both images | measured, 2 runs, local Docker | CR01 RUNLOG; no out/ artifact is published |
| The version-dependent kill during the shutdown checkpoint | measured, 2 runs per row | same RUNLOG, 2026-10-01 section |
Managed restart kept stats_reset 3 of 3 | measured, one project, counters only | platform-downtime D01, as recorded in the CR01 RUNLOG |
idx_scan across REINDEX variants, VACUUM FULL, drop and create, single-table reset, restarts | measured, PG 17.12, HNSW index; runs A and D agree | HP03, run facts |
| Table counters undercount 3 s after writes | measured once, cause not isolated | EA02c, facts |
pg_stat_slru names and reset functions | measured, 4 images | MX00, facts |
| Clean shutdown keeps stats, unclean start resets them | documented1 | doc-read for this page, PostgreSQL 17 |
n_live_tup and timestamps cleared together; idx_scan on PG 13 to 19; the size gap | notes only2 | pg-analyser records, throwaway containers, not re-run |
Modules
Section titled “Modules”| Module | Experiment | Test | Artifact |
|---|---|---|---|
| CR01 | checkpointer-reset | cr01-restart-mode.ts | none published (RUNLOG) |
| HP03 | hnsw-plan-shapes | hp03-idx-scan.ts | run-2026-12-03T06-46-21-869Z |
| EA02c | extension-acl | ea02-write-paths.ts | run-2026-12-03T06-31-30-455Z |
| MX00 | multixact-slru | mx00-inventory.ts | run-2026-12-03T06-15-53-848Z |
| D01 (cited) | platform-downtime | recorded in the CR01 RUNLOG, not re-read | RUNLOG |
Related docs
Section titled “Related docs”- Postgres collation version drift and
REFRESH COLLATION VERSION- the same lesson for a recorded version: the stored value moves independently of the thing it is supposed to describe. - Postgres MultiXact SLRU contention -
pg_stat_slruread as the evidence of a latency penalty, with the row names from MX00. - Supabase incident classes and client workarounds - restart timings from the same platform-downtime experiment on 2026-08-04 (n = 1), beside the three 2026-10-13 restarts whose counters are read here.
- Postgres lock table capacity and out of shared memory - another case where a documented figure is a floor rather than the observed limit.
- Extension-owned tables on Supabase Postgres - the experiment that produced the read-after-write undercount above (EA02c), beside its measurements of grants on extension tables.
References
Section titled “References”-
PostgreSQL Global Development Group, “The Cumulative Statistics System,” PostgreSQL 17 Documentation. https://www.postgresql.org/docs/17/monitoring-stats.html ↩ ↩2 ↩3 ↩4
-
pg-analyser, “AGENTS.md” (the 2026-09-03 and 2026-12-03 additions), GitHub, commit 7fd0dc4. https://github.com/erfianugrah/pg-analyser/blob/7fd0dc4958964dc540a43c0ab47ba2696d5a18f2/AGENTS.md ↩ ↩2 ↩3 ↩4