Initialization fork

An empty table or index created for an unlogged table

An initialization fork is an empty table or index of the appropriate type created for an unlogged table. If the unlogged table is reinitialized following a crash, the initialization fork is copied over the main fork.

Source code

Code handling reinitialisation of unlogged tables is in: src/backend/storage/file/reinit.c, specifically the function ResetUnloggedRelations().

The latter is called from src/backend/access/transam/xlog.c in StartupXLOG().

Examples

The initialisation fork(s) are created with the suffix _init:

postgres=# CREATE UNLOGGED TABLE foo (id int primary key);
CREATE TABLE

postgres=# SELECT pg_relation_filepath('foo'), pg_relation_filepath('foo_pkey')
 pg_relation_filepath | pg_relation_filepath 
----------------------+----------------------
 base/13261/16499     | base/13261/16502
(1 row)

postgres:data$ ll base/13261/16499*
-rw------- 1 postgres postgres 0 Nov 17 11:01 base/13261/16499
-rw------- 1 postgres postgres 0 Nov 17 11:01 base/13261/16499_init

postgres:data$ ll base/13261/16502*
-rw------- 1 postgres postgres 8192 Nov 17 11:01 base/13261/16502
-rw------- 1 postgres postgres 8192 Nov 17 11:01 base/13261/16502_init

After inserting some data into the table:

postgres:data$ ll base/13261/16499*
-rw------- 1 postgres postgres 368640 Nov 17 11:09 base/13261/16499
-rw------- 1 postgres postgres  24576 Nov 17 11:09 base/13261/16499_fsm
-rw------- 1 postgres postgres      0 Nov 17 11:01 base/13261/16499_init

postgres:data$ ll base/13261/16502*
-rw------- 1 postgres postgres 245760 Nov 17 11:09 base/13261/16502
-rw------- 1 postgres postgres   8192 Nov 17 11:01 base/13261/16502_init

Categories

PostgreSQL internals, Storage