MDL-58729 database: Improve performance of CLI tool.