krebuild utility

This utility rebuilds a tables index directly from the data. This is faster than dropping exiting indices and creating new ones in SQL.

Unless the optional -f switch is specified, then a fast rebuild will be attempted using the existing sequence set and just rebuilding the index set to compact index block and optimally balance the index tree. This is a lot quicker than a full rebuild, as the data rows will not be examined. However, if the index is found to be inconsistent during a fast rebuild, then a full rebuild will be automatically performed. Full rebuilds will rebuild the free data chain.

This utility can reformat the index to a more modern index format. Unless the -4 switch is specified, then version 3.0 tables will be rebuilt as version 3 and version 4 tables will be rebuilt as version 4. With this switch, version 3.0 tables will be converted to version 4 tables. Similarly earlier versions can be converted to type 6 with the -6 switch. To convert tables to type 7 the kconvert utility must be used.

Switch Purpose
-c consolidate extents
-f full rebuild
-p partno specify 'partition' number to use when locking table
-s silent mode. No messages printed.
-u use access mode 'U' to open table
-v print version only
-V level set verbose level
-4 rebuild as type 4 index
-6 rebuild as type 6 index

If a partition number is not specified, then a unique partition number is automatically allocated using the normal KCML rules for allocating background partition numbers.

A significant amount of temporary work space of as much as twice the index size is required and this needs to be available in the systems temporary directory however the environment variable WORKSPACE determines where temporary work files are created and can be used to redirect work files to a bigger filesystem.

Archiving

The krebuild utility can be used to archive old entries in a table by copying them to an archive file, deleting the rows and rebuilding the indexes. This mode is controlled by some extra command line switches:

SwitchPurpose
-A colname dateArchive rows where the value of the colname column is less than the cutoff date. The iprefix for the column is optional but it must have a datatype of DATE. The date must be in YYYY-MM-DD format.
-B colname date1 date2Archive rows where the value of the colname column is greater than or equal to date1 and less than or equal to date2. The iprefix for the column is optional but it must have a datatype of DATE. The date must be in YYYY-MM-DD format.
-DDelete the archived rows.
-L sizeInclude up to size bytes of any BLOB columns. The size may be zero to ignore BLOBs or may be all to archive all the bytes in the BLOB. BLOB data is archived as quoted hexadecimal digits. If there is no BLOB data for a given column then unquoted word NULL is archived.
-hInclude the column names as the first row of a CSV archive.
-rRead only mode that will produce an archive log but not delete any data or rebuild the indexes.
-x extSpecify an extension for the archive file. The default is '.csv'.

The specified date column must exist and have the datatype of DATE. Rows with dates earlier than this date will be archived. Rows where this column has a NULL value will always be included in the archive.

Archiving will not delete the archived rows unless the -D flag is also present. The indexes will still be rebuilt though.

The CSV format used has the following properties

An example:

	krebuild -A savedate 2006-01-01 -D SO_01_HISTORY_0001

This will create a file SO_01_HISTORY_0001.csv containing the archive:

1851,1,2007-06-12,17:28:24,0000-00-00,00:00:00,"kcc","W","SL",0.00,0.00,0.00, ...
1850,1,2007-06-12,15:01:08,0000-00-00,00:00:00,"kcc","W","SL",0.00,0.00,0.00, ...
...