• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

.gitignoreH A D08-Nov-202172 54

Catalog.pmH A D08-Nov-20217.1 KiB273199

MakefileH A D08-Nov-20214.2 KiB9960

READMEH A D08-Nov-20215.9 KiB11295

aclchk.cH A D08-Nov-2021156.2 KiB5,8513,855

catalog.cH A D08-Nov-202114.8 KiB477210

dependency.cH A D08-Nov-202176.3 KiB2,6251,599

genbki.plH A D08-Nov-202114.9 KiB552385

heap.cH A D08-Nov-202198.4 KiB3,3081,823

index.cH A D08-Nov-2021119.9 KiB3,8221,880

indexing.cH A D08-Nov-20219.7 KiB334151

information_schema.sqlH A D08-Nov-2021107.6 KiB2,9621,928

namespace.cH A D08-Nov-2021121.7 KiB4,4612,545

objectaccess.cH A D08-Nov-20213 KiB12963

objectaddress.cH A D08-Nov-2021133.5 KiB5,1984,128

partition.cH A D08-Nov-202168.2 KiB2,4111,457

pg_aggregate.cH A D08-Nov-202128.4 KiB874558

pg_collation.cH A D08-Nov-20216.6 KiB239159

pg_constraint.cH A D08-Nov-202130.4 KiB1,110699

pg_conversion.cH A D08-Nov-20215.6 KiB211133

pg_db_role_setting.cH A D08-Nov-20217 KiB262179

pg_depend.cH A D08-Nov-202120.2 KiB777466

pg_enum.cH A D08-Nov-202116.6 KiB623355

pg_inherits.cH A D08-Nov-202111.3 KiB405209

pg_largeobject.cH A D08-Nov-20214.4 KiB183104

pg_namespace.cH A D08-Nov-20213.2 KiB11562

pg_operator.cH A D08-Nov-202124.9 KiB865505

pg_proc.cH A D08-Nov-202134 KiB1,164790

pg_publication.cH A D08-Nov-202112.4 KiB499308

pg_range.cH A D08-Nov-20213.6 KiB13991

pg_shdepend.cH A D08-Nov-202140.3 KiB1,481881

pg_subscription.cH A D08-Nov-202112.2 KiB528344

pg_type.cH A D08-Nov-202127.4 KiB870526

postgres.bkiH A D08-Nov-2021618.4 KiB6,6266,625

postgres.descriptionH A D08-Nov-2021114.4 KiB2,9142,913

postgres.shdescriptionH A D08-Nov-202149 21

schemapg.hH A D08-Nov-202119.3 KiB215186

storage.cH A D08-Nov-202115.6 KiB549290

system_views.sqlH A D08-Nov-202140.3 KiB1,1491,011

toasting.cH A D08-Nov-202112.8 KiB444263

README

1src/backend/catalog/README
2
3System Catalog
4==============
5
6This directory contains .c files that manipulate the system catalogs;
7src/include/catalog contains the .h files that define the structure
8of the system catalogs.
9
10When the compile-time scripts (Gen_fmgrtab.pl and genbki.pl)
11execute, they grep the DATA statements out of the .h files and munge
12these in order to generate the postgres.bki file.  The .bki file is then
13used as input to initdb (which is just a wrapper around postgres
14running single-user in bootstrapping mode) in order to generate the
15initial (template) system catalog relation files.
16
17-----------------------------------------------------------------
18
19People who are going to hose around with the .h files should be aware
20of the following facts:
21
22- It is very important that the DATA statements be properly formatted
23(e.g., no broken lines, proper use of white-space and _null_).  The
24scripts are line-oriented and break easily.  In addition, the only
25documentation on the proper format for them is the code in the
26bootstrap/ directory.  Just be careful when adding new DATA
27statements.
28
29- Some catalogs require that OIDs be preallocated to tuples because
30of cross-references from other pre-loaded tuples.  For example, pg_type
31contains pointers into pg_proc (e.g., pg_type.typinput), and pg_proc
32contains back-pointers into pg_type (pg_proc.proargtypes).  For such
33cases, the OID assigned to a tuple may be explicitly set by use of the
34"OID = n" clause of the .bki insert statement.  If no such pointers are
35required to a given tuple, then the OID = n clause may be omitted
36(then the system generates an OID in the usual way, or leaves it 0 in a
37catalog that has no OIDs).  In practice we usually preassign OIDs
38for all or none of the pre-loaded tuples in a given catalog, even if only
39some of them are actually cross-referenced.
40
41- We also sometimes preallocate OIDs for catalog tuples whose OIDs must
42be known directly in the C code.  In such cases, put a #define in the
43catalog's .h file, and use the #define symbol in the C code.  Writing
44the actual numeric value of any OID in C code is considered very bad form.
45Direct references to pg_proc OIDs are common enough that there's a special
46mechanism to create the necessary #define's automatically: see
47backend/utils/Gen_fmgrtab.pl.  We also have standard conventions for setting
48up #define's for the pg_class OIDs of system catalogs and indexes.  For all
49the other system catalogs, you have to manually create any #define's you
50need.
51
52- If you need to find a valid OID for a new predefined tuple,
53use the unused_oids script.  It generates inclusive ranges of
54*unused* OIDs (e.g., the line "45-900" means OIDs 45 through 900 have
55not been allocated yet).  Currently, OIDs 1-9999 are reserved for manual
56assignment; the unused_oids script simply looks through the include/catalog
57headers to see which ones do not appear in "OID =" clauses in DATA lines.
58(As of Postgres 8.1, it also looks at CATALOG and DECLARE_INDEX lines.)
59You can also use the duplicate_oids script to check for mistakes.
60
61- The OID counter starts at 10000 at bootstrap.  If a catalog row is in a
62table that requires OIDs, but no OID was preassigned by an "OID =" clause,
63then it will receive an OID of 10000 or above.
64
65- To create a "BOOTSTRAP" table you have to do a lot of extra work: these
66tables are not created through a normal CREATE TABLE operation, but spring
67into existence when first written to during initdb.  Therefore, you must
68manually create appropriate entries for them in the pre-loaded contents of
69pg_class, pg_attribute, and pg_type.  Avoid making new catalogs be bootstrap
70catalogs if at all possible; generally, only tables that must be written to
71in order to create a table should be bootstrapped.
72
73- Certain BOOTSTRAP tables must be at the start of the Makefile
74POSTGRES_BKI_SRCS variable, as these cannot be created through the standard
75heap_create_with_catalog process, because it needs these tables to exist
76already.  The list of files this currently includes is:
77	pg_proc.h pg_type.h pg_attribute.h pg_class.h
78Within this list, pg_type.h must come before pg_attribute.h.
79Also, indexing.h must be last, since the indexes can't be created until all
80the tables are in place, and toasting.h should probably be next-to-last
81(or at least after all the tables that need toast tables).  There are
82reputedly some other order dependencies in the .bki list, too.
83
84-----------------------------------------------------------------
85
86When munging the .c files, you should be aware of certain conventions:
87
88- The system catalog cache code (and most catalog-munging code in
89general) assumes that the fixed-length portions of all system catalog
90tuples are in fact present, because it maps C struct declarations onto
91them.  Thus, the variable-length fields must all be at the end, and
92only the variable-length fields of a catalog tuple are permitted to be
93NULL.  For example, if you set pg_type.typrelid to be NULL, a
94piece of code will likely perform "typetup->typrelid" (or, worse,
95"typetup->typelem", which follows typrelid).  This will result in
96random errors or even segmentation violations.  Hence, do NOT insert
97catalog tuples that contain NULL attributes except in their
98variable-length portions!  (The bootstrapping code is fairly good about
99marking NOT NULL each of the columns that can legally be referenced via
100C struct declarations ... but those markings won't be enforced against
101DATA commands, so you must get it right in a DATA line.)
102
103- Modification of the catalogs must be performed with the proper
104updating of catalog indexes!  That is, most catalogs have indexes
105on them; when you munge them using the executor, the executor will
106take care of doing the index updates, but if you make direct access
107method calls to insert new or modified tuples into a heap, you must
108also make the calls to insert the tuple into ALL of its indexes!  If
109not, the new tuple will generally be "invisible" to the system because
110most of the accesses to the catalogs in question will be through the
111associated indexes.
112