You can create an empty standby tenant if the primary tenant is a new tenant or the primary tenant contains complete logs generated since its creation.
Step 1: Create a dedicated user for accessing views
When a standby tenant connects to a primary tenant, the standby tenant must access system views of the primary tenant. Therefore, a dedicated user with the privilege to query the system views is required. You can use a user with the privilege in the primary tenant, or create a dedicated user with the privilege in the primary tenant for the standby tenant.
The standby tenant need to access the following system views:
GV$OB_LOG_STAT: contains the servers in the primary tenant, the log sequence number (LSN) range of log streams for replicas, and the role information indicating whether a replica is a leader.For more information about the
GV$OB_LOG_STATview, see GV$OB_LOG_STAT.GV$OB_UNITS: contains the replica status, zones, and regions of all units in the primary tenant. You can use this view to filter, query, and maintain server connections for tenants.For more information about the
GV$OB_UNITSview, see GV$OB_UNITS.GV$OB_PARAMETERS: contains the metadata required for services, such as thecluster_idandtenant_idof the primary tenant.For more information about the
GV$OB_PARAMETERSview, see GV$OB_PARAMETERS.DBA_OB_ACCESS_POINT: contains information about the access portal. If the access portal changes during migration, replication, or disaster recovery of the primary tenant, the standby tenant automatically synchronizes the change without manual modification.For more information about the
DBA_OB_ACCESS_POINTview, see DBA_OB_ACCESS_POINT.DBA_OB_TENANTS: contains the compatibility mode of the primary tenant.For more information about the
DBA_OB_TENANTSview, see DBA_OB_TENANTS.DBA_OB_LS: contains the log streams and log stream status of the primary tenant.For more information about the
DBA_OB_LSview, see DBA_OB_LS.
To create and authorize a dedicated user, perform the following operations:
Notice
In OceanBase Database, standby tenants synchronize usernames and privileges from a primary tenant. You cannot create a user or grant privileges to a user in a standby tenant. Therefore, if the source of a standby tenant is another standby tenant, you must create a dedicated user for accessing views in the corresponding primary tenant and grant privileges to the user.
MySQL mode
Log on to the primary tenant as the administrator.
Create a user.
obclient [oceanbase]> CREATE USER rep_user IDENTIFIED BY '******';Grant privileges to the user.
The following sample statement grants the user the
SELECTprivilege on all tables in theoceanbasedatabase. You can also grant the user theSELECTprivilege on theGV$OB_LOG_STAT,GV$OB_UNITS,GV$OB_PARAMETERS,DBA_OB_ACCESS_POINT,DBA_OB_TENANTS, andDBA_OB_LSviews in theoceanbasedatabase.obclient [oceanbase]> GRANT SELECT ON oceanbase.* TO rep_user;
Oracle mode
Log on to the primary tenant as the administrator.
Create a user.
obclient [SYS]> CREATE USER rep_user IDENTIFIED BY ******;Grant the
STANDBY_REPLICATIONrole to the created userrep_user.STANDBY_REPLICATIONis a default system role that has theCREATE SESSIONprivilege and the query privileges on the following views by default:- GV$OB_LOG_STAT
- GV$OB_UNITS
- GV$OB_PARAMETERS
- DBA_OB_ACCESS_POINT
- DBA_OB_TENANTS
- DBA_OB_LS
- DBA_OB_LS_HISTORY
Here is a sample statement:
obclient [SYS]> GRANT STANDBY_REPLICATION TO rep_user;
Step 2: Create a standby tenant
Log on as the
rootuser to thesystenant of the cluster where you want to create the standby tenant.Create a unit config for the standby tenant.
The following sample statement creates a unit config named
unit1that contains one CPU core and 5 GB of memory:obclient [oceanbase]> CREATE RESOURCE UNIT unit1 MAX_CPU 1, MEMORY_SIZE = '5G';For more information, see Create a tenant.
Create a resource pool for the standby tenant.
The following sample statement creates a resource pool named
pool_for_standby.obclient [oceanbase]> CREATE RESOURCE POOL pool_for_standby UNIT = 'unit1', UNIT_NUM = 1, ZONE_LIST = ('zone1','zone2','zone3');For more information, see Create a tenant.
Create an empty standby tenant.
The SQL syntax is as follows:
CREATE STANDBY TENANT [IF NOT EXISTS] tenant_name LOG_RESTORE_SOURCE [=] string_value [tenant_characteristic_list]; tenant_characteristic_list: tenant_characteristic [, tenant_characteristic...] tenant_characteristic: COMMENT 'string' | PRIMARY_ZONE [=] zone_name | RESOURCE_POOL_LIST [=](pool_name [, pool_name...]) | LOCALITY [=] 'locality description'The parameters are described as follows:
tenant_name: the name of the standby tenant to be created. This parameter is required. The name cannot exceed 128 characters in length. It must contain only uppercase and lowercase letters, digits, and underscores. The name must start with a letter or an underscore (_) and must not contain reserved keywords of OceanBase Database.IF NOT EXISTS: If the tenant name already exists and you do not specify theIF NOT EXISTSparameter, the system returns an error. This parameter is optional.LOG_RESTORE_SOURCE: the log restore source, in the format of'SERVICE=$ip_list USER=$user_name@$tenant_name PASSWORD=$password';. This parameter is required. The fields of this parameter are consistent with those specified in theALTER SYSTEM SET LOG_RESTORE_SOURCEstatement.The fields of this parameter are described as follows:
$ip_list: the IP addresses and SQL port number of the OBServer nodes where replicas of the primary tenant reside. The SQL port number is 2881 by default. You can obtain the IP address and SQL port number by querying theDBA_OB_ACCESS_POINTview in the primary tenant.$user_name: the name of the dedicated user for accessing views.$tenant_name: the name of the primary tenant to connect to.$password: the password of the dedicated user for accessing views.
COMMENT: the comment. This parameter is optional.RESOURCE_POOL_LIST: the resource pools to be used by the standby tenant. This parameter is required.PRIMARY_ZONE: the name of the primary zone where the standby tenant resides. This parameter is optional.LOCALITY: the distribution of replicas of the standby tenant across zones. This parameter is optional.
Here is an example:
obclient [oceanbase]> CREATE STANDBY TENANT IF NOT EXISTS standby_tenant LOG_RESTORE_SOURCE = "SERVICE=xx.xx.xx.1:2881;xx.xx.xx.2:2881;xx.xx.xx.3:2881 USER=rep _user@mysql PASSWORD=******" RESOURCE_POOL_LIST=('pool_for_standby');Query the tenant status.
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 setIn the query result, the value of
TENANT_ROLEisSTANDBYand that ofSTATUSisNORMAL, which indicates that the standby tenant has been created and is in the normal state.The standby tenant automatically enters the continuous synchronization mode.