LDAP server fails to start because of a corrupted database on FreeBSD


January 2013.

Situation


Your LDAP server on your FreeBSD box can't start. Nothing shows up in the logs to help you.

# /usr/local/etc/rc.d/slapd start
/usr/local/etc/rc.d/slapd: WARNING: failed to start slapd

Finding the problem


Start the server manually with verbose information and read the output.

# /usr/local/libexec/slapd -h "ldap://10.0.0.XX/ ldap://[your:ipv6:here::]/" -u ldap -g ldap -d -1
[...]
5105220b bdb_db_open: database "dc=test,dc=example,dc=com" cannot be opened, err 22. Restore from backup!
5105220b backend_startup_one (type=bdb, suffix="dc=test,dc=example,dc=com"): bi_db_open failed! (22)
[...]

You now determined that your database is corrupted.

Repairing your database



# ls /usr/local/bin/db_recover*
/usr/local/bin/db_recover-4.6

# /usr/local/bin/db_recover-4.6 -v -h /var/db/openldap-data/
Finding last valid log LSN: file: 1 offset 338791
Recovery starting from [1][338646]
Recovery complete at Sun Jan 27 14:41:12 2013
Maximum transaction ID 80000009 Recovery checkpoint [1][338791]

If all went well, you should be able to start slapd again. Don't forget to backup your database.