# DBmaint Module

_This page explains what the DBmaint module is and when to use it._

The DBmaint module is a specialized utility suite within the KDB-X ecosystem designed for the structural maintenance and evolution of partitioned kdb+ databases. It streamlines complex administrative tasks such as schema changes, column transformations, and attribute management by automating the application of these changes across all database partitions at once. By providing a standardized interface for modifying persisted data, it reduces manual intervention and reduces the risk of inconsistencies that can arise from direct filesystem operations.

## Key features

- **Schema Evolution**: Easily add (`addCol`), delete (`delCol`), rename (`renameCol`), or reorder (`reorderCols`) columns across all partitions.
- **Data Transformation**: Apply unary functions to entire columns (`fnCol`) or cast columns to different types (`castCol`) globally.
- **Table Management**: Support for adding new tables (`addTab`), renaming existing ones (`renameTab`), or removing them entirely (`delTab`).
- **Attribute Control**: Simplified commands to apply or remove kdb+ performance attributes like parted (`p`), sorted (`s`), unique (`u`), or grouped (`g`) using `setAttr` and `rmAttr`.

## Typical use cases

- **Database Refactoring**: Renaming legacy columns or change type of a column to meet new business requirements.
- **Performance Tuning**: Assigning the "parted" attribute to the `sym` column across years of historical data to optimize on-disk lookups.
- **Data Correction**: Using `fnCol` to fix data entry errors across specific date ranges or the entire history.
- **Schema Synchronization**: Using `addMissingCols` to ensure that older partitions contain the same columns as the most recent data capture, preventing "missing column" errors during cross-partition queries.

For a full list of available functions and examples, refer to the [DBmaint documentation on GitHub](https://github.com/KxSystems/dbmaint/tree/main/docs){target=_blank}.
