📄 ug_ch13.htm
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2//EN"><html><head><meta name="generator" content="HTML Tidy for Linux/x86 (vers 1 September 2005), see www.w3.org"><meta http-equiv="content-type" content="text/html; charset=us-ascii"><meta name="Generator" content="Microsoft Word 97"><title>db.* User's Guide Chapter 13</title></head><body><h1><a name="Maintenance"></a>Chapter 13<br>Maintenance Utilities</h1><h2><a name="Introduction"></a>13.1 Introduction</h2><p><font size="2">This chapter describes the use of additionalutility programs that are part of the basic <b><i>db.*</i></b>system. These utilities support database maintenance andadministration tasks. They are listed in Table 13-1below.</font></p><p align="center"><b>Table 13-1. <i>db.*</i> Utilities</b></p><table border cellspacing="1" cellpadding="7" width="487"><tr><td width="24%" valign="top"><p><b><font size="2">Utility</font></b></p></td><td width="76%" valign="top"><p><b><font size="2">Definition</font></b></p></td></tr><tr><td width="24%" valign="top"><p><b><font size="2">datdump</font></b></p></td><td width="76%" valign="top"><p><font size="2">Formatted Data File Dump Utility</font></p></td></tr><tr><td width="24%" valign="top"><p><b><font size="2">dbcheck</font></b></p></td><td width="76%" valign="top"><p><font size="2">Database Consistency Check Utility</font></p></td></tr><tr><td width="24%" valign="top"><p><b><font size="2">dchain</font></b></p></td><td width="76%" valign="top"><p><font size="2">Delete Chain Sort Utility</font></p></td></tr><tr><td width="24%" valign="top"><p><b><font size="2">initdb</font></b></p></td><td width="76%" valign="top"><p><font size="2">Database Initialization Utility</font></p></td></tr><tr><td width="24%" valign="top"><p><b><font size="2">keybuild</font></b></p></td><td width="76%" valign="top"><p><font size="2">Key File Build Utility</font></p></td></tr><tr><td width="24%" valign="top"><p><b><font size="2">keydump</font></b></p></td><td width="76%" valign="top"><p><font size="2">Formatted Key File Dump Utility</font></p></td></tr><tr><td width="24%" valign="top"><p><b><font size="2">keypack</font></b></p></td><td width="76%" valign="top"><p><font size="2">Key File Packing Utility</font></p></td></tr><tr><td width="24%" valign="top"><p><b><font size="2">prdbd</font></b></p></td><td width="76%" valign="top"><p><font size="2">Database Dictionary Print Utility</font></p></td></tr><tr><td width="24%" valign="top"><p><b><font size="2">dbclrlb</font></b></p></td><td width="76%" valign="top"><p><font size="2">Clear Lock Bit Utility</font></p></td></tr></table><p><font size="2"> </font></p><h2><a name="datdump"></a>13.2 Formatted Data File Dump Utility(datdump)</h2><p><font size="2">The <b>datdump</b> utility displays a formatteddump of the contents of a <b><i>db.*</i></b> data file. In additionto the data field contents, <b>datdump</b> displays all of theinformation in the record header, including the record id, databaseaddress, record lock bit setting, stored optional keys, timestampvalues, set pointers, and member pointers.</font></p><p>This utility is particularly useful in gaining an understandingof the structure of a <b><i>db.*</i></b> data file as described insection 14.2.2, "Data File Organization." The <b>datdump</b>utility is executed as follows:</p><pre><font color="#0000FF">datdump [-h] [-x] [-f] [-<i>rslotno</i>]<b> </b><i>dbname</i><b> </b><i>datfile</i></font></pre><p><font size="2">where <i>datfile</i> is the name of the data filein database <i>dbname</i> whose contents will be displayed. If the<b>-h</b> option is specified, only the record header informationis printed. If the <b>-x</b> option is specified, the reportproduces a hex dump but no formatted dump of each record. If the<b>-f</b> option is specified, a formatted dump is printed but nohex dump is printed. If none of these options are specified thenthe result is a full dump including header, data fields, and hexrecord dump. The <b>-r</b> option can be used to instruct<b>datdump</b> to dump only the contents of the record at thespecified slot number, <i>slotno</i>, in <i>datfile</i>. The reportis written to file <b>stdout</b> and can be redirected asneeded.</font></p><h2><a name="dbcheck"></a>13.3 Database Consistency Check Utility(dbcheck)</h2><p><font size="2">The <b>dbcheck</b> utility checks the consistencyof a database by validating the location and key values associatedwith each record and key in the data and key files. The position ofeach record in a data file is verified, and each key field ischecked to ensure that it exists. For each key in a key file, thekey field contents in the associated record are checked to ensurethat they match the data stored in the key file. (The consistencyof optional key fields can only be guaranteed for optional keysthat exist; missing optional keys cannot be reported.) All lockedrecord occurrences (that is, set Record Lock Bits) will also bereported by <b>dbcheck</b>.</font></p><p>The <b>dbcheck</b> utility can (optionally) perform setconsistency checking. Set membership consistency verifies that:</p><p>1. The member and owner record types are valid<br>2. The membership count is correct<br>3. The doubly linked lists are properly formed</p><p>Key file structure consistency checks performed (optionally)verify that:</p><p>1. All B-tree pages are either in the B-tree or are deleted<br>2. All B-tree null child pointers are at the same tree level<br>3. B-tree key order is correct<br>4. Duplicate keys are correct</p><p>In addition, <b>dbcheck</b> can also verify the consistency oftimestamps.</p><p>The <b>dbcheck</b> utility has several parameters (see Chapter2, "Utility Descriptions," of the <b><i>db.*</i> ReferenceManual</b> for the full definition), but the most common method toinvoke it is shown below:</p><pre><font color="#0000FF">dbcheck {[-s] [-k] [-dk] [-kd] [-a][-ts] [-r#] [-p#] [-f#] [-t] [-c] } dbname [dbfile...]</font></pre><p><font size="2">The name of the database to be checked is<i>dbname</i>, and <i>dbfile</i> is the name of one or more fileswithin <i>dbname</i> to be checked. If no files are specified, theconsistency of the entire database is checked. The <b>-s</b> optionenables the checking of set consistency. The <b>-k</b> optionperforms key file structure checking. The <b>-dk</b> option checksthat the key file contains the key for each key field in each datafile. The <b>-kd</b> option checks that a record exists for eachkey in each key file. The <b>-ts</b> option performs timestampconsistency checks. All of these options are turned on by the<b>-a</b> option.</font></p><p>The <b>-r#</b> option reports every # percentage completed tofile <b>stderr</b>. The <b>-p#</b> option sets to <b>#</b> thenumber of pages in the cache for use by <b>dbcheck</b>. The<b>-f#</b> option sets to <b>#</b> the number of open files for<b>dbcheck</b>. The <b>-t</b> option prints a traceback of theB-tree when a key file inconsistency is detected. The <b>-c</b>option prints a count of the objects scanned in the check.</p><p>Database inconsistencies will be reported with a messagedescribing the nature of the error and the database address of therecord involved in the inconsistency.</p><h2><a name="dchain"></a>13.4 Delete Chain Sort Utility(dchain)</h2><p><font size="2">The <b>dchain</b> utility sorts the deletedrecord slots on the delete chain into database address order. Thepurpose is to increase the probability that newly created recordsin the same file will be placed close together. The extent of anyperformance improvement, however, will depend upon the application.Its most likely use would be after a periodic purge of particularrecord types that tend to be entered together, as they would leavemany contiguous record slots on the delete chain. This utility isinvoked as follows:</font></p><pre><font color="#0000FF">dchain <i>dbname</i> [<i>dbfile</i>]</font></pre><p><font size="2">where <i>dbname</i> is the name of the databaseand <i>dbfile</i> is the name of one or more data files in<i>dbname</i> whose delete chain is to be sorted. If no files arelisted then all data files in <i>dbname</i> will beprocessed.</font></p><h2><a name="initdb"></a>13.5 Database Initialization Utility(initdb)</h2><p><font size="2">A database must be initialized before any datacan be stored in it. This initialization can be done dynamicallythrough function calls, through use of <b>ida</b>, or by usingutility <b>initdb</b>. Execute <b>initdb</b> as follows:</font></p><pre><font color="#0000FF">initdb <i>[</i>-y<i>] dbname</i></font></pre><p><font size="2">where <i>dbname</i> is the name by which thedatabase to be initialized is defined in the <b>database</b>statement in DDL specification. The program will display the namesof the database files and prompt you for confirmation. If you replywith a <b>y</b>, then the files are reinitialized; otherwise theprogram terminates. If the <b>-y</b> option is specified, theninitialization will proceed without displaying the file names andconfirmation prompt.</font></p><h2><a name="keybuild"></a>13.6 Key File Build Utility(keybuild)</h2><p><font size="2">Utility <b>keybuild</b> will rebuild all keyfiles for a database. It rebuilds the key files by firstreinitializing the file, and then sequentially reading all recordsfrom each data file and re-creating each key field from thecontents of the record.</font></p><p>The <b>keybuild</b> utility can be used to re-create the keyfiles when there is a key file inconsistency (for example, asreported by <b>dbcheck</b>). It can also construct new key filesafter you have added or removed key attributes from fields in yourDDL specification. For example, if you make an existing key field anon-key, or change a non-key to a key field in your DDL, you canrun <b>keybuild</b> to rebuild the key files for the new schema.You can also use <b>keybuild</b> to reassign key fields todifferent key files.</p><p>Optional keys are re-created by keybuild from the optional keystored bit flags contained in the record header. To run keybuild,enter the following command line:</p><pre><font color="#0000FF">keybuild <i>dbname</i></font></pre><p><font size="2">where <i>dbname</i> is the name of the databasewhose key files are to be rebuilt.</font></p><h2><a name="keydump"></a>13.7 Formatted Key File Dump Utility(keydump)</h2><p><font size="2">Utility <b>keydump</b> will display a formatteddump of a database key file. The B-tree organization of a<b><i>db.*</i></b> key file dump is described in section 14.2.3,"Key File Organization." <b>keydump</b> can assist you in learninghow these files are structured. It is invoked asfollows:</font></p><pre><font color="#0000FF">keydump [-h] <i>dbname</i> <i>keyfile</i></font></pre><p><font size="2">where <i>keyfile</i> is the name of the key filein database <i>dbname</i> whose contents will be displayed. If the<b>-h</b> option is specified, the key values are printed inhexadecimal; otherwise the contents are displayed as formatted forthe data type of the key field. The report is written to standardoutput and can be redirected as needed.</font></p><h2><a name="keypack"></a>13.8 Key File Pack Utility (keypack)</h2><p><font size="2">B-tree sorting algorithms allow for dynamicinsertion and deletion of keys in B-tree nodes (see section 14.2.3,"Key File Organization"). It is the nature of these algorithms toleave approximately 20 to 30 percent of the file unused. Forapplications that have frequent key updates, this is requiredoverhead. Other applications may build their key files first, thenuse them primarily for lookups. In such applications, where thekeys will not be changing, it is possible to run <b>keypack</b> tofill each node in the B-tree, thereby reducing the number of nodesrequired in the key file. This results in significant savings indisk space and lookup times in large databases.</font></p><p>The <b>keypack</b> utility has several parameters (see Chapter2, "Utility Descriptions," of the <b><i>db.*</i> ReferenceManual</b> for the full definitions). The utility is invoked asfollows:</p><pre><font color="#0000FF">keypack <i>[</i>-u<i>num] [</i>-o<i>|</i>-x<i>] [</i>-t <i>path] [</i>-b <i>path] [</i>-k <i>path] [</i>-p<i>num] dbname [keyfile]</i></font></pre><p><font size="2">where <i>dbname</i> is the name of the databasewhose key files are to be packed. All key files will be packedunless a specific key file, <i>keyfile</i>, is specified. The<b>-u</b> option specifies the number of key slots per node to beleft unfilled. If the key file is to be modifiable, <i>num</i> mustbe 1 or greater (default is 1). If <i>num</i> is 0, the key fieldscontained in the key file must all be declared in static records(see section 4.2.5, "Record Declarations").</font></p><p>Option <b>-o</b> opens the database in one-user mode; option<b>-x</b> opens the database in exclusive access mode. Option<b>-t</b> specifies the location (<i>path</i>) of the temporarypacked key file. When finished, the original key file is deletedand the temporary packed key file is renamed to the original keyfile name.</p><p>Option <b>-b</b> specifies the <i>path</i> where a backup of theoriginal key files will be copied. Option <b>-k</b> specifies the<i>path</i> where the packed key files will be placed. Option<b>-p</b> sets pages in the <b><i>db.*</i></b> cache to<i>num</i>.</p><h2><a name="prdbd"></a>13.9 Database Dictionary Print Utility(prdbd)</h2><p><font size="2">The <b>prdbd</b> utility displays the contents ofthe database dictionary file (<b>dbname.dbd</b>). <b>prdbd</b> willreport the default database page size and each entry in the filetable, record table, field table, set table, member table, sortfield table, and key table.</font></p><p>Section 14.3, "Database Dictionary Table Structure," describesin detail the organization of a <b><i>db.*</i></b> dictionary. Thisutility can be used to help you understand and make use of thedictionary in your own applications.</p><p>To run <b>prdbd</b>, enter the following command:</p><pre><font color="#0000FF">prdbd <i>[</i>-c<i>] dbname</i></font></pre><p><font size="2">where <i>dbname</i> is the name of the databasewhose dictionary will be displayed. Option <b>-c</b> specifies thatsymbolic names be omitted from the report. The report will bewritten to standard output and can be redirected asdesired.</font></p><h2><a name="dbclrlb"></a>13.10 Clear Lock Bit Utility(dbclrlb)</h2><p><font size="2">The <b>dbclrlb</b> utility clears any set lockbits in the specified data files. If no data files are specified,all lock bits in the database are cleared, including those ondeleted and undeleted records.</font></p><p>To run <b>dbclrlb</b>, enter the following command:</p><pre><font color="#0000FF">dbclrlb <i>dbname [data_files]</i></font></pre><p><font size="2">where <i>dbname</i> is the name of the databasewhose lock bits will be cleared. All files will be cleared unlessfiles are specified with <i>data_files</i>.</font></p><p><a href="UG_Ch14.htm">Next Page</a></p></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -