#set TITLE = "database maintenance"
#include top

#include  space
.SH Table cleaning and index rebuild
Over time, updates cause \fBshsql\fR 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 \fBshsql's\fR \fCMAINTAIN\fR command:
.IP
\fC$ shsql "maintain \fItablename\fC "
.LP
\fCMAINTAIN\fR is automatically invoked when you use
#set FILE = "create.html#index"
#set TAG = "CREATE INDEX"
#include link
(without the \fCLATER\fR option),
#set FILE = "alter.html"
#set TAG = "ALTER,"
#include link
or the
#set FILE = "dataedit.1.html"
#set TAG = "dataedit(1)"
#include link
utility (unless you elect not to rebuild indexes after editing).
.LP
\fCMAINTAIN\fR actually invokes a program in the \fBshsql\fR bin called 
#set FILE = "tabmaint.1.html"
#set TAG = "tabmaint(1)"
#include link
(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.  
.LP
A suggested approach is to put \fCshsql MAINTAIN\fR or \fCtabmaint\fR invocations into your 
\fBcrontab\fR, 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.
.LP
A table that is undergoing cleaning / index rebuild is automatically
#set FILE = "tablelocking.html"
#set TAG = "write-locked"
#include link
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.
.LP
The tabmaint utility creates temporary files called \fC__tmpmaint_*\fR 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.

.ig >>
<a name=other></a>
.>>
#include space

.SH Other maintenance issues
.LP
Daily backups of data and code are a must.
.LP
Leftover
#set FILE = "temptables.html#cleanup"
#set TAG = "temporary files"
#include link
should be cleaned out occasionally.  This can be automated by setting up
a cron entry containing a find(1) command, such as this:
.LP
18 04 * * 3 /usr/bin/find /home/steve/dbproj/tmp ! -type d  -mtime +1 -exec rm -f {} \\;

.LP
The 
#set FILE = "logs.html"
#set TAG = "error log"
#include link
will accumulate any database errors that occur.  
.LP
The
#set FILE = "logs.html"
#set TAG = "database transaction logs"
#include link
will grow in size over time.  


#include bottom
