想知道 WAL ....
drop table big;
CREATE TABLE big(
bid integer PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
s char(1000)
) WITH (fillfactor = 10);
insert into big(s) values('foo');
checkpoint;
select pg_current_wal_lsn() ;
explain( analyze, costs off, verbose, timing off, buffers,settings, wal,timing off, summary)
delete from big;
select pg_current_wal_lsn() ;
回报:
QUERY PLAN
------------------------------------------------------
Delete on public.big (actual rows=0 loops=1)
Buffers: shared hit=2 dirtied=1
WAL: records=1 fpi=1 bytes=1119
-> Seq Scan on public.big (actual rows=1 loops=1)
Output: ctid
Buffers: shared hit=1 dirtied=1
Settings: search_path = 'public'
Query Identifier: 6906021239059634709
Planning:
Buffers: shared hit=2
Planning Time: 0.155 ms
Execution Time: 0.206 ms
(12 rows)
Parameter | Value
-----------------+-------
wal_compression | off
-----------------+-------
full_page_writes| on
页面元:
select * from page_header(get_raw_page('big',0));
lsn | checksum | flags | lower | upper | special | pagesize | version | prune_xid
------------+----------+-------+-------+-------+---------+----------+---------+-----------
1/D2FB7F90 | 0 | 0 | 28 | 7160 | 8192 | 8192 | 4 | 0
(1 row)
2 lsn位置做减法运算返回1160。
问题:
fpi = 1
意味着将 8192 字节转储到 WAL?WAL: records=1 fpi=1 bytes=1119
1119字节是什么意思?
相关: https: //wiki.postgresql.org/wiki/Full_page_writes
这个想法是在检查点之后为每个页面的第一次修改切换到“物理”日志记录,这是一种奇特的说法,我们将整个 8KB 页面转储到事务日志中,而不是描述如何更改它。
这
INSERT
是自上次修改该 8kB 页面的检查点以来的第一个事务(因为表是新的),因此 PostgreSQL将整个页面写入磁盘。这就是 FPI 的含义:F ull P age I mage。该页面大小为 8kB,但中间有一个洞。那个洞没有复制到WAL,所以实际的字节数要小一些。