Before you create standby tenants, you must select the source and creation method, specify the number of standby tenants to be created, and configure resources for the standby tenants.
Select the source for standby tenants
A standby tenant synchronizes logs from the primary tenant or another standby tenant. A deployment architecture where a standby tenant synchronizes logs from another standby tenant is called a cascaded standby database or a cascaded standby tenant.
You can select the source for the standby tenants based on your business needs.
Select the number of standby tenants to be created
OceanBase Database does not limit the number of standby tenants that synchronize logs from a primary or standby tenant.
However, if the Physical Standby Database solution is based on log archiving, log synchronization depends on the storage medium. In this case, you must determine the number of standby tenants to be created based on your business needs.
If your Physical Standby Database solution is based on network, a standby tenant must read logs from the source tenant during synchronization. This consumes not only the CPU, memory, and I/O resources of the source tenant, but also the network bandwidth between the standby tenant and the source tenant. In this case, you must determine the number of standby tenants to be created based on the resource usage of the source tenant and your business needs.
Select the method for creating standby tenants
OceanBase Database allows you to create standby tenants by using one of the following three methods based on your business scenario:
Create an empty standby tenant
If the primary tenant is a new tenant, or if the cluster where the primary tenant resides or the log archiving medium stores complete logs of the primary tenant since its creation, you can create standby tenants without relying on baseline or minor compaction data other than the logs. In this case, you can use the
CREATE STANDBY TENANTstatement to create a standby tenant.To check whether the primary tenant has complete logs, perform the following steps:
Log on as the
root userto thesystenant of the cluster where the primary tenant resides.Query the value of
TENANT_IDof the primary tenant.Execute the following statement in the
systenant of the cluster where the primary tenant resides to query the value ofTENANT_IDof the primary tenant:SELECT TENANT_ID FROM oceanbase.DBA_OB_TENANTS WHERE TENANT_NAME = 'mysql001';Execute the following statement in the primary tenant to query the value of
TENANT_IDof the primary tenant:MySQL mode:
SELECT TENANT_ID FROM oceanbase.DBA_OB_TENANTS WHERE TENANT_NAME = 'mysql001';Oracle mode:
SELECT TENANT_ID FROM SYS.DBA_OB_TENANTS WHERE TENANT_NAME = 'oracle001';
The query result is as follows:
+-----------+ | TENANT_ID | +-----------+ | 1002 | +-----------+ 1 rows in setExecute the following statement to query log streams of the primary tenant.
MySQL mode
SELECT TENANT_ID,LS_ID, BEGIN_LSN FROM oceanbase.GV$OB_LOG_STAT WHERE TENANT_ID = 1002 AND ROLE = 'LEADER';Oracle mode
SELECT TENANT_ID,LS_ID, BEGIN_LSN FROM SYS.GV$OB_LOG_STAT WHERE TENANT_ID = 1002 AND ROLE = 'LEADER';
The query result is as follows:
+-----------+-------+-----------+ | TENANT_ID | LS_ID | BEGIN_LSN | +-----------+-------+-----------+ | 1002 | 1 | 0 | | 1002 | 1001 | 0 | +-----------+-------+-----------+ 2 rows in setBEGIN_LSNindicates the earliest log sequence number (LSN) stored in the current log stream replica. If the value ofBEGIN_LSNis0, the current log stream replica contains complete logs generated since the tenant was created.In the query result, the value of
BEGIN_LSNfor the log stream replica is0, which indicates that the log stream replica contains complete logs generated since the tenant was created. If the value ofBEGIN_LSNfor all log stream replicas of the tenant is0, all log stream replicas of the tenant contain complete logs, and you can use theCREATE STANDBY TENANTstatement to create an empty standby tenant.
Create a standby tenant by using the physical backup and recovery feature
You can use this method to create standby tenants in any scenarios. For more information about the physical backup and recovery feature, see Introduction to physical backup and restore.
Create a standby tenant by using the
BACKUP DATABASE PLUS ARCHIVELOGfeatureWhen you create a standby tenant by using the conventional physical backup and recovery feature, you must store data backups and archived logs in shared storage such as Object Storage Service (OSS) and Network File System (NFS). In addition, the shared storage must be accessible to the clusters where the primary and standby tenants reside. These requirements are hard to meet for users who use OceanBase Database Community Edition or have deployed OceanBase Database in standalone mode on a single server.
Therefore, you can use the
BACKUP DATABASE PLUS ARCHIVELOGfeature to generate a database snapshot for all data and archived logs of the primary tenant on the local server if the primary tenant is in standalone mode, or on the shared storage in OceanBase Database Community Edition when the primary tenant belongs to a cluster. The snapshot contains baseline data and archived logs required for running the database. Then you can upload the snapshot to a medium accessible to the cluster where you want to create a standby tenant, and finally restore the standby tenant from the database snapshot.
Configure resources for standby tenants
Before you create standby tenants, you must allocate a resource pool to standby tenants, configure CPU, memory, log disk space, and IOPS resources for standby tenants, and specify the number of replicas, primary zone, and locality for standby tenants.
The resource specifications of a standby tenant can be different from those of the primary tenant. We recommend that you select appropriate resource specifications for standby tenants based on your business needs and the business load of the primary and standby tenants.