readme
来自「PostgreSQL7.4.6 for Linux」· 代码 · 共 110 行
TXT
110 行
$Header: /cvsroot/pgsql/src/backend/catalog/README,v 1.7 2002/04/27 21:24:33 tgl Exp $This directory contains .c files that manipulate the system catalogs;src/include/catalog contains the .h files that define the structureof the system catalogs.When the compile-time scripts (such as Gen_fmgrtab.sh and genbki.sh)execute, they grep the DATA statements out of the .h files and mungethese in order to generate the .bki files. The .bki files are thenused as input to initdb (which is just a wrapper around postgresrunning single-user in bootstrapping mode) in order to generate theinitial (template) system catalog relation files.-----------------------------------------------------------------People who are going to hose around with the .h files should be awareof the following facts:- It is very important that the DATA statements be properly formatted(e.g., no broken lines, proper use of white-space and _null_). Thescripts are line-oriented and break easily. In addition, the onlydocumentation on the proper format for them is the code in thebootstrap/ directory. Just be careful when adding new DATAstatements.- Some catalogs require that OIDs be preallocated to tuples becauseof cross-references from other pre-loaded tuples. For example, pg_typecontains pointers into pg_proc (e.g., pg_type.typinput), and pg_proccontains back-pointers into pg_type (pg_proc.proargtypes). For suchcases, the OID assigned to a tuple may be explicitly set by use of the"OID = n" clause of the .bki insert statement. If no such pointers arerequired to a given tuple, then the OID = n clause may be omitted(then the system generates a random OID in the usual way, or leaves it0 in a catalog that has no OIDs). In practice we usually preassign OIDsfor all or none of the pre-loaded tuples in a given catalog, even if onlysome of them are actually cross-referenced.- We also sometimes preallocate OIDs for catalog tuples whose OIDs mustbe known directly in the C code. In such cases, put a #define in thecatalog's .h file, and use the #define symbol in the C code. Writingthe actual numeric value of any OID in C code is considered very bad form.(Direct references to pg_proc OIDs are common enough that there's a specialmechanism to create the necessary #define's automatically: seebackend/utils/Gen_fmgrtab.sh. For all the other system catalogs, you haveto manually create any #define's you need.)- If you need to find a valid OID for a tuple that will be referred to byothers, use the unused_oids script. It generates inclusive ranges of*unused* OIDs (e.g., the line "45-900" means OIDs 45 through 900 havenot been allocated yet). Currently, OIDs 1-9999 are reserved for manualassignment; the unused_oids script simply looks through the include/catalogheaders to see which ones do not appear in "OID =" clauses.- OIDs 10000-16383 are reserved for assignment by the genbki.sh script:it will insert these OIDs if it sees a clause "OID = 0" in a DATAstatement. You would typically use this feature if you don't care exactlywhich OID is assigned to a catalog row (because it has no cross-referencesyou need to hardwire) but you want to give it a DESCR entry. The DESCR macrowill not work for rows that don't have any OID at genbki.sh time.- The OID counter starts at 16384 at bootstrap. If a catalog row is in atable that requires OIDs, but no OID was preassigned by hand or by genbki.sh,then it will receive an OID of 16384 or above.- To create a "BOOTSTRAP" table you have to do a lot of extra work: thesetables are not created through a normal CREATE TABLE operation, but springinto existence when first written to during initdb. Therefore, you mustmanually create appropriate entries for them in the pre-loaded contents ofpg_class, pg_attribute, and pg_type. You'll also need to add code to functionheap_create() in heap.c to force the correct OID to be assigned when the tableis first referenced. (It's near the top of the function with the commentbeginning in "Real ugly stuff".) Avoid making new catalogs be bootstrapcatalogs if at all possible; generally, only tables that must be written toin order to create a table should be bootstrapped.- Certain BOOTSTRAP tables must be at the start of the MakefilePOSTGRES_BKI_SRCS variable, as these will not be created through the standardheap_create_with_catalog process, because it needs these tables to existalready. The list of files this currently includes is: pg_proc.h pg_type.h pg_attribute.h pg_class.hAlso, indexing.h must be last, since the indexes can't be created until allthe tables are in place. There are reputedly some other order dependenciesin the .bki list, too.-----------------------------------------------------------------When munging the .c files, you should be aware of certain conventions:- The system catalog cache code (and most catalog-munging code ingeneral) assumes that the fixed-length portions of all system catalogtuples are in fact present, because it maps C struct declarations ontothem. Thus, the variable-length fields must all be at the end, andonly the variable-length fields of a catalog tuple are permitted to beNULL. For example, if you set pg_type.typdelim to be NULL, apiece of code will likely perform "typetup->typdelim" (or, worse,"typetyp->typelem", which follows typdelim). This will result inrandom errors or even segmentation violations. Hence, do NOT insertcatalog tuples that contain NULL attributes except in theirvariable-length portions!- Modification of the catalogs must be performed with the properupdating of catalog indexes! That is, most catalogs have indexeson them; when you munge them using the executor, the executor willtake care of doing the index updates, but if you make direct accessmethod calls to insert new or modified tuples into a heap, you mustalso make the calls to insert the tuple into ALL of its indexes! Ifnot, the new tuple will generally be "invisible" to the system becausemost of the accesses to the catalogs in question will be through theassociated indexes.
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?