Fork

A concept describing the type of a relation's physical storage

In PostgreSQL's data directory, each relation's data is stored in a so-called fork:

  • main fork (no suffix)
  • freespace map (suffix: fsm)
  • visibility map (suffix: vm)
  • initialization fork (suffix: init)

The main fork, which contains the actual data (possibly split over multiple files), is always present.

Source code

src/include/common/relpath.h:

/*
 * 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;

src/common/relpath.c:

/*
 * 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 */
};

Examples

A relation with visibility and freespace map forks:

-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

Categories

PostgreSQL internals, Storage

See also

initialization_fork