Review
New pg_stat_tablespace view for tablespace level metrics (v10)
- Proposal version
- 10
- Base commit
- 412848dac37f2e4455e1505f83f0af0f3d28a67d
Assessment
PostgreSQL's pg_stat_io reports I/O metrics across backend contexts and object types, but does not break down metrics by tablespace. This feature patch introduces a new cumulative statistics view, pg_stat_tablespace, reporting block reads/hits, read/write times, temporary file metrics, and tuple operations per tablespace.
Key aspects of version 10:
- Addresses stats leakage across DROP TABLESPACE: flushes now only look up existing entries without auto-creating, while CREATE TABLESPACE and first-use initialize the entry safely.
- Eliminates hot-path hash table lookups during block time accounting by using a compact local array for active tablespaces between flushes.
- Corrects statistics routing when objects are moved between tablespaces across transactions.
- Adds comprehensive documentation in monitoring.sgml and isolation test coverage.
The patch was applied on base commit 412848dac37f2e4455e1505f83f0af0f3d28a67d, compiled with zero warnings, and successfully linked.
Discussion and Consensus
The thread shows extensive, constructive discussion across 10 iterations. Reviewers Zsolt Parragi and Andres Freund identified edge- case statistics leaks on dropped tablespaces and hot-path overhead in earlier versions. The author addressed both issues in v10 with eager creation semantics and array-based buffering. The patch is maturing well toward committer consideration.