[Nix-dev] Nix no longer needs Berkeley DB

Eelco Dolstra e.dolstra at tudelft.nl
Wed Jun 25 11:46:30 CEST 2008


Hi,

A few weeks ago, I merged the no-bdb branch with the trunk.  This branch changed 
the Nix store metadata storage from using Berkeley DB to using separate (plain 
text) files per store path.  This means that Berkeley DB is no longer needed 
(except for converting old Nix stores).  The new storage schema has a bunch of 
advantages:

- Berkeley DB environments don't work over NFS (because it uses mmap).  The new 
approach uses only plain locks, so if your NFS server/client support locking 
(via lockd), then you can share a Nix store via NFS.  These can even be 
different architectures (e.g. a i686-linux and powerpc-darwin machine could 
share a Nix store on an NFS server).

- Berkeley DB has the problem that if a process crashes, any other processes 
accessing the BDB environment will fail as well, and recovery is needed.  Nix 
runs recovery automatically, but it's still a pain.

- In the build farm we got frequent BDB deadlock errors.  Admittedly this is a 
problem in how Nix did transactions; you have to retry a transaction when a 
deadlock is detected, but we didn't do that.

- Berkeley DB environments aren't compatible between different architectures. 
So upgrading a NixOS installation from i686-linux to x86_64-linux was a problem.

- Users frequently had problems with Berkeley DB running out of locks or other 
resources (http://nixos.org/releases/nix/nix-0.11/manual/#id2521556).  The new 
approach has no such limits.

- The new approach no longer needs read/write access to the database in order to 
do read-only queries (like nix-env -qas \*).  So this to some extent obviates 
the need for the Nix daemon if you just want to allow unprivileged users to do 
queries (just like e.g. RPM allows any user to do rpm -qa).

Some notes on upgrading:

- The no-bdb Nix is now the default for NixOS.  If you do an svn up / 
nixos-rebuild switch, your database will be upgraded automatically at some 
point.  (Perhaps not by the switch, but when you next run a Nix command that 
accesses the store.)  Once the upgrade has succeeded, you can't go back!  [1] So 
you may wish to make a backup of /nix/var/nix/db ;-)

- After the upgrade, you can delete the old BDB files:

$ cd /nix/var/nix/db
$ rm __db* log.* derivers references referrers reserved validpaths DB_CONFIG

Note that the new metadata is stored in /nix/var/nix/db/info and 
/nix/var/nix/db/referrer.  BTW, just because the files in those directories are 
human-readable doesn't mean that they're human-editable.  Nix is pretty 
particular about the format.

- Nix by default still has a dependency on Berkeley DB in order to be able to 
upgrade.  If you don't need this, you can build Nix with the 
--disable-old-db-compat configure flag.

- The new storage schema may or may not require less disk space than the BDB 
environment.  It mostly depends on the cluster size of your file system.  With 1 
KB clusters (which seems to be the ext3 default nowadays) it usually takes up 
much less space.

[1] Actually, if you haven't deleted the old BDB files from /nix/var/nix/db, you 
can downgrade by doing "echo -n 4 > /nix/var/nix/db/schema".

-- 
Eelco Dolstra | http://www.st.ewi.tudelft.nl/~dolstra/



More information about the nix-dev mailing list