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 needs 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-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, andDBA_OB_LSviews in theoceanbasedatabase.obclient [oceanbase]> GRANT SELECT ON oceanbase.* TO rep_user;
Oracle-compatible mode
Log in to the primary tenant as the administrator.
Execute the following command to 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
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. The name 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 (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.