Skip to content

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_reset was unchanged across docker restart (SIGINT, fast shutdown) and jumped to the restart instant after SIGKILL, identically on supabase/postgres 17.6.1.136 and postgres 17.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 progress at the next start (CR01 stop-timing table).
  • A managed restart’s stop was the clean shape from the counters: stats_reset kept 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_scan survived REINDEX, REINDEX CONCURRENTLY (new index OID (object identifier), counters kept), VACUUM FULL and a clean restart, and read 0 after DROP INDEX plus CREATE INDEX, after create-concurrently-and-rename, after pg_stat_reset_single_table_counters and after crash recovery (HP03c, HP03d). Plain EXPLAIN does not count a scan; EXPLAIN (ANALYZE) does (HP03a).
  • A stats reset clears n_live_tup and 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_tables deltas 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_slru row names are lower case with underscores on 17.11 and CamelCase on 15.19, and pg_stat_reset_shared('slru') does not exist on 15.19 while pg_stat_reset_slru(NULL) works on both (MX00).
  • A healthy pg_database_size minus 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.
What you seeRead it asCheck
stats_reset moved to a restart timeAn unclean start, or a manual reset; not proven by the timestampThe 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 indexThe index may be young, rebuilt by drop and create, or reset; it may also serve shapes that cannot use itpg_stat_database.stats_reset, last_idx_scan, and the index OID against its age (HP03c)
idx_scan is 0 after a scheduled REINDEXNot caused by the REINDEX; the counter survived itA drop and create, or a create-concurrently-and-rename, in the maintenance script (HP03c)
n_live_tup is 0 on a large tableA reset counter if no vacuum or analyze is on record; empty if one isThe four timestamps in pg_stat_user_tables (notes)
A table’s counters look low after a loadThe read may be too earlyRead again after 15 s or more (EA02c)
pg_database_size is far above the sum of relation sizesFiles no relation owns, or an uncommitted rewriteA remainder above about 163 KB is a candidate list to inspect (notes)

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.

TargetRestart modestats_reset beforestats_reset afterChangednum_requested after
supabaseclean2026-10-01 06:37:07.994094+002026-10-01 06:37:07.994094+00false5
supabaseunclean2026-10-01 06:37:07.994094+002026-10-01 06:37:19.694786+00true1
vanillaclean2026-10-01 06:37:07.96934+002026-10-01 06:37:07.96934+00false5
vanillaunclean2026-10-01 06:37:07.96934+002026-10-01 06:37:22.461344+00true1

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.

VersionKilledStop-side logNext startStats
17.4 (postgres:17.4-alpine)postmaster onlycheckpoint complete from the surviving checkpointer, no database system is shut downdatabase system was shut down atkept
17.11 (postgres:17.11-alpine)postmaster onlysamesamekept
18.6 (postgres:18-alpine)postmaster onlysamesamereset
18.6 (bare cluster, system binaries)postmaster onlysamesamereset
17.11every Postgres process (pkill -9 postgres)checkpoint starting, no completeshutdown was interrupted, not properly shut down; automatic recovery in progressreset
17.11nothing (clean pg_ctl stop)database system is shut downwas shut down atkept
  • 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_reset that moved to a restart time should come with that startup line; if the startup log says was shut down at, look for something other than the stop path (an explicit pg_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_tup and all four vacuum and analyze timestamps together, and any later VACUUM or ANALYZE re-counts n_live_tup from 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.reltuples is 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_reset and a null pg_stat_database reset marker on a hosted project all pointed at one wipe 10 days earlier in those notes.

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.

Operationidx_scan before to afterIndex OIDlast_idx_scanpg_stat_database.stats_reset
REINDEX INDEX85 to 85same (16721)keptnever to never
REINDEX INDEX CONCURRENTLY90 to 90changed (16721 to 16778)keptnever to never
DROP INDEX, then CREATE INDEX of the same name95 to 0changed (16778 to 16779)nullnever to never
CREATE INDEX CONCURRENTLY a twin, DROP INDEX the old, RENAME the twin5 to 0changed (16779 to 16780)nullnever to never
VACUUM FULL of the table5 to 5same (16780)keptnever to never
pg_stat_reset_single_table_counters('items_hnsw')10 to 0samenullnever 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 EXPLAIN of a query added 0 to idx_scan; EXPLAIN (ANALYZE) of the same query added 20. A shape that cannot use the index (a MATERIALIZED CTE (common table expression) returning the distance, an OFFSET 0 subquery, ORDER BY 1 - distance) left idx_scan unchanged, 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): REINDEX and REINDEX CONCURRENTLY do not reset idx_scan, and only DROP plus CREATE does; a scheduled REINDEX therefore 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_scan after a failover or a hosted project’s maintenance restart, and the effect of pg_upgrade on 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.

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_size minus 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 a supabase/postgres:17.12.0.006 container after pgbench. It did not grow with 120,000 relations.
  • kill -9 of a VACUUM FULL backend 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.
  • 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_scan on PG 18 and later, on a replica, after a failover and after pg_upgrade; the PG 13 to 19 REINDEX claim 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.
  • 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.
PracticeEvidenceModule
Check the startup log before reading a moved stats_reset as a crashOn 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 logsCR01
Compare idx_scan with stats_reset, last_idx_scan and the index OIDA REINDEX kept the counter; drop and create, create-concurrently-and-rename and a single-table reset zeroed itHP03c
Read idx_scan 0 on a shape-bound index as undecidedA shape that cannot use the index leaves idx_scan unchangedHP03a
Use EXPLAIN (ANALYZE) knowing it counts a scanPlain EXPLAIN: 0; EXPLAIN (ANALYZE): +20 for 20 executionsHP03a
Wait 15 s before reading table counters after a burst7 / 1 / 7 at 3 s, 10 / 3 / 10 at 15 sEA02c
Match pg_stat_slru rows by both spellings across majorsLower case with underscores on 17.11, CamelCase on 15.19; one reset function missing on 15.19MX00
Read 0 live rows plus no vacuum on record as a resetThe reset clears n_live_tup and the four timestamps togetherpg-analyser notes, no lab record
Treat a size remainder above about 163 KB as files to inspectAbout 158 to 163 KB on healthy PG 15 to 19; a 151 MB orphan after a killed VACUUM FULLpg-analyser notes, no lab record

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.

ClaimStatusHow it was checked
Clean restart keeps and SIGKILL resets pg_stat_checkpointer, both imagesmeasured, 2 runs, local DockerCR01 RUNLOG; no out/ artifact is published
The version-dependent kill during the shutdown checkpointmeasured, 2 runs per rowsame RUNLOG, 2026-10-01 section
Managed restart kept stats_reset 3 of 3measured, one project, counters onlyplatform-downtime D01, as recorded in the CR01 RUNLOG
idx_scan across REINDEX variants, VACUUM FULL, drop and create, single-table reset, restartsmeasured, PG 17.12, HNSW index; runs A and D agreeHP03, run facts
Table counters undercount 3 s after writesmeasured once, cause not isolatedEA02c, facts
pg_stat_slru names and reset functionsmeasured, 4 imagesMX00, facts
Clean shutdown keeps stats, unclean start resets themdocumented1doc-read for this page, PostgreSQL 17
n_live_tup and timestamps cleared together; idx_scan on PG 13 to 19; the size gapnotes only2pg-analyser records, throwaway containers, not re-run
ModuleExperimentTestArtifact
CR01checkpointer-resetcr01-restart-mode.tsnone published (RUNLOG)
HP03hnsw-plan-shapeshp03-idx-scan.tsrun-2026-12-03T06-46-21-869Z
EA02cextension-aclea02-write-paths.tsrun-2026-12-03T06-31-30-455Z
MX00multixact-slrumx00-inventory.tsrun-2026-12-03T06-15-53-848Z
D01 (cited)platform-downtimerecorded in the CR01 RUNLOG, not re-readRUNLOG
  1. PostgreSQL Global Development Group, “The Cumulative Statistics System,” PostgreSQL 17 Documentation. https://www.postgresql.org/docs/17/monitoring-stats.html ↩ ↩2 ↩3 ↩4

  2. 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