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.
Notice
- After you select the source for a standby tenant, we recommend that you enable log archiving for the source tenant, which is the primary tenant or another standby tenant, of the standby tenant before you create the standby tenant. If log archiving is not enabled for the source tenant, when the standby tenant lags behind the source tenant and the logs on the source tenant have been recycled, log synchronization will be stuck on the standby tenant. If log archiving is enabled for the source tenant before the standby tenant is created, the standby tenant can automatically synchronize data from the archive logs of the source tenant.
- For more information about how to enable log archiving on the source tenant, see Enable log archiving.
- If log synchronization is stuck on the standby tenant because log archiving is not enabled on the source tenant, troubleshoot the issue by referring to Issue 3: The log synchronization of the standby tenant is abnormal in Log synchronization stuck for the physical standby database.
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 to which the primary tenant belongs 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 administrator to the primary tenant or the sys tenant of the cluster to which the primary tenant belongs.
Execute the following statement to query comparison information about log streams in the primary tenant.
Query the information from the sys tenant of the cluster to which the primary tenant belongs
(SELECT LS_ID FROM oceanbase.CDB_OB_LS_HISTORY WHERE TENANT_ID = xxxx) EXCEPT (SELECT LS_ID FROM oceanbase.CDB_OB_LS WHERE TENANT_ID = xxxx);or
(SELECT LS_ID FROM oceanbase.CDB_OB_LS_HISTORY WHERE TENANT_ID = xxxx) MINUS (SELECT LS_ID FROM oceanbase.CDB_OB_LS WHERE TENANT_ID = xxxx);You can query the
DBA_OB_TENANTSview for the ID of the primary tenant.Query the information from the primary tenant
MySQL modeOracle mode(SELECT LS_ID FROM oceanbase.DBA_OB_LS_HISTORY) EXCEPT (SELECT LS_ID FROM oceanbase.DBA_OB_LS);or
(SELECT LS_ID FROM oceanbase.DBA_OB_LS_HISTORY) MINUS (SELECT LS_ID FROM oceanbase.DBA_OB_LS);(SELECT LS_ID FROM SYS.DBA_OB_LS_HISTORY) MINUS (SELECT LS_ID FROM SYS.DBA_OB_LS);
You can query the
DBA_OB_LS_HISTORYorCDB_OB_LS_HISTORYview for information about all log streams created in the tenant, and query theDBA_OB_LSorCDB_OB_LSview for the log stream that provides services in the tenant. If the query result is not empty, the query result shows the log streams that were once created in the primary tenant but were deleted later due to reasons such as load balancing or scaling.In this case, the logs of the primary tenant are incomplete, and you cannot use the
CREATE STANDBY TENANTstatement to create a standby tenant. If the query result is empty, proceed to the next step.Execute the following statement to query log streams of the primary tenant.
Query log streams of the primary tenant from the sys tenant of the cluster to which the primary tenant belongs
SELECT LS_ID, BEGIN_LSN FROM oceanbase.GV$OB_LOG_STAT WHERE TENANT_ID = xxxx AND ROLE = 'LEADER' ;You can query the
DBA_OB_TENANTSview for the ID of the primary tenant.Query the information from the primary tenant
MySQL modeOracle modeSELECT LS_ID, BEGIN_LSN FROM oceanbase.GV$OB_LOG_STAT WHERE ROLE = 'LEADER' ;SELECT LS_ID, BEGIN_LSN FROM SYS.GV$OB_LOG_STAT WHERE ROLE = 'LEADER' ;
A sample query result is as follows:
+-------+-----------+ | LS_ID | BEGIN_LSN | +-------+-----------+ | 1 | 0 | | 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 restore (with complete logs) feature
You can use this method to create standby tenants in any scenarios. For more information about the physical backup and restore feature, see Overview.
Create a standby tenant by using the BACKUP DATABASE PLUS ARCHIVELOG feature
When you create a standby tenant by using the regular physical backup and restore (with complete logs) feature, you must use shared storage such as Alibaba Cloud Object Storage Service (OSS) or Network File System (NFS) to store data backups and archive logs, and the shared storage must be accessible to the clusters to which the primary and standby tenants belong. 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 ARCHIVELOG feature to generate a database snapshot for all data and archive 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 archive 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. You can calculate the amount of physical resources required by each resource unit of the standby tenant based on the primary tenant and the number of resource units of the standby tenant to be created.
Assume that the tenant ID of the primary tenant is 1002 and two resource units are to be created for the standby tenant. After you log on to the sys tenant of the cluster to which the primary tenant belongs, you can execute the following statement to calculate the amount of physical resources required by each resource unit of the standby tenant:
obclient [oceanbase]> CALL DBMS_OB_LIMIT_CALCULATOR.CALCULATE_MIN_PHY_RES_NEEDED_BY_STANDBY_TENANT(PRIMARY_TENANT_ID => 1002, STANDBY_TENANT_UNIT_NUM => 2);
The result is as follows:
+------------------------+------------+
| PHYSICAL_RESOURCE_NAME | MIN_VALUE |
+------------------------+------------+
| memstore | 0 |
| memory | 4294967296 |
| data_disk | 0 |
| clog_disk | 2147483648 |
| cpu | 0 |
+------------------------+------------+
5 rows in set