2022-10-26 00:18:25 +02:00
|
|
|
# Database Maintenance
|
|
|
|
|
|
|
|
## Reindexing
|
|
|
|
|
2022-12-26 23:52:03 +01:00
|
|
|
In some (rare) cases you may need to reindex. Please note the server will sometimes reindex on
|
|
|
|
startup as a result of the project changing its internal schema definitions. This is normal and
|
|
|
|
expected - you may never need to start a reindex yourself as a result!
|
2022-10-26 00:18:25 +02:00
|
|
|
|
2022-12-26 23:52:03 +01:00
|
|
|
You'll likely notice a need to reindex if you add indexes to schema and you see a message in your
|
|
|
|
logs such as:
|
2022-10-26 00:18:25 +02:00
|
|
|
|
2022-12-26 23:52:03 +01:00
|
|
|
```
|
|
|
|
Index EQUALITY name not found
|
|
|
|
Index {type} {attribute} not found
|
|
|
|
```
|
2022-10-26 00:18:25 +02:00
|
|
|
|
2022-12-26 23:52:03 +01:00
|
|
|
This indicates that an index of type equality has been added for name, but the indexing process has
|
|
|
|
not been run. The server will continue to operate and the query execution code will correctly
|
|
|
|
process the query - however it will not be the optimal method of delivering the results as we need
|
|
|
|
to disregard this part of the query and act as though it's un-indexed.
|
2022-10-26 00:18:25 +02:00
|
|
|
|
|
|
|
Reindexing will resolve this by forcing all indexes to be recreated based on their schema
|
|
|
|
definitions (this works even though the schema is in the same database!)
|
|
|
|
|
2022-12-26 23:52:03 +01:00
|
|
|
```bash
|
|
|
|
docker stop <container name>
|
|
|
|
docker run --rm -i -t -v kanidmd:/data \
|
|
|
|
kanidm/server:latest /sbin/kanidmd reindex -c /data/server.toml
|
|
|
|
docker start <container name>
|
|
|
|
```
|
2022-10-26 00:18:25 +02:00
|
|
|
|
|
|
|
Generally, reindexing is a rare action and should not normally be required.
|
|
|
|
|
|
|
|
## Vacuum
|
|
|
|
|
2022-12-26 23:52:03 +01:00
|
|
|
[Vacuuming](https://www.sqlite.org/lang_vacuum.html) is the process of reclaiming un-used pages from
|
|
|
|
the sqlite freelists, as well as performing some data reordering tasks that may make some queries
|
|
|
|
more efficient . It is recommended that you vacuum after a reindex is performed or when you wish to
|
|
|
|
reclaim space in the database file.
|
2022-10-26 00:18:25 +02:00
|
|
|
|
2022-12-26 23:52:03 +01:00
|
|
|
Vacuum is also able to change the pagesize of the database. After changing `db_fs_type` (which
|
|
|
|
affects pagesize) in server.toml, you must run a vacuum for this to take effect:
|
2022-10-26 00:18:25 +02:00
|
|
|
|
2022-12-26 23:52:03 +01:00
|
|
|
```bash
|
|
|
|
docker stop <container name>
|
|
|
|
docker run --rm -i -t -v kanidmd:/data \
|
|
|
|
kanidm/server:latest /sbin/kanidmd vacuum -c /data/server.toml
|
|
|
|
docker start <container name>
|
|
|
|
```
|
2022-10-26 00:18:25 +02:00
|
|
|
|
|
|
|
## Verification
|
|
|
|
|
2022-12-26 23:52:03 +01:00
|
|
|
The server ships with a number of verification utilities to ensure that data is consistent such as
|
|
|
|
referential integrity or memberof.
|
2022-10-26 00:18:25 +02:00
|
|
|
|
|
|
|
Note that verification really is a last resort - the server does _a lot_ to prevent and self-heal
|
|
|
|
from errors at run time, so you should rarely if ever require this utility. This utility was
|
|
|
|
developed to guarantee consistency during development!
|
|
|
|
|
|
|
|
You can run a verification with:
|
|
|
|
|
2022-12-26 23:52:03 +01:00
|
|
|
```bash
|
|
|
|
docker stop <container name>
|
|
|
|
docker run --rm -i -t -v kanidmd:/data \
|
|
|
|
kanidm/server:latest /sbin/kanidmd verify -c /data/server.toml
|
|
|
|
docker start <container name>
|
|
|
|
```
|
2022-10-26 00:18:25 +02:00
|
|
|
|
|
|
|
If you have errors, please contact the project to help support you to resolve these.
|