在PostgreSQL的数据目录中,每个关系的实际数据都存储在一个称为fork的文件中
- 主分叉(无后缀)
- 空闲空间图(后缀:
fsm) - 可见性图(后缀:
vm) - 初始化分叉(后缀:
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 */
};
示例
具有可见性图和空闲空间图分叉的关系
-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
