If you have deployed an OceanBase cluster on your server and want to deploy a new OceanBase cluster on the same server, clear out the old cluster before you deploy the new one.
This topic describes how to clear out an old cluster in two scenarios. Choose the one that suits your needs.
Recommendation
Before you clear the old cluster environment, we recommend that you back up the data. This ensures the integrity and security of the data and provides a data copy that you can restore or migrate if needed in the future.
For more information about how to back up data from an OceanBase cluster, see Prepare for a backup.
Scenario 1: Deploy an OceanBase cluster using the CLI
If you manually deployed the cluster on your machine through the CLI, you can perform the cleanup operations described in this section.
Step 1: Stop and uninstall the service
Stop the old observer process and make sure it is no longer running. Then, uninstall the relevant database software. The steps are as follows:
Notice
After the observer process is stopped, OceanBase Database will become unavailable. Therefore, before you perform the following operations, make sure that the cluster is no longer in use and all necessary data has been backed up. Proceed with caution to avoid data loss or system unavailability.
Run the following command to check whether the observer process exists.
ps -ef|grep observer(Optional) Stop the observer process.
If your server has an observer process, use the following command to stop the old observer process:
kill -9 `pidof observer`Run the following command to view the name of the RPM package of OceanBase Database that has been installed.
rpm -qa|grep oceanbaseRun the following command to uninstall the OceanBase Database RPM package.
sudo rpm -e $rpm_nameIn this command,
$rpm_nameis the name of the package to be uninstalled.You can run the following command to check whether the RPM package has been uninstalled.
rpm -ql $rpm_nameRepeat steps 1 to 4 until the services on all OBServer nodes are stopped and uninstalled.
Step 2: Clean up database files
Delete the old database files, including data files, log files, and temporary files.
Notice
Once a file or directory is deleted, it cannot be restored. Therefore, make sure that the data in the target directory is no longer used before you perform the following operations.
Run the following command to delete the log disk file of the observer process.
sudo rm -rf /home/admin/oceanbase/*Run the following command to delete the log disk file of the observer process.
sudo rm -rf /data/log1/*Run the following command to delete the data disk file of the observer process.
sudo rm -rf /data/1/*Repeat steps 1 to 3 until all old database files in all OBServer nodes are deleted.
Scenario 2: OceanBase cluster deployed using OBD
If you deployed the cluster using OBD commands, you can perform the cleanup by following the steps in this topic.
View the status of the cluster.
obd cluster listThe output is as follows. For more information, see obd cluster list.
+--------------------------------------------------------+ | Cluster List | +------+-------------------------------+-----------------+ | Name | Configuration Path | Status (Cached) | +------+-------------------------------+-----------------+ | test | /home/admin/.obd/cluster/odp | running | | demo | /home/admin/.obd/cluster/demo | running | +------+-------------------------------+-----------------+Check whether a standby tenant exists.
This example uses the test cluster. You need to modify the cluster name to the actual one.
obd cluster tenant show test -gIf the output shows that there are no standby tenants and only the sys tenant in the cluster, you have deployed the primary/standby tenants in OBD. For more information about the output, see Deploy primary and standby tenants in OBD.
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | tenant base info | +-------------+-------------+--------------------+--------------+---------+---------+-------------+---------------------+---------------------+---------------+-------------+-------------+ | tenant_name | tenant_type | compatibility_mode | primary_zone | max_cpu | min_cpu | memory_size | max_iops | min_iops | log_disk_size | iops_weight | tenant_role | +-------------+-------------+--------------------+--------------+---------+---------+-------------+---------------------+---------------------+---------------+-------------+-------------+ | sys | SYS | MYSQL | RANDOM | 3.0 | 3.0 | 1024M | 9223372036854775807 | 9223372036854775807 | 2048M | 3 | PRIMARY | +-------------+-------------+--------------------+--------------+---------+---------+-------------+---------------------+---------------------+---------------+-------------+-------------+(Optional) Decouple the primary and standby tenants.
If the cluster contains standby tenants, an error will occur when you attempt to destroy the cluster. In this case, you can decouple the primary and standby tenants, or you can forcibly destroy the cluster. If you forcibly destroy the cluster, the standby tenants will become unavailable. Whether you perform this step depends on your business scenario.
For more information, see Decouple primary and standby tenants.
Destroy the cluster.
Notice
The
obd cluster destroycommand is irreversible. It will stop the observer process and clear the database files. Therefore, make sure that the cluster is no longer in use and all the data to be backed up has been backed up before you execute this command.This example uses the test cluster. You must modify the cluster name to the actual one in your situation.
obd cluster destroy test -f [--igs]The
-foption specifies to forcibly stop the running processes in the working directory and destroy the cluster.The
--igsoption specifies that when a tenant in the cluster has a standby tenant in another cluster, theobd cluster destroycommand is enforced.
References
If you are using OceanBase Cloud Platform (OCP) to manage the OceanBase cluster, you can delete the cluster directly in the OCP console. For more information, see Delete a cluster.
If you have deployed OceanBase Database in a Kubernetes environment, you can use ob-operator to manage the OceanBase cluster. For more information, see Delete a cluster.