.ig >>
<STYLE TYPE="text/css">
<!--
        A:link{text-decoration:none}
        A:visited{text-decoration:none}
        A:active{text-decoration:none}
        OL,UL,P,BODY,TD,TR,TH,FORM { font-family: arial,helvetica,sans-serif;; font-size:small; color: #333333; }

        H1 { font-size: x-large; font-family: arial,helvetica,sans-serif; }
        H2 { font-size: large; font-family: arial,helvetica,sans-serif; }
        H3 { font-size: medium; font-family: arial,helvetica,sans-serif; }
        H4 { font-size: small; font-family: arial,helvetica,sans-serif; }
-->
</STYLE>
<title>shsql: database maintenance</title>
<body bgcolor=99cc99 vlink=0000FF>
<br>
<br>
<center>
<table cellpadding=2 bgcolor=FFFFFF width=550 ><tr>
<td align=right><a href="shsql_home.html">
<img src="img/shsql.gif" border=0><br><small>SQL database system</a> &nbsp; </td></tr>
<td>
.>>

.TH database maintenance TDH "09-FEB-2005   TDH scg@jax.org" 

.ig >>
<br><br><br>
.>>
.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
.ig >>
<a href="create.html#index">
.>>
\0CREATE INDEX
.ig >>
</a>
.>>
(without the \fCLATER\fR option),
.ig >>
<a href="alter.html">
.>>
\0ALTER,
.ig >>
</a>
.>>
or the
.ig >>
<a href="dataedit.1.html">
.>>
\0dataedit(1)
.ig >>
</a>
.>>
utility (unless you elect not to rebuild indexes after editing).
.LP
\fCMAINTAIN\fR actually invokes a program in the \fBshsql\fR bin called 
.ig >>
<a href="tabmaint.1.html">
.>>
\0tabmaint(1)
.ig >>
</a>
.>>
(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
.ig >>
<a href="tablelocking.html">
.>>
\0write-locked
.ig >>
</a>
.>>
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>
.>>
.ig >>
<br><br><br>
.>>

.SH Other maintenance issues
.LP
Daily backups of data and code are a must.
.LP
Leftover
.ig >>
<a href="temptables.html#cleanup">
.>>
\0temporary files
.ig >>
</a>
.>>
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 
.ig >>
<a href="logs.html">
.>>
\0error log
.ig >>
</a>
.>>
will accumulate any database errors that occur.  
.LP
The
.ig >>
<a href="logs.html">
.>>
\0database transaction logs
.ig >>
</a>
.>>
will grow in size over time.  


.ig >>
<br>
<br>
</td></tr>
<td align=right>
<a href="shsql_home.html">
<img src="img/shsql.gif" border=0></a><br>
<a href="Copyright.html">Copyright Steve Grubb</a> &nbsp;
</td></tr>
</table>
.>>
