Although Postfix uses file locking to avoid access conflicts
while updating Berkeley DB or other local database files, you still
have a problem when the update fails because the disk is full or
because something else happens. This is because commands such as
postmap(1) or
postalias(1) overwrite existing files. If the update
fails in the middle then you have no usable database, and Postfix
will stop working. This is not an issue with the CDB database type
available with Postfix 2.2 and later, because
CDB
database rebuilds are atomic.
With multi-file databases such as DBM, there is no simple
solution. With Berkeley DB and other "one file" databases, it is
possible to add some extra robustness by using "mv" to REPLACE an
existing database file instead of overwriting it:
# postmap access.in && mv access.in.db access.db
This converts the input file "access.in" into the output file
"access.in.db", and replaces the file "access.db" only when the
postmap(1) command was successful. Of course typing such commands
becomes boring quickly, and this is why people use "make" instead,
as shown below. User input is shown in bold font.
# cat Makefile
all: aliases.db access.db virtual.db ...etcetera...
# Note 1: commands are specified after a TAB character.
# Note 2: use
postalias(1) for local aliases,
postmap(1) for the rest.
aliases.db: aliases.in
postalias aliases.in
mv aliases.in.db aliases.db
access.db: access.in
postmap access.in
mv access.in.db access.db
virtual.db: virtual.in
postmap virtual.in
mv virtual.in.db virtual.db
...etcetera...
# vi access.in
...editing session not shown...
# make
postmap access.in
mv access.in.db access.db
#
The "make" command updates only the files that have changed.
In case of error, the "make" command will stop and will not invoke
the "mv" command, so that Postfix will keep using the existing
database file as if nothing happened.