You can create an empty standby tenant when the primary tenant is newly created, or when you can confirm that the primary tenant currently has complete logs from the time that tenant was created.
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 needs to access the following system views:
GV$OB_LOG_STAT: obtains the primary tenant's server list, the LSN range of log streams on replica services, and role information (such as whether a replica is a leader).For more information about the
GV$OB_LOG_STATview, see GV$OB_LOG_STAT.GV$OB_UNITS: queries all unit information of the primary tenant to obtain replica status, zone, and region information for filtering, retrieving, and maintaining tenant server connections.For more information about the
GV$OB_UNITSview, see GV$OB_UNITS.GV$OB_PARAMETERS: queries 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: obtains access point information. If the access point changes during primary-tenant migration, replication, or disaster recovery, the standby tenant detects the change automatically and you do not need to change it manually.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.DBA_OB_LOG_RESTORE_SOURCE: used when switching a standby tenant to the primary role to query upstream information about the former primary tenant, so you can determine whether Switchover can run without changing the protection mode.For more information about the
DBA_OB_LOG_RESTORE_SOURCEview, see DBA_OB_LOG_RESTORE_SOURCE.
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-compatible mode
Log in to the primary tenant as the administrator.
Execute the following command to create a new user.
obclient [oceanbase]> CREATE USER rep_user IDENTIFIED BY '******';Grant privileges to the user.
The following example grants the user the
SELECTprivilege on all tables in theoceanbasedatabase. You can also grant only theSELECTprivilege on theGV$OB_LOG_STAT,GV$OB_UNITS,GV$OB_PARAMETERS,DBA_OB_ACCESS_POINT,DBA_OB_TENANTS,DBA_OB_LS, andDBA_OB_LOG_RESTORE_SOURCEviews in theoceanbasedatabase.obclient [oceanbase]> GRANT SELECT ON oceanbase.* TO rep_user;
Oracle-compatible mode
Log in to the primary tenant as the administrator.
Create a new user.
obclient [SYS]> CREATE USER rep_user IDENTIFIED BY ******;Grant the
STANDBY_REPLICATIONrole to the new userrep_user.STANDBY_REPLICATIONis a system default role that includes theCREATE SESSIONsystem privilege and 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
- DBA_OB_LOG_RESTORE_SOURCE
The statement is as follows:
obclient [SYS]> GRANT STANDBY_REPLICATION TO rep_user;
Step 2: Create a standby tenant
Log in as the
rootuser to thesystenant of the cluster where you want to create the standby tenant.Execute the following command to create the unit specification required for the standby tenant.
For example, create a unit specification named
unit1with 1 CPU core and 5 GB memory:obclient [oceanbase]> CREATE RESOURCE UNIT unit1 MAX_CPU 1, MEMORY_SIZE = '5G';For more information about how to create a unit specification, see Create a tenant.
Create the resource pool required for the standby tenant.
For example, create 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 about how to create a resource pool, see Create a tenant.
Execute the following command to 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 tenant name must not be a reserved keyword 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: log restore source configuration. This parameter is required. The value uses the format'SERVICE=$ip_list USER=$user_name@$tenant_name PASSWORD=$password';. The fields are the same as for theALTER SYSTEM SET LOG_RESTORE_SOURCEstatement.The fields of this parameter are described as follows:
$ip_list: the IP addresses and SQL port number (default 2881) of the OBServer nodes where replicas of the primary tenant reside. You can obtain this information by querying theDBA_OB_ACCESS_POINTview in the primary tenant. You do not need to specify all OBServer nodes if multiple nodes exist.$user_name: the dedicated user for accessing views that you just created.$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.
An example is as follows:
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');Execute the following command to view 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, if the value of
TENANT_ROLEisSTANDBYand that ofSTATUSisNORMAL, the standby tenant is in the normal state and has been created successfully.After creation, the standby tenant automatically enters continuous synchronization mode.
