Re: [Patch] New pg_stat_tablespace view

From: shihao zhong <zhong950419(at)gmail(dot)com>
To: Andres Freund <andres(at)anarazel(dot)de>
Cc: Bernd Reiß <bd_reiss(at)gmx(dot)at>, Ahmed Gouda <ahmed(dot)gouda(at)cybertec(dot)at>, Zsolt Parragi <zsolt(dot)parragi(at)percona(dot)com>, songjinzhou <tsinghualucky912(at)foxmail(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>, jian he <jian(dot)universality(at)gmail(dot)com>
Subject: Re: [Patch] New pg_stat_tablespace view
Date: 2026-09-24 15:22:50
Message-ID: CAGRkXqQM90=58C=ht+nEFk7MTp1GMV8F3fw4Jg5z+NM3Wbu=tg@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi Andres,

v8 counts the time in pgstat_count_io_op_time(), next to the per-backend
time. bufmgr.c and localbuf.c call a variant that takes the tablespace OID
as one more argument, and that is their whole change. The last tablespace
entry used is cached, so the usual case is one compare and an add, with no
hash lookup. The times are flushed with the IO stats, so the checkpointer
and bgwriter changes are gone.

It also fixes an assertion failure at shutdown in v7, after dropping a
tablespace the checkpointer had written to. There is a test for it in
029_stats_restart.pl.

As for why, here is one tablespace on a RAM disk and one on the SSD, same
table, same 5000 random lookups, with debug_io_direct=data to keep the OS
cache out:

tablespace_name | blks_read | blk_read_time | us_per_block
-----------------+-----------+---------------+--------------
ts_ssd | 9645 | 667.8 | 69.2
ts_ram | 9645 | 170.1 | 17.6

pg_stat_io and pg_stat_database only show the sum.

Regards,
Shihao

Attachment Content-Type Size
pg_stat_tablespace-v8.patch application/octet-stream 70.2 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Heikki Linnakangas 2026-09-24 15:23:14 Re: [PATCH] Two remaining shmem attachment issues in single-user mode
Previous Message Peter Eisentraut 2026-09-24 15:15:28 Re: run pgindent in CI