9.3. Applying New Indexes to Existing Databases

New indexes are not added to existing databases automatically. They must be added manually, and Directory Server has two methods for applying new indexes to an existing database: running the db2index.pl script or running a cn=index,cn=tasks task.

9.3.1. Running the db2index.pl Script

After creating an indexing entry or adding additional index types to an existing indexing entry, run the db2index.pl script to generate the new set of indexes to be maintained by the Directory Server. After the script is run, the new set of indexes is active for any new data added to the directory and any existing data in the directory.
Run the db2index.pl Perl script.
[root@server ~]# /usr/lib[64]/dirsrv/slapd-example/db2index.pl -D "cn=Directory Manager" -w secret -n ExampleServer -t sn
For more information about using this Perl script, see the Directory Server Configuration and Command-Line Tool Reference.
Table 9.3, “db2index.pl Options” describes the db2index.pl options.

Table 9.3. db2index.pl Options

Option Description
-D Specifies the DN of the administrative user.
-w Specifies the password of the administrative user.
-n Specifies the name of the database being indexed.
-t Specifies the name of the attribute contained by the index.

9.3.2. Using a cn=tasks Entry to Create an Index

The cn=tasks,cn=config entry in the Directory Server configuration is a container entry for temporary entries that the server uses to manage tasks. Several common directory tasks have container entries under cn=tasks,cn=config. Temporary task entries can be created under cn=index,cn=tasks,cn=config to initiate an indexing operation.
This task entry requires a unique name (cn) and a definition for the attribute and type of index, set in nsIndexAttribute in the format attribute:index_type.
For example:
ldapmodify -a -D "cn=directory manager" -W -p 389 -h server.example.com -x

dn: cn=example presence index,cn=index,cn=tasks,cn=config
changetype: add
objectclass: top
objectclass: extensibleObject
cn: example presence index
nsInstance: userRoot
nsIndexAttribute: "cn:pres"
There are three possible index_types:
  • pres for presence indexes
  • eq for equality indexes
  • sub for substring indexes
As soon as the task is completed, the entry is removed from the directory configuration.
The Directory Server Configuration and Command-Line Tool Reference has more information on running Directory Server tasks under the cn=tasks entries.