Performing routine maintenance

Loading schemas and/or data is not the only task you would perform with Ansible on a database. Sometimes, manual intervention is required in a database. For example, PostgreSQL requires VACUUM operations from time to time, to free up unused space in the database. MariaDB has a maintenance tool called mysqlcheck that can be used to verify the integrity of tables and perform optimization. Each platform will have its own specific tools for maintenance operations, and it is up to you to establish the best practices for database maintenance on your chosen platform. Furthermore, sometimes it is necessary to make simple changes to a database. For example, it might be necessary to delete (or update) a row from a table, to clear an error situation that has occurred in an application.

Of course, all these activities could be performed manually—however, this (as always) brings about the risk of losing track of what happened, who ran a task, and how they ran it (for example, which options were provided). If we move this example into the world of Ansible and AWX, suddenly we have a complete audit trail of activities, and we know exactly what was run and how it was run. Furthermore, if special options are required for a task, these will be stored within the playbooks, and thus the self-documentation that Ansible provides is available here too.

As our examples thus far have been very MariaDB-centric, let's take a look at how you might run a full vacuum on a table in PostgreSQL, with Ansible.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset