在PostgreSQL的数据目录中,每个关系的数据都存储在所谓的fork
中
- 主fork(无后缀)
- 空闲空间映射(后缀:
fsm
) - 可见性映射(后缀:
vm
) - 初始化fork(后缀:
init
)
包含实际数据(可能分布在多个文件中)的主fork
始终存在。
源代码
/* * Stuff for fork names. * * The physical storage of a relation consists of one or more forks. * The main fork is always created, but in addition to that there can be * additional forks for storing various metadata. ForkNumber is used when * we need to refer to a specific fork in a relation. */ typedef enum ForkNumber { InvalidForkNumber = -1, MAIN_FORKNUM = 0, FSM_FORKNUM, VISIBILITYMAP_FORKNUM, INIT_FORKNUM ... } ForkNumber;
/* * Lookup table of fork name by fork number. * * If you add a new entry, remember to update the errhint in * forkname_to_number() below, and update the SGML documentation for * pg_relation_size(). */ const char *const forkNames[] = { "main", /* MAIN_FORKNUM */ "fsm", /* FSM_FORKNUM */ "vm", /* VISIBILITYMAP_FORKNUM */ "init" /* INIT_FORKNUM */ };
示例
具有可见性和空闲空间映射fork的关系
-rw------- 1 postgres postgres 36249600 21 Dec 15:59 16384 -rw------- 1 postgres postgres 32768 21 Dec 15:59 16384_fsm -rw------- 1 postgres postgres 8192 21 Dec 15:59 16384_vm