Search This Blog

Saturday, November 7, 2009

Postgresql - Storage Level

1.Page
Page is the fundamental storage unit of Postgre.
There is a figure in \src\include\storage\bufpage.h depicting page structure.



2.FSM
Postgre uses an additional page called "FSM"(free space mapping) page to indicate free spaces in heap pages.
Also, for each heap page, it is divided into BLOCKSIZE/256 parts, thus a byte is enough to record how much free space left in a page.
Actually, FSM is a tree structure. Suppose we have heap pages with free space values 3, 4, 0, 2. Then FSM structure is like this:
      4
  4        2
3   4    0   2
More details can be found in /src/backend/storage/freespace/README.

3.Virtual File Descriptor
Vfd is an wrapper of system file descriptor.
The reason to use this use such an object is that Postgre may open so many file descriptors for a variety of reasons-including base tables, sort and hash spool files, and etc-that the number of file descriptors being used is quite easy to exceed system limits.
Vfds are managed as an LRU pool, and all file descriptor operations(opening, closing and so on) should be through interfaces of vfds.
More details can be found in /src/backend/storage/file/fd.c .
Also, there is a file "buffile.c" under the same directory, which provides a very incomplete emulation of stdio atop virtual Files.

No comments:

Post a Comment