shsql: database maintenance

SQL database system
| Manual page for database(maintenance)

## Table cleaning and index rebuild

Over time, updates cause shsql database tables to contain more and more "dead space". Also, any indexes associated with a table become increasingly out of date.`` Performance can often be improved if data files are cleaned up and indexes are regenerated from time to time.`` This can be done using shsql's `MAINTAIN` command:

  `$ shsql "maintain` tablename`"`

`MAINTAIN` is automatically invoked when you use CREATE INDEX (without the `LATER` option), ALTER, or the dataedit(1) utility (unless you elect not to rebuild indexes after editing).``

`MAINTAIN` actually invokes a program in the shsql bin called tabmaint(1) (you can invoke the program directly if you prefer).`` Either way, the table will be cleaned up and all indexes associated with the table rebuilt.

A suggested approach is to put `shsql MAINTAIN` or `tabmaint` invocations into your crontab, for every table that requires periodic cleaning and index rebuild.`` The frequency with which this should be done depends on the volume of database update that is occuring; anywhere between once per month and once per day seems reasonable.``

A table that is undergoing cleaning / index rebuild is automatically write-locked to prevent other processes from updating it during that time.`` Results are placed into a temp file, then a read-lock is held briefly while temp file replaces original data file.``

The tabmaint utility creates temporary files called `__tmpmaint_*` are in the data directory..`` if it is interrupted or abnormally terminates these files may be left around. They can be cleaned up as needed.``

## Other maintenance issues

Daily backups of data and code are a must.``

Leftover temporary files should be cleaned out occasionally. This can be automated by setting up a cron entry containing a find(1) command, such as this:

18 04 * * 3 /usr/bin/find /home/steve/dbproj/tmp ! -type d -mtime +1 -exec rm -f {} \;

The error log will accumulate any database errors that occur.

The database transaction logs will grow in size over time.
Copyright Steve Grubb

Markup created by unroff 1.0, `` `` February 09, 2005.