Linux HOWTOs

About | Home | Search


HOWTO: db4
Description: Database library and utilities
Click here for ChangeLog
NOTE: I use GNU tar >= 1.13.25 so it's -j for .tar.bz2 files,
it's safe to assume that make, gcc, binutils, fileutils/coreutils, gawk, sed, and grep are prerequisites for almost everything


# Oracle Berkeley DB 4.x
# ======================
# Slackware 13.0, 13.1, 13.37: db42 4.2.52, db44 4.4.20
# Slackware 14.0: db42 4.2.52, db44 4.4.20, db48 4.8.30

# I have several versions of bdb 4 in this howto.  You should use the
# latest stable release unless you have applications that were created
# before it was released, (sometimes) requiring an older version.  You
# can install all of them (as done below) without trouble, but I'd stick
# with only what's necessary.

# If you install these with their default prefix of
# /usr/local/BerkeleyDB.4.x, you don't have to worry about it conflicting
# with an existing db4 installation.  If you'd rather replace the Slackware
# installed db4 (or just install it the same way), add --prefix=/usr to the
# configure line below.  If you do that, you should run 'removepkg db4 db42
# db44' before you run 'make install' to make sure there aren't any old
# files left over.


# Berkeley db4 4.4.20
# ===================
cd
test -f installed/db-4.4.20.tar.gz && mv installed/db-4.4.20.tar.gz .
test ! -f db-4.4.20.tar.gz &&
 wget http://download.oracle.com/berkeley-db/db-4.4.20.tar.gz

# Verify tarball w/ md5sum:
echo "d84dff288a19186b136b0daf7067ade3  db-4.4.20.tar.gz" | md5sum -c

mkdir -p -m 0700 src
cd src
find -maxdepth 1 -type d -name "db-4.4.*" -exec rm -r {} \;
tar xzvf ~/db-4.4.20.tar.gz
cd db-4.4.20
test $UID = 0 && chown -R root:root .
chmod -R u+w .

# Apply 4 bugfix patches:
for pnum in `seq 4`; do
  wget -nc http://www.sleepycat.com/update/4.4.20/patch.4.4.20.$pnum &&
   patch -p0 < patch.4.4.20.$pnum
  echo "Hit enter to continue"
  read
done

cd build_unix
../dist/configure \
 --enable-compat185 \
 --enable-rpc \
 --enable-shared
make

# Become root to install it
su

# Install it
make install

# Make sure your non-root user can remove the source later
chown -R $USER .
chmod -R u+w .

# Become yourself again
exit

cd
mkdir -p -m 0700 installed
rm -f installed/db-4.4.*.tar.*
mv db-4.4.20.tar.gz installed/

# Skip down to the bottom for some other configuration


# Berkeley db4 4.5.20
# ===================
cd
test -f installed/db-4.5.20.tar.gz && mv installed/db-4.5.20.tar.gz .
test ! -f db-4.5.20.tar.gz &&
 wget http://download.oracle.com/berkeley-db/db-4.5.20.tar.gz

# Verify tarball w/ md5sum:
# (I couldn't find one elsewhere, so this one is from me, not from Oracle)
echo "b0f1c777708cb8e9d37fb47e7ed3312d  db-4.5.20.tar.gz" | md5sum -c

mkdir -p -m 0700 src
cd src
find -maxdepth 1 -type d -name "db-4.5.*" -exec rm -r {} \;
tar xzvf ~/db-4.5.20.tar.gz
cd db-4.5.20
test $UID = 0 && chown -R root:root .
chmod -R u+w .

# Apply 2 bugfix patches:
for pnum in `seq 2`; do
  wget -nc http://www.oracle.com/technology/products/berkeley-db/db/update/\
4.5.20/patch.4.5.20.$pnum &&
   patch -p0 < patch.4.5.20.$pnum
  echo "Hit enter to continue"
  read
done

cd build_unix
../dist/configure \
 --enable-compat185 \
 --enable-rpc \
 --enable-shared
make

# Become root to install it
su

# Install it
make install

# Make sure your non-root user can remove the source later
chown -R $USER .
chmod -R u+w .

# Become yourself again
exit

cd
mkdir -p -m 0700 installed
rm -f installed/db-4.5.*.tar.*
mv db-4.5.20.tar.gz installed/

# Skip down to the bottom for some other configuration


# Berkeley db4 4.7.25
# ===================
cd
test -f installed/db-4.7.25.tar.gz && mv installed/db-4.7.25.tar.gz .
test ! -f db-4.7.25.tar.gz &&
 wget http://download.oracle.com/berkeley-db/db-4.7.25.tar.gz

# Verify tarball w/ md5sum:
# (I couldn't find one elsewhere, so this one is from me, not from Oracle)
echo "ec2b87e833779681a0c3a814aa71359e  db-4.7.25.tar.gz" | md5sum -c

mkdir -p -m 0700 src
cd src
find -maxdepth 1 -type d -name "db-4.7.*" -exec rm -r {} \;
tar xzvf ~/db-4.7.25.tar.gz
cd db-4.7.25
test $UID = 0 && chown -R root:root .

# Apply 3 bugfix patches:
for pnum in `seq 3`; do
  wget -nc http://www.oracle.com/technology/products/berkeley-db/db/update/\
4.7.25/patch.4.7.25.$pnum &&
   patch -p0 < patch.4.7.25.$pnum
  echo "Hit enter to continue"
  read
done

cd build_unix
../dist/configure \
 --enable-compat185 \
 --enable-rpc \
 --enable-shared
make

# Become root to install it
su

# Install it
make install

# Make sure your non-root user can remove the source later
chown -R $USER .
chmod -R u+w .

# Become yourself again
exit

cd
mkdir -p -m 0700 installed
rm -f installed/db-4.7.*.tar.*
mv db-4.7.25.tar.gz installed/

# Skip down to the bottom for some other configuration


# "Some other configuration"
# ==========================
# Become root
su

# Be ready for things to potentially go crazy when you start doing this.
#
# You can run 'lsof /usr/lib/libdb.so' to get an idea of what running
# apps are using the current version that is installed in the
# system-wide location of /usr/lib/libdb.so (if there is one) or
# /usr/local/lib/libdb.so and other directories that you may have
# set in /etc/ld.so.conf
#
# If things are linked with the full path of the older-version Berkeley
# DB library, like /usr/local/BerkeleyDB.4.2/lib/libdb.so, then you
# should be OK.  Go through the procedure below, then rebuilding that
# app and it should start using the new version you installed.
#
# ...but if things are linked to /usr/lib/libdb.so and you change that,
# then you may have trouble.
#
# If you use something like Cyrus IMAP, you'll probably want to shut it
# down, install the new BDB, rebuild and reinstall Cyrus, run the
# 'db_upgrade' utility in /var/imap, then start Cyrus again.
# You may have to do some things with OpenLDAP's daemons (slapd/slurpd),
# sendmail, etc...  Sendmail will probably be fine with 'newaliases',
# running 'make' in /etc/mail, or whatever you usually do to create
# the .db files in there - if you have it using Berkeley DB.

# If you installed it with the default prefix, it's installed as
# /usr/local/BerkeleyDB.X.X  If you build something that uses bdb, it
# probably won't find it there.  Some things will have a configure flag
# like --with-db-includes and --with-db-libs so you can tell it where to
# find them.  If something like that is not available, pass it
# CPPFLAGS="-I/usr/local/BerkeleyDB.X.X/include"
# to find the includes and
# LDFLAGS="-L/usr/local/BerkeleyDB.X.X/lib"
# to find the libraries.

# You can also make your newly installed BDB available system-wide without
# having to specify it's location.  To do this, you'll have to either zap or
# at least, move conflicting files.  Just keep in mind that if an appliaction
# is linked to libdb-3.3.so and you remove it, that application will break.

# To remove old versions of db4, run this.  You may be able to skip this and
# just run the 'Get the new version(s) noticed' part below, but certain apps
# like Cyrus IMAP and SASL still have (had?) trouble without doing this.
test -x /sbin/removepkg && /sbin/removepkg db4 db42 db44
mkdir -p -m 0700 ~/backup/bdb/db4
test -d /usr/include/db4 && mv -f /usr/include/db4 ~/backup/bdb/db4/
find /lib /usr/lib -name "libdb-4.*.so" -exec mv -f {} ~/backup/bdb/db4/ \;
find /usr/lib -name "libdb4.*" -exec mv -f {} ~/backup/bdb/db4/ \;
find /usr/bin -type f -name "db4_*" -exec mv -f {} ~/backup/bdb/db4/ \;
test -f /usr/bin/berkeley_db4_svc &&
 mv -f /usr/bin/berkeley_db4_svc ~/backup/bdb/db4/

# To remove db3 files also:
test -x /sbin/removepkg && /sbin/removepkg db31 db3
mkdir -p -m 0700 ~/backup/bdb/db3
test -d /usr/include/db3 && mv -f /usr/include/db3 ~/backup/bdb/db3/
test -d /usr/include/db31 && mv -f /usr/include/db31 ~/backup/bdb/db3/
find /lib /usr/lib -name "libdb-3.*" -exec mv -f {} ~/backup/bdb/db3/ \;

# To remove files that could be from either of them:
test ! -d ~/backup/bdb && mkdir -p -m 0700 ~/backup/bdb
find /usr/bin -type f -name "db_*" -exec mv -f {} ~/backup/bdb/ \;
for file in /usr/lib/libdb.a /usr/lib/libdb.so /usr/include/db.h
do
  test -L $file && rm $file
  test -f $file && mv $file ~/backup/bdb/
done

# Get the new version(s) noticed.  Not that you should, but if you did
# install all of them, the "default" one would be the highest version that
# you installed.
#
# This will create a /usr/include/db.h symlink, a /usr/lib/libdb.a symlink,
# a /usr/lib/libdb.so symlink, a /etc/profile.d/db4.sh to add the bin
# directory to your PATH when you login, and will update /etc/ld.so.conf

rm -f /etc/profile.d/db4.sh /usr/include/db.h /usr/lib/libdb.a \
 /usr/lib/libdb.so
for dbver in 4.7 4.6 4.5 4.4 4.3 4.2 4.1 4.0
do
  test -d /usr/local/BerkeleyDB.$dbver &&
   ( test ! -L /usr/include/db.h &&
      ln -sf /usr/local/BerkeleyDB.$dbver/include/db.h /usr/include/db.h
     test ! -L /usr/lib/libdb.a &&
      ln -sf /usr/local/BerkeleyDB.$dbver/lib/libdb.a /usr/lib/libdb.a
     test ! -L /usr/lib/libdb.so &&
      ln -sf /usr/local/BerkeleyDB.$dbver/lib/libdb.so /usr/lib/libdb.so
     test ! -f /etc/profile.d/db4.sh &&
      ( echo '#!/bin/sh' > /etc/profile.d/db4.sh
        echo "export PATH=\"/usr/local/BerkeleyDB.$dbver/bin:\$PATH\"" >> \
         /etc/profile.d/db4.sh
        chmod 755 /etc/profile.d/db4.sh )
     egrep "^/usr/local/BerkeleyDB.$dbver/lib$" /etc/ld.so.conf > /dev/null \
      2>&1 ||
      echo "/usr/local/BerkeleyDB.$dbver/lib" >> /etc/ld.so.conf &&
       ldconfig )
done

# Become yourself again
exit

# Update your current shell's PATH with db's bin directory:
test -x /etc/profile.d/db4.sh &&
 echo $PATH | grep -q /usr/local/BerkeleyDB ||
  . /etc/profile.d/db4.sh

Back to the list


Last updated: Tue, 07 Aug 2018 12:06:17 -0400
Jason Englander <jason at englanders dot us>