Home | History | Annotate | Line # | Download | only in html
      1 <!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN"
      2         "https://www.w3.org/TR/html4/loose.dtd">
      3 
      4 <html>
      5 
      6 <head>
      7 
      8 <title>Postfix Berkeley DB Howto</title>
      9 
     10 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
     11 <link rel='stylesheet' type='text/css' href='postfix-doc.css'>
     12 
     13 </head>
     14 
     15 <body>
     16 
     17 <h1><img src="postfix-logo.jpg" width="203" height="98" ALT="">Postfix Berkeley DB Howto</h1>
     18 
     19 <hr>
     20 
     21 <h2>Introduction</h2>
     22 
     23 <p> Postfix uses databases of various kinds to store and look up
     24 information. Postfix databases are specified as "type:name".
     25 Berkeley DB implements the Postfix database type "hash" and
     26 "btree".  The name of a Postfix Berkeley DB database is the name
     27 of the database file without the ".db" suffix. Berkeley DB databases
     28 are maintained with the <a href="postmap.1.html">postmap(1)</a> command.  </p>
     29 
     30 <p> Note: Berkeley DB version 4 is not supported by Postfix versions
     31 before 2.0.  </p>
     32 
     33 <p> This document describes: </p>
     34 
     35 <ol>
     36 
     37 <li> <p> How to build Postfix <a href="#disable_db">without Berkeley
     38 DB support</a> even if the system comes with Berkeley DB. </p>
     39 
     40 <li> <p> How to build Postfix on <a href="#no_db">systems that
     41 normally have no Berkeley DB library</a>. </p>
     42 
     43 <li> <p> How to build Postfix on <a href="#bsd">BSD</a> or <a
     44 href="#linux">Linux</a> systems with multiple Berkeley DB
     45 versions.  </p>
     46 
     47 <li> <p> How to <a href="#tweak">tweak</a> performance. </p>
     48 
     49 <li> <p> Missing <a href="#pthread">pthread</a> library trouble. </p>
     50 
     51 </ol>
     52 
     53 <h2><a name="disable_db">Building Postfix without Berkeley
     54 DB support even if the system comes with Berkeley DB</a></h2>
     55 
     56 <p> Note: The following instructions apply to Postfix 2.9 and later. </p>
     57 
     58 <p> Postfix will normally enable Berkeley DB support if the system
     59 is known to have it. To build Postfix without Berkeley DB support,
     60 build the makefiles as follows: </p>
     61 
     62 <blockquote>
     63 <pre>
     64 % make makefiles CCARGS="-DNO_DB"
     65 % make
     66 </pre>
     67 </blockquote>
     68 
     69 <p> This will disable support for "hash" and "btree" files. </p>
     70 
     71 <h2><a name="no_db">Building Postfix on systems that normally have
     72 no Berkeley DB library</a></h2>
     73 
     74 <p> Some UNIXes ship without Berkeley DB support; for historical
     75 reasons these use DBM files instead. A problem with DBM files is
     76 that they can store only limited amounts of data. To build Postfix
     77 with
     78 Berkeley DB support you need to download and install the source
     79 code from <a href="https://www.oracle.com/database/technologies/related/berkeleydb.html">https://www.oracle.com/database/technologies/related/berkeleydb.html</a>. </p>
     80 
     81 <p> Warning: some Linux system libraries use Berkeley DB, as do
     82 some third-party libraries such as SASL. If you compile Postfix
     83 with a different Berkeley DB implementation, then every Postfix
     84 program will dump core because either the system library, the SASL
     85 library, or Postfix itself ends up using the wrong version. </p>
     86 
     87 <p>The more recent Berkeley DB versions have a compile-time switch,
     88 "--with-uniquename", which renames the symbols so that multiple
     89 versions of Berkeley DB can co-exist in the same application.
     90 Although wasteful, this may be the only way to keep things from
     91 falling apart. </p>
     92 
     93 <p> To build Postfix after you installed the Berkeley DB from
     94 source code, use something like: </p>
     95 
     96 <blockquote>
     97 <pre>
     98 % make makefiles CCARGS="-DHAS_DB -I/usr/local/BerkeleyDB/include" \
     99     AUXLIBS="-L/usr/local/BerkeleyDB/lib -ldb"
    100 % make
    101 </pre>
    102 </blockquote>
    103 
    104 <p> If your Berkeley DB shared library is in a directory that the RUN-TIME
    105 linker does not know about, add a "-Wl,-R,/path/to/directory" option after
    106 "-ldb". </p>
    107 
    108 <p> Solaris needs this: </p>
    109 
    110 <blockquote>
    111 <pre>
    112 % make makefiles CCARGS="-DHAS_DB -I/usr/local/BerkeleyDB/include" \
    113     AUXLIBS="-R/usr/local/BerkeleyDB/lib -L/usr/local/BerkeleyDB/lib -ldb"
    114 % make
    115 </pre>
    116 </blockquote>
    117 
    118 <p> The exact pathnames depend on the Berkeley DB version, and on
    119 how it was installed. </p>
    120 
    121 <p> Warning: the file format produced by Berkeley DB version 1 is
    122 not compatible with that of versions 2 and 3 (versions 2 and 3 have
    123 the same format). If you switch between DB versions, then you may
    124 have to rebuild all your Postfix DB files. </p>
    125 
    126 <p> Warning: if you use Berkeley DB version 2 or later, do not
    127 enable DB 1.85 compatibility mode. Doing so would break fcntl file
    128 locking. </p>
    129 
    130 <p> Warning: if you use Perl to manipulate Postfix's Berkeley DB
    131 files, then you need to use the same Berkeley DB version in Perl
    132 as in Postfix.  </p>
    133 
    134 <h2><a name="bsd">Building Postfix on BSD systems with multiple
    135 Berkeley DB versions</a></h2>
    136 
    137 <p> Some BSD systems ship with multiple Berkeley DB implementations.
    138 Normally, Postfix builds with the default DB version that ships
    139 with the system. </p>
    140 
    141 <p> To build Postfix on BSD systems with a non-default DB version,
    142 use a variant of the following commands: </p>
    143 
    144 <blockquote>
    145 <pre>
    146 % make makefiles CCARGS=-I/usr/include/db3 AUXLIBS=-ldb3
    147 % make
    148 </pre>
    149 </blockquote>
    150 
    151 <p> Warning: the file format produced by Berkeley DB version 1 is
    152 not compatible with that of versions 2 and 3 (versions 2 and 3 have
    153 the same format). If you switch between DB versions, then you may
    154 have to rebuild all your Postfix DB files. </p>
    155 
    156 <p> Warning: if you use Berkeley DB version 2 or later, do not
    157 enable DB 1.85 compatibility mode. Doing so would break fcntl file
    158 locking. </p>
    159 
    160 <p> Warning: if you use Perl to manipulate Postfix's Berkeley DB
    161 files, then you need to use the same Berkeley DB version in Perl
    162 as in Postfix.  </p>
    163 
    164 <h2><a name="linux">Building Postfix on Linux systems with multiple
    165 Berkeley DB versions</a></h2>
    166 
    167 <p> Some Linux systems ship with multiple Berkeley DB implementations.
    168 Normally, Postfix builds with the default DB version that ships
    169 with the system. </p>
    170 
    171 <p> Warning: some Linux system libraries use Berkeley DB. If you
    172 compile Postfix with a non-default Berkeley DB implementation, then
    173 every Postfix program will dump core because either the system
    174 library or Postfix itself ends up using the wrong version. </p>
    175 
    176 <p> On Linux, you need to edit the makedefs script in order to
    177 specify a non-default DB library.  The reason is that the location
    178 of the default db.h include file changes randomly between vendors
    179 and between versions, so that Postfix has to choose the file for
    180 you. </p>
    181 
    182 <p> Warning: the file format produced by Berkeley DB version 1 is
    183 not compatible with that of versions 2 and 3 (versions 2 and 3 have
    184 the same format). If you switch between DB versions, then you may
    185 have to rebuild all your Postfix DB files. </p>
    186 
    187 <p> Warning: if you use Berkeley DB version 2 or later, do not
    188 enable DB 1.85 compatibility mode. Doing so would break fcntl file
    189 locking. </p>
    190 
    191 <p> Warning: if you use Perl to manipulate Postfix's Berkeley DB
    192 files, then you need to use the same Berkeley DB version in Perl
    193 as in Postfix.  </p>
    194 
    195 <h2><a name="tweak">Tweaking performance</a></h2>
    196 
    197 <p> Postfix provides two configuration parameters that control how
    198 much buffering memory Berkeley DB will use. </p>
    199 
    200 <ul>
    201 
    202 <li> <p> <a href="postconf.5.html#berkeley_db_create_buffer_size">berkeley_db_create_buffer_size</a> (default: 16 MBytes per
    203 table).  This setting is used by the commands that maintain Berkeley
    204 DB files: <a href="postalias.1.html">postalias(1)</a> and <a href="postmap.1.html">postmap(1)</a>.  For "hash" files, create
    205 performance degrades rapidly unless the memory pool is O(file size).
    206 For "btree" files, create performance is good with sorted input even
    207 for small memory pools, but with random input degrades rapidly
    208 unless the memory pool is O(file size). </p>
    209 
    210 <li> <p> <a href="postconf.5.html#berkeley_db_read_buffer_size">berkeley_db_read_buffer_size</a> (default: 128 kBytes per
    211 table).  This setting is used by all other Postfix programs. The
    212 buffer size is adequate for reading. If the cache is smaller than
    213 the table, random read performance is hardly cache size dependent,
    214 except with btree tables, where the cache size must be large enough
    215 to contain the entire path from the root node. Empirical evidence
    216 shows that 64 kBytes may be sufficient. We double the size to play
    217 safe, and to anticipate changes in implementation and bloat. </p>
    218 
    219 </ul>
    220 
    221 <h2><a name="pthread">Missing pthread library trouble</a></h2>
    222 
    223 <p> When building Postfix fails with: </p>
    224 
    225 <blockquote>
    226 <pre>
    227 undefined reference to `pthread_condattr_setpshared'
    228 undefined reference to `pthread_mutexattr_destroy'
    229 undefined reference to `pthread_mutexattr_init'
    230 undefined reference to `pthread_mutex_trylock'
    231 </pre>
    232 </blockquote>
    233 
    234 <p> Add the "-lpthread" library to the "make makefiles" command. </p>
    235 
    236 <blockquote>
    237 <pre>
    238 % make makefiles .... AUXLIBS="... -lpthread"
    239 </pre>
    240 </blockquote>
    241 
    242 <p> More information is available at
    243 <a href="https://www.oracle.com/database/technologies/related/berkeleydb.html">https://www.oracle.com/database/technologies/related/berkeleydb.html</a>. </p>
    244 
    245 </body>
    246 
    247 </html>
    248