Purpose
You can use the CREATE STANDBY TENANT statement to create an empty standby tenant in a Physical Standby Database scenario. A standby tenant created by using this statement automatically enters the continuous synchronization state.
To create a normal user tenant, use the CREATE TENANT statement.
Limitations and considerations
You can use this statement to create a standby tenant only when the primary tenant is newly created and has the complete logs since its creation. For more information about how to verify whether a primary tenant has complete logs, see Preparations.
When you use this statement to create a standby tenant, make sure that a dedicated user has been created for accessing system views such as
GV$OB_LOG_STAT,GV$OB_UNITS,GV$OB_PARAMETERS,DBA_OB_ACCESS_POINT,DBA_OB_TENANTS, andDBA_OB_LSin the primary tenant. For more information about the dedicated user, see Create an empty standby tenant.You must create an empty standby tenant from the sys tenant of the cluster where the standby tenant resides.
Required privileges
You can create a tenant only as the root user of the sys tenant (namely root@sys).
Syntax
CREATE STANDBY TENANT [IF NOT EXISTS] tenant_name
{LOG_RESTORE_SOURCE [=] string_value} [tenant_option_list];
tenant_option_list:
tenant_option [, tenant_option...]
tenant_option:
LOCALITY [=] 'locality_description'
| PRIMARY_ZONE [=] primary_zone_name
| RESOURCE_POOL_LIST [=] (pool_name [, pool_name...])
| COMMENT [=] 'string'
Parameters
| Parameter | Description |
|---|---|
| tenant_name | The name of the standby tenant to be created. The name must start with a letter or an underscore (_) and cannot exceed 63 characters in length. It can contain letters, digits, and underscores (_), and cannot contain reserved keywords of OceanBase Database. |
| IF NOT EXISTS | If the tenant name already exists and IF NOT EXISTS is not specified, an error will be returned. |
| LOG_RESTORE_SOURCE | Required. The log restore source of the tenant, in the format of 'SERVICE=ip_list USER=user_name@tenant_name PASSWORD=password'. The options in the command are described as follows:
|
| LOCALITY | Optional. The distribution of replicas of the standby tenant across zones. For example, F@z1,F@z2,F@z3 indicates that z1, z2, and z3 are full-featured replicas. We recommend that you set the locality of the standby tenant to be the same as that of the primary tenant. |
| PRIMARY_ZONE | The primary zone of the tenant. Valid values:
If you do not specify this parameter when you create a tenant, the default value RANDOM is used. |
| RESOURCE_POOL_LIST | Required. The resource pool list of the standby tenant. We recommend that you set the unit config of the standby tenant to be the same as that of the primary tenant. If the tenant has multiple resource pools, they must have the same UNIT_NUM value, which indicates the number of resource units.
NoticeThe zones of resource pools allocated to the same tenant must not overlap. |
| COMMENT | Optional. The comment. |
Examples
Assume that the primary tenant is named mysql and that a dedicated user test for accessing views in the primary tenant has been created. Perform the following steps to create an empty standby tenant named standby_tenant:
Log on as the
rootuser to thesystenant of the cluster where you want to create the standby tenant.Create a resource unit with one CPU core and 5 GB of memory.
obclient [oceanbase]> CREATE RESOURCE UNIT 1C5G MAX_CPU 1, MEMORY_SIZE = '5G';Create a resource pool named
pool_for_standby.obclient [oceanbase]> CREATE RESOURCE POOL pool_for_standby UNIT = '1C5G', UNIT_NUM = 1, ZONE_LIST = ('zone1', 'zone2', 'zone3');Obtain the value of
LOG_RESTORE_SOURCEand create an empty tenant.obclient [oceanbase]> CREATE STANDBY TENANT IF NOT EXISTS standby_tenant LOG_RESTORE_SOURCE = 'SERVICE=11.xxx.xxx.xxx:17855;11.xxx.xxx.xxx:17857;11.xxx.xxx.xxx:17859 USER=test@mysql PASSWORD=******' RESOURCE_POOL_LIST=('pool_for_standby');View the tenant status in the
DBA_OB_TENANTSview. IfTENANT_ROLEisSTANDBYandSTATUSisNORMAL, the tenant is in the normal state and is created successfully.obclient [oceanbase]> SELECT TENANT_NAME, TENANT_TYPE, CREATE_TIME, STATUS, TENANT_ROLE,SCN_TO_TIMESTAMP(SYNC_SCN) FROM oceanbase.DBA_OB_TENANTS WHERE TENANT_NAME = 'standby_tenant';The query result is as follows:
+----------------+-------------+----------------------------+--------+-------------+----------------------------+ | TENANT_NAME | TENANT_TYPE | CREATE_TIME | STATUS | TENANT_ROLE | SCN_TO_TIMESTAMP(SYNC_SCN) | +----------------+-------------+----------------------------+--------+-------------+----------------------------+ | standby_tenant | USER | 2023-04-14 21:06:48.787550 | NORMAL | STANDBY | 2023-04-14 21:12:59.183293 | +----------------+-------------+----------------------------+--------+-------------+----------------------------+ 1 row in set