Download PDF file (1425K characters)

Transcript
Chapter 3: Tutorial
37
3.15.3 Database Maintenance
There are two principal operations of database management: expiration and
compaction. Expiration consists in removing expired entries from the database. In fact, it is rarely needed, since the expired entries are removed in the
process of normal mailfromd work. Nevertheless, a special option is provided in case an explicit expiration is needed (for example, before dumping
the database to another format, to avoid transferring useless information).
The command line option ‘--expire’ instructs mailfromd to delete expired entries from the specified database. As usual, the database is specified
using ‘--format’ option. If it is not given explicitly, ‘cache’ is assumed.
While removing expired entries the space they occupied is marked as free,
so it can be used by subsequent inserts. The database does not shrink after
expiration is finished. To actually return the unused space to the file system
you should compact your database.
This is done by running mailfromd --compact (and, optionally, specifying the database to operate upon with ‘--format’ option). Notice, that
compacting a database needs roughly as much disk space on the partition
where the database resides as is currently used by the database. Database
compaction runs in three phases. First, the database is scanned and all nonexpired records are stored in the memory. Secondly, a temporary database
is created in the state directory and all the cached entries are flushed into
it. This database is named after the PID of the running mailfromd process.
Finally, the temporary database is renamed to the source database.
Both ‘--compact’ and ‘--expire’ can be applied to all databases by
combining them with ‘--all’. It is useful, for example, in ‘crontab’ files.
For example, I have the following monthly job in my ‘crontab’:
0 1 1 * * /usr/local/sbin/mailfromd --compact --all
3.16 Testing Filter Scripts
It is important to check your filter script before actually starting to use it.
There are several ways to do so.
To test the syntax of your filter script, use the ‘--lint’ option. It will
cause mailfromd to exit immediately after attempting to compile the script
file. If the compilation succeeds, the program will exit with code 0. Otherwise, it will exit with error code 78 (‘configuration error’). In the latter
case, mailfromd will also print a diagnostic message, describing the error
along with the exact location where the error was diagnosed, for example:
mailfromd: /etc/mailfromd.mf:39: syntax error, unexpected reject
The error location is indicated by the name of the file and the number of
the line when the error occurred. By using the ‘--location-column’ option
you instruct mailfromd to also print the column number. E.g. with this
option the above error message may look like:
mailfromd: /etc/mailfromd.mf:39.12 syntax error, unexpected reject