Updating the Stock LDAP Index Patterns

July 10, 2025

Similar to other databases, LDAP supports the creation of index tables to speed up queries. Any attribute can be used to define an index and can either be indexed by equality matching (uid=ameyer) or substring matching (uid=ameyer).

Stock Values

By default the following index tables are created:

olcDbIndex: objectClass eq
olcDbIndex: cn,uid eq
olcDbIndex: uidNumber,gidNumber eq
olcDbIndex: member,memberUid eq

or:

AttributeEqualitySubstringNotes
objectClassXdefines one or more object classes belonging to an object
cnXThe Common Name of an object (usually a user’s first name)
uidXThe User ID of an object (usually a user’s username)
uidNumberXA user’s POSIX style user ID (1000)
gidNumberXA group’s POSIX style group ID (1000)
memberXthe Distinguished Name of a member of a groupOfNames
memberUidXThe POSIX UserID of a member of a POSIX style group

Improved Values

Here are the index values that I use:

olcDbIndex: objectClass eq
olcDbIndex: cn,sn,uid,mail eq,sub
olcDbIndex: uidNumber,gidNumber eq
olcDbIndex: member,memberUid,memberOf eq

or:

AttributeEqualitySubstringNotes
objectClassXdefines one or more object classes belonging to an object
cnXXThe Common Name of an object (usually a user’s first name or full name)
snXXThe Surname of an object (usually a user’s last name)
uidXXThe User ID of an object (usually a user’s username)
mailXXThe email address of a user (ameyer@zerosla.com)
uidNumberXA user’s POSIX style user ID (1000)
gidNumberXA group’s POSIX style group ID (1000)
memberXthe Distinguisted Name of a member of a groupOfNames
memberUidXThe POSIX UserID of a member of a POSIX style group
memberOfXA dynamic attribute introduced by the memberOf overlay[1]

[1] memberOf entries are the Distinguished Name of a groupOfNames a user belongs to. This is useful for two reasons:

  1. If the user object is deleted, all corresponding member attributes are removed from all groupOfNames listed
  2. Provides a way to determine group membership by querying the user object instead of querying all groupOfNames objects
  • By adding an index for mail we can significantly speed up queries for a user’s email address: great for postfix systems.
  • Cn, sn, uid, and mail also create substring index tables: these are (usually) short values that are commonly substring searched when performing user searches.
  • Some systems prefer to use memberOf instead of member to determine group membership, by indexing we can speed these queries up as well

Deployment

Your environment may vary, but I will assume that you are using a single MDB database for your LDAP directory as this is the stock configuration.

change-indices.ldif

dn: olcDatabase={1}mdb,cn=config
changetype: modify
replace: olcDbIndex
olcDbIndex: objectClass eq
olcDbIndex: cn,sn,uid,mail eq,sub
olcDbIndex: uidNumber,gidNumber eq
olcDbIndex: member,memberUid,memberOf eq

ldapmodify -Y EXTERNAL -H ldapi:/// -v -f ./change-indices.ldif

When executed, this ldif will replace ALL olcDbIndex attributes with the list provided. Be sure to edit the ldif if you have already customized your index tables.