postgresql中fork的含义

发布时间 2023-06-23 13:50:45作者: lightdb

pg_relation_size ( relation regclass [fork text ] ) → bigint

Computes the disk space used by one fork” of the specified relation. (Note that for most purposes it is more convenient to use the higher-level functions pg_total_relation_size or pg_table_size, which sum the sizes of all forks.) With one argument, this returns the size of the main data fork of the relation. The second argument can be provided to specify which fork to examine:

  • main returns the size of the main data fork of the relation.

  • fsm returns the size of the Free Space Map (see Section 68.3) associated with the relation.

  • vm returns the size of the Visibility Map (see Section 68.4) associated with the relation.

  • init returns the size of the initialization fork, if any, associated with the relation,无日志表和索引有(参见https://postgrespro.com/blog/pgsql/5967858,恢复时用到).

 

  一个表通常具有4个fork,main(第一个,数据本身,包括表和索引), fsm,vm(对所有事务都可见的页面,仅包含冻结元素的页面,查询优化目的,索引没有vm,每个页面2位,第一位表示页面中的所有元素对所有事务可见,用于确认是否可使用Index only scan;第二位,表示页面是否冻结,如果冻结了,anti-wraparound vacuum不需要访问该页面。设置了一定成立,未设置未必不成立,pg_visibility可用来检查实际值),init。

  vacuum与否对性能还是有较大的影响,具体可参见postgresql/lightdb vacuum对性能的影响

 

 参考:

https://habr.com/en/company/postgrespro/blog/469087/