=> CREATE DATABASE wal_buffercache;
CREATE DATABASE
=> \c wal_buffercache
You are now connected to database "wal_buffercache" as user "postgres".
=> CREATE TABLE t(n integer);
CREATE TABLE
=> INSERT INTO t SELECT 1 FROM generate_series(1,10000);
INSERT 0 10000
Сколько страниц на диске занимает таблица?
=> SELECT setting FROM pg_settings WHERE name = 'block_size';
setting --------- 8192 (1 row)
=> SELECT pg_table_size('t') / 8192;
?column? ---------- 43 (1 row)
Из них основной слой:
=> SELECT pg_relation_size('t','main') / 8192;
?column? ---------- 40 (1 row)
И карта свободного пространства:
=> SELECT pg_relation_size('t','fsm') / 8192;
?column? ---------- 3 (1 row)
Сколько буферов в кэше занимает таблица?
=> CREATE EXTENSION pg_buffercache;
CREATE EXTENSION
=> SELECT CASE relforknumber WHEN 0 THEN 'main' WHEN 1 THEN 'fsm' WHEN 2 THEN 'vm' END relfork, count(*) FROM pg_buffercache b, pg_class c WHERE b.reldatabase = ( SELECT oid FROM pg_database WHERE datname = current_database() ) AND c.oid = 't'::regclass AND b.relfilenode = c.relfilenode GROUP BY 1;
relfork | count ---------+------- fsm | 2 main | 40 (2 rows)
=> SELECT count(*) FROM pg_buffercache b WHERE isdirty;
count ------- 88 (1 row)
=> CHECKPOINT;
CHECKPOINT
=> SELECT count(*) FROM pg_buffercache b WHERE isdirty;
count ------- 0 (1 row)
Грязных буферов не осталось. Подробнее о контрольной точке рассказывается в отдельной теме.