How to fix Subversion errors after upgrading your Berkeley DB library

After a routine "apt-get upgrade" of Debian testing, I found myself unable to use my Subversion repository. I got an error message when trying to commit a file:

svn: Berkeley DB error while opening environment for filesystem db:
DB_VERSION_MISMATCH: Database environment version mismatch
svn: bdb: Program version 4.3 doesn't match environment version

A note from the Subversion FAQ had this to say:

After upgrading to Berkeley DB 4.3, I'm seeing repository errors.

Normally one can simply run svnadmin recover to upgrade a Berkeley DB repository in-place. However, due to a bug in the way this command invokes the db_recover() API, this won't work correctly when upgrading from BDB 4.0/4.1/4.2 to BDB 4.3.

Use this procedure to upgrade your repository in-place to BDB 4.3:

  • Make sure no process is accessing the repository (stop Apache, svnserve, restrict access via file://, svnlook, svnadmin, etc.)
  • Using an older svnadmin binary (that is, linked to an older BerkeleyDB):
    1. Recover the repository: 'svnadmin recover /path/to/repository'
    2. Make a backup of the repository.
    3. Delete all unused log files. You can see them by running 'svnadmin list-unused-dblogs /path/to/repeository'
    4. Delete the shared-memory files. These are files in the repository's db/ directory, of the form __db.00*

The repository is now usable by Berkeley DB 4.3.

As the instructions note, you need a copy of subversion linked with a pre-4.3 version of the Berkeley database library. Subversion uses Berkeley via the APR Library. So we need to install appropriate verions of Berkeley, APR and Subversion.

My notes are below. Note that I installed the APR and Subversion software into a local directory (/home/mk/proj/svn_db/local in my case). Also, my Subversion repository is in /data/svnroot.

# export LD_CONFIG_PATH=/home/mk/proj/svn_db/local

# wget 'http://downloads.sleepycat.com/db-4.2.52.tar.gz'
# tar -xvzf db-4.2.52.tar.gz
# cd db-4.2.52
# cd build_unix
# ../dist/configure
# make
# make install

# wget 'http://archive.apache.org/dist/apr/apr-0.9.5.tar.gz'
# tar -xvzf apr-0.9.5.tar.gz
# cd apr-0.9.5
# ./configure --prefix=/home/mk/proj/svn_db/local
# make
# make install

# wget 'http://archive.apache.org/dist/apr/apr-util-0.9.5.tar.gz'
# tar -xvzf apr-util-0.9.5.tar.gz
# cd apr-util-0.9.5
# ./configure --prefix=/home/mk/proj/svn_db/local --with-apr=/home/mk/proj/svn_db/local --with-berkeley-db=/usr/local/BerkeleyDB.4.2/

# make
# make install

# wget 'http://subversion.tigris.org/downloads/subversion-1.2.3.tar.bz2'
# tar -xvjf subversion-1.2.3.tar.bz2
# cd subversion-1.2.3
# ./configure --prefix=/home/mk/proj/svn_db/local --with-apr=/home/mk/proj/svn_db/local --with-berkeley-db=/usr/local/BerkeleyDB.4.2/
# make
# make install

# su
# /home/mk/proj/svn_db/local/bin/svnadmin recover /data/svnroot
# tar -cvf ~/svnroot_backup.tar /data/svnroot

Then I executed steps 3 and 4 from the FAQ. At this point, I was able to commit files to my repository again.

Link to story

Technorati tags for this post:

Comments on "How to fix Subversion errors after upgrading your Berkeley DB library":

Comment by zauron.subs[arroba]gmail.com

Posted at Feb 20th 2006.

Thanks, this story helps me a lot, I've the same problem but to compile I need a couple of exports and --with-apr-util parameter to compile subversion:

# export LD_CONFIG_PATH=/home/mk/proj/svn_db/local

# wget 'http://downloads.sleepycat.com/db-4.2.52.tar.gz'
# tar -xvzf db-4.2.52.tar.gz
# cd db-4.2.52
# cd build_unix
# ../dist/configure
# make
# make install

# wget 'http://archive.apache.org/dist/apr/apr-0.9.5.tar.gz'
# tar -xvzf apr-0.9.5.tar.gz
# cd apr-0.9.5
# ./configure --prefix=/home/mk/proj/svn_db/local
# make
# make install

# export LDFLAGS="-L/usr/local/BerkeleyDB.4.2/lib"
# export LD_LIBRARY_PATH=/usr/local/BerkeleyDB.4.2/lib

# wget 'http://archive.apache.org/dist/apr/apr-util-0.9.5.tar.gz'
# tar -xvzf apr-util-0.9.5.tar.gz
# cd apr-util-0.9.5
# ./configure --prefix=/home/mk/proj/svn_db/local --with-apr=/home/mk/proj/svn_db/local --with-berkeley-db=/usr/local/BerkeleyDB.4.2/
#
# make
# make install

# wget 'http://subversion.tigris.org/downloads/subversion-1.2.3.tar.bz2'
# tar -xvjf subversion-1.2.3.tar.bz2
# cd subversion-1.2.3
# ./configure --prefix=/home/mk/proj/svn_db/local --with-apr=/home/mk/proj/svn_db/local --with-apr-util=/home/mk/proj/svn_db/local --with-berkeley-db=/usr/local/BerkeleyDB.4.2/
# make
# make install

Comment by matt

Posted at Feb 24th 2006.
Ahah! I knew somebody could use this info.

Comment by <Anonymous>

Posted at Mar 3rd 2006.

Make that 2 people at least. I needed the

--with-apr-util

as well

Thanks!

Comment by <Anonymous>

Posted at Jun 5th 2006.
me three

Comment by Jon@jonsthoughtsoneverything.com

Posted at Aug 4th 2006. Jon@jonsthoughtsoneverything.com's URL
i'm so close to being 4, but for some reason, my apr-util configure script can't find my BerkeleyDB.4.2 install. I'm using:

./configure --with-apr=/usr/local/apr --with-berkeley-db=/usr/local/BerkeleyDB.4.2/

but it just can't find it.. configure: error: Berkeley DB not found.. whats going on here?

Comment by Bob

Posted at Nov 22nd 2006.

Brilliant, thanks Matt for saving me a lot of time (the SVN FAQ advice was
rather too brief).

I managed to do the whole thing in one directory (in my case
/usr/local/svn_rescue) without any need to set LD_*_PATH variables:
[I hope what I paste in below formats OK!]

wget 'http://downloads.sleepycat.com/db-4.2.52.tar.gz'
tar -xvzf db-4.2.52.tar.gz
cd db-4.2.52
cd build_unix
../dist/configure --prefix=/usr/local/svn_rescue
make
make install

wget 'http://archive.apache.org/dist/apr/apr-0.9.5.tar.gz'
tar -xvzf apr-0.9.5.tar.gz
cd apr-0.9.5
./configure --prefix=/usr/local/svn_rescue
make
make install

wget 'http://archive.apache.org/dist/apr/apr-util-0.9.5.tar.gz'
tar -xvzf apr-util-0.9.5.tar.gz
cd apr-util-0.9.5
./configure --prefix=/usr/local/svn_rescue --with-apr=/usr/local/svn_rescue --with-berkeley-db=/usr/local/svn_rescue
make
make install

wget 'http://subversion.tigris.org/downloads/subversion-1.2.3.tar.bz2'
tar -xvjf subversion-1.2.3.tar.bz2
cd subversion-1.2.3
./configure --prefix=/usr/local/svn_rescue --with-apr=/usr/local/svn_rescue --with-apr-util=/usr/local/svn_rescue
+--with-berkeley-db=/usr/local/svn_rescue
make
make install

# then continue with instructions in SVN FAQ

/usr/local/svn_rescue/bin/svnadmin recover /path/to/repository

Comment by Adam

Posted at Jan 2nd 2008.

I made a use for this too. I tried over and over again with various builds of BDB, apr, and apr-util. It turned out that I needed to do the following after the BDB build:

cp /usr/local/BerkeleyDB.4.5/libdb-4.5.so /usr/lib

Everything else worked after that.

Comment by Adam

Posted at Feb 2nd 2008.
On Debian, the following worked

apt-get install libdb4.4-dev
./configure --with-berkeley-db=/usr/include:/usr/lib
Allowed html tags: br p blockquote i b em code strong u ol ul li a
(type "human" here)