| 1 |
src/backend/storage/smgr/README |
| 2 |
|
| 3 |
Storage Managers |
| 4 |
================ |
| 5 |
|
| 6 |
In the original Berkeley Postgres system, there were several storage managers, |
| 7 |
of which only the "magnetic disk" manager remains. (At Berkeley there were |
| 8 |
also managers for the Sony WORM optical disk jukebox and persistent main |
| 9 |
memory, but these were never supported in any externally released Postgres, |
| 10 |
nor in any version of PostgreSQL.) The "magnetic disk" manager is itself |
| 11 |
seriously misnamed, because actually it supports any kind of device for |
| 12 |
which the operating system provides standard filesystem operations; which |
| 13 |
these days is pretty much everything of interest. However, we retain the |
| 14 |
notion of a storage manager switch in case anyone ever wants to reintroduce |
| 15 |
other kinds of storage managers. Removing the switch layer would save |
| 16 |
nothing noticeable anyway, since storage-access operations are surely far |
| 17 |
more expensive than one extra layer of C function calls. |
| 18 |
|
| 19 |
In Berkeley Postgres each relation was tagged with the ID of the storage |
| 20 |
manager to use for it. This is gone. It would be probably more reasonable |
| 21 |
to associate storage managers with tablespaces, should we ever re-introduce |
| 22 |
multiple storage managers into the system catalogs. |
| 23 |
|
| 24 |
The files in this directory, and their contents, are |
| 25 |
|
| 26 |
smgr.c The storage manager switch dispatch code. The routines in |
| 27 |
this file call the appropriate storage manager to do storage |
| 28 |
accesses requested by higher-level code. smgr.c also manages |
| 29 |
the file handle cache (SMgrRelation table). |
| 30 |
|
| 31 |
md.c The "magnetic disk" storage manager, which is really just |
| 32 |
an interface to the kernel's filesystem operations. |
| 33 |
|
| 34 |
Note that md.c in turn relies on src/backend/storage/file/fd.c. |
| 35 |
|
| 36 |
|
| 37 |
Relation Forks |
| 38 |
============== |
| 39 |
|
| 40 |
Since 8.4, a single smgr relation can be comprised of multiple physical |
| 41 |
files, called relation forks. This allows storing additional metadata like |
| 42 |
Free Space information in additional forks, which can be grown and truncated |
| 43 |
independently of the main data file, while still treating it all as a single |
| 44 |
physical relation in system catalogs. |
| 45 |
|
| 46 |
It is assumed that the main fork, fork number 0 or MAIN_FORKNUM, always |
| 47 |
exists. Fork numbers are assigned in src/include/common/relpath.h. |
| 48 |
Functions in smgr.c and md.c take an extra fork number argument, in addition |
| 49 |
to relfilelocator and block number, to identify which relation fork you want to |
| 50 |
access. Since most code wants to access the main fork, a shortcut version of |
| 51 |
ReadBuffer that accesses MAIN_FORKNUM is provided in the buffer manager for |
| 52 |
convenience. |