> For the complete documentation index, see [llms.txt](https://docs.cennso.com/cennso/cennso-db/latest/llms.txt) (all documentation: [llms.txt](https://docs.cennso.com/llms.txt)). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.cennso.com/cennso/cennso-db/latest/operation-guides/cennso-db-change-roles.md).

# Change database roles

Sometimes it might be necessary to change the roles of the existing database instances, for example, to perform maintenance on the database node. In this case, you need to assign the primary role to another database instance.

To do this, run the following command in the orchestrator's container:

```bash
orchestrator-client -c graceful-master-takeover-auto -alias {MYSQL-POD-NAME}.{MYSQL-CR-NAME}.{NAMESPACE}
```

Replace each placeholder with an appropriate value:

- `MYSQL-POD-NAME` - MySQL server pod name.
- `MYSQL-CR-NAME` - the Custom Resource name of the MySQL cluster. You can find it using the `kubectl get perconaservermysqls -n {NAMESPACE}` command.
- `NAMESPACE` - the Kubernetes namespace where the MySQL instance is running

The command sets the MySQL server running in the `MYSQL-POD-NAME` as the primary.

> [!IMPORTANT]
> After the roles switch, HAProxy continues to hold the old connections. Only the new connections are established to the new primary. The affected application is responsible for reacting to the MySQL [1290](https://dev.mysql.com/doc/mysql-errors/8.0/en/server-error-reference.html) error code and reconnecting.
