Symas employee?Sign in

← Knowledge Base

Reference

Using slapindex

Date: 11-04-2022

slapindex regenerates index files for back-mdb databases. You run it after:

  • adding or changing any index lines in slapd.conf or olcDbIndex values in cn=config, or
  • after serious DB corruption or data restore (e.g., from LDIF)

WARNING: Don’t run slapindex while slapd is online — LMDB will complain or corrupt data!

 

Prerequisites

You need exclusive access to the database files.

Stop slapd first unless you’re indexing a replica copy that’s offline:

 
systemctl stop slapd
# or
service slapd stop

Confirm your DB path (e.g. /var/lib/ldap or /opt/symas/var/openldap-data). That’s where the data.mdb and lock.mdb live.

Example (slapd.conf setup)

If you changed lines like this:

index cn eq,sub
index mail eq
index uid eq

Run:

slapindex -f /opt/symas/etc/openldap/slapd.conf -b "dc=example,dc=com"

Options:

Flag Meaning
-f Path to your slapd.conf
-b Base DN for the DB you want to reindex (only needed if multiple DBs)
-v Verbose (recommended)

If you omit -b, it indexes every DB defined in the config.

Example (cn=config setup)

If you’re using dynamic config (/opt/symas/etc/openldap/slapd.d), and you want to add indexes, use ldapmodify using an ldif file with the indexes you wish to add.

Here's a link to the ldapmodify knowledge base article: Using ldapmodify.

Here is an example of a .ldif file with new index attributes to add:

   dn: olcDatabase={1}mdb,cn=config
   changetype: modify
   add: olcDbIndex
   olcDbIndex: attrA eq
   -
   add: olcDbIndex
   olcDbIndex: attrB eq

Find the database directory.  Default for Symas OpenLDAP is: /opt/symas/var/openldap-data/

Run:

slapindex -F /opt/symas/etc/openldap/slapd.d -b "dc=example,dc=com" -v

The -v will run in Verbose mode, but this is not required.

Caution

-q (quick mode) skips value validation; omit it if you’re verifying attribute syntax changes

If you changed index definitions drastically, a slapcat → wipe DB → slapadd cycle is safest

For more information, please see slapindex Man Page.