Whether you are using a log-archiving-based physical standby or a network-based physical standby, you need to configure a log restore source for the standby tenant. Both deployment methods support dynamic, on-demand modification of the log restore source at any time, and you can also switch between different types of log restore sources as needed. This topic will explain how to configure the log restore source for both log-archiving-based and network-based physical standby scenarios.
Considerations
When switching log restore sources, you must ensure that both the old and new sources match the original source tenant specified at the time the standby tenant was created. This means the log restore source must either use the source tenant’s log archiving or point directly to the source tenant. If the log restore sources before and after the change do not match, it will cause data errors for the standby tenant and make recovery impossible. In this case, you will need to create a new standby tenant.
Scenario where a physical standby tenant is created based on log archiving
When you use the physical backup restore (with logs) feature to create a standby tenant, the default restore source is set for the standby tenant when you execute the RESTORE command to restore the standby tenant. The default restore source is the log archiving destination of the primary tenant or the source standby tenant. Therefore, you usually do not need to set a restore source. If you want to set the log restore source to directly point to the primary tenant or the source standby tenant, refer to Scenario where a physical standby tenant is created by using a network in this topic and configure the log restore source again.
For a standby tenant created by using other methods (create an empty standby tenant and use the BACKUP DATABASE PLUS ARCHIVELOG feature to create a standby tenant), if you want to set the log restore source to use the log archiving of the primary tenant, you need to manually set the log restore source. The following steps describe how to do this.
Notice
If the archiving medium is an object storage service (such as Alibaba Cloud OSS, Azure Blob Storage, AWS S3, or an object storage service compatible with the S3 protocol), you need to refer to the following steps to reconfigure the log restore source if the primary tenant or the source standby tenant changes the backup medium key information during the operation of the physical standby tenant.
Log in as an administrator to the standby tenant, or to the
systenant of the cluster where the standby tenant resides.Execute the following command to configure the standby tenant's restore source to point to the primary tenant's archiving destination.
From the
systenant of the cluster where the standby tenant resides, configure the standby tenant's restore sourceALTER SYSTEM SET LOG_RESTORE_SOURCE ='LOCATION=archive_path' TENANT = tenant_name;From the standby tenant, configure this tenant's own restore source
ALTER SYSTEM SET LOG_RESTORE_SOURCE ='LOCATION=archive_path';
Here, the
LOCATIONattribute specifies the archiving destination of the primary tenant.The following examples describe how to configure the log restore source when the archiving medium is an OSS or NFS server.
Alibaba Cloud OSSNFSWhen the archiving medium of the primary tenant is OSS, the following examples show how to set the log restore source from the
systenant of the cluster where the standby tenant resides, or from the standby tenant:obclient> ALTER SYSTEM SET LOG_RESTORE_SOURCE ='location=oss://oceanbase-test-bucket/backup/archive?host=****.aliyun-inc.com&access_id=****&access_key=****' TENANT = standby_tenant;obclient> ALTER SYSTEM SET LOG_RESTORE_SOURCE ='location=oss://oceanbase-test-bucket/backup/archive?host=****.aliyun-inc.com&access_id=****&access_key=****';When the archiving medium of the primary tenant is NFS, the following examples show how to set the log restore source from the
systenant of the cluster where the standby tenant resides, or from the standby tenant:obclient> ALTER SYSTEM SET LOG_RESTORE_SOURCE ='location=file:///data/1/sh_archive' TENANT = standby_tenant;obclient> ALTER SYSTEM SET LOG_RESTORE_SOURCE ='location=file:///data/1/sh_archive';
Scenario where a physical standby tenant is created by using a network
When you create a standby tenant by using the empty standby tenant method, the default log restore source is set when you execute the CREATE STANDBY TENANT statement: it points directly to the primary tenant. Therefore, you usually do not need to set it again. If you still need to change the log restore source to use the primary tenant's log archiving, refer to Scenario where a physical standby tenant is created based on log archiving in this topic and configure the log restore source again.
For a standby tenant created by using other methods (the backup and restore (with logs) feature and the BACKUP DATABASE PLUS ARCHIVELOG feature), if you need to set the log restore source to point to the primary tenant or source standby tenant, follow the steps below to set it manually with the ALTER SYSTEM SET LOG_RESTORE_SOURCE statement.
Step 1: Create a dedicated user for accessing views
When a standby tenant connects to a primary tenant or source standby tenant, the standby tenant accesses some system views of the primary tenant or source standby 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 source standby tenant, or create a dedicated user with the privilege in the primary tenant or source standby 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: queries the compatibility mode of the primary tenant.For more information about the
DBA_OB_TENANTSview, see DBA_OB_TENANTS.DBA_OB_LS: queries 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 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,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: Obtain access point information for the primary tenant or source standby tenant
For a network-based physical standby deployment, when you set the log restore source you also need the access point information of the primary tenant or source standby tenant; that is, the IP addresses and SQL port numbers of the OBServer nodes where the tenant replicas reside.
Log in to the primary tenant or source standby tenant as the administrator.
Execute the following command to obtain access point information.
MySQL-compatible mode
obclient [oceanbase]> SELECT * FROM oceanbase.DBA_OB_ACCESS_POINT;Note
If you are logged in to the
systenant, query theCDB_OB_ACCESS_POINTview to obtain access point information.Oracle-compatible mode
obclient [SYS]> SELECT * FROM SYS.DBA_OB_ACCESS_POINT;
The query result is as follows:
+-----------+-------------+-------------+----------+ | TENANT_ID | TENANT_NAME | SVR_IP | SQL_PORT | +-----------+-------------+-------------+----------+ | 1004 | mysql | xx.xx.xx.22 | 17855 | | 1004 | mysql | xx.xx.xx.23 | 17857 | | 1004 | mysql | xx.xx.xx.24 | 17859 | +-----------+-------------+-------------+----------+ 3 rows in setIn this example, the queried tenant has three replicas. If the primary tenant or source standby tenant has a single replica, only one row is returned.
Step 3: Check the primary tenant settings
In the current primary/standby architecture, when the primary tenant undergoes scaling in, Transfer, or other operations, its log streams might be deleted and logs might be recycled, potentially causing the standby tenant's log synchronization to become stuck. To resolve this issue, you need to enable archiving mode on the primary tenant or configure the tenant-level parameter ls_gc_delay_time.
To check whether archiving mode is enabled on the primary tenant or whether the value of the ls_gc_delay_time parameter is greater than 0s, perform the following steps:
Check whether archiving mode is enabled on the primary tenant
Log in to the primary tenant or the
systenant of the cluster where the primary tenant resides using an administrator account.Query whether archiving mode is enabled.
For the
systenant of the cluster where the primary tenant resides:obclient> SELECT LOG_MODE FROM oceanbase.DBA_OB_TENANTS WHERE TENANT_NAME='mysql';For user tenants:
MySQL-compatible modeOracle-compatible modeQuery whether archiving mode is enabled in MySQL-compatible mode:
obclient> SELECT LOG_MODE FROM oceanbase.DBA_OB_TENANTS;Query whether archiving mode is enabled in Oracle-compatible mode:
obclient> SELECT LOG_MODE FROM SYS.DBA_OB_TENANTS;
A sample query result is as follows:
+--------------+ | LOG_MODE | +--------------+ | NOARCHIVELOG | +--------------+ 1 row in setAs shown in the query result,
ARCHIVELOGindicates that archiving mode is enabled on the primary tenant, whileNOARCHIVELOGindicates that archiving mode is disabled. For more information about how to enable archiving mode, see Enable archiving mode.
Check whether the value of the
ls_gc_delay_timeparameter is greater than0sThe tenant-level parameter
ls_gc_delay_timeconfigures the delayed deletion time for log streams. The default value is0s, which means the delayed deletion feature is not enabled. When thels_gc_delay_timeparameter is set and archiving is not enabled, a log stream will wait for a specified period before being recycled after meeting the deletion conditions.Log in to the primary tenant as the administrator.
Query the value of the
ls_gc_delay_timeparameter.obclient> SHOW PARAMETERS LIKE '%ls_gc_delay_time%';In the above query result, a value of
0sindicates that the parameter is not configured. If needed, you can adjust this value. For more information about thels_gc_delay_timeparameter, see ls_gc_delay_time.
Step 4: Set the log restore source
Log in as the administrator to the standby tenant or the
systenant of the cluster where the standby tenant resides.Execute the following command to set the log restore source.
Execute the following statement in the
systenant of the cluster where the standby tenant resides to specify the log restore source of the standby tenant:ALTER SYSTEM SET LOG_RESTORE_SOURCE ='SERVICE=$ip_list USER=$user_name@$tenant_name PASSWORD=$password' TENANT = standby_tenant_name;Execute the following statement in the standby tenant to specify the log restore source of the standby tenant:
ALTER SYSTEM SET LOG_RESTORE_SOURCE ='SERVICE=$ip_list USER=$user_name@$tenant_name PASSWORD=$password';
The parameters are described as follows:
$ip_list: the IP addresses and SQL port number of the OBServer nodes where replicas of the primary tenant or source standby tenant reside. Use the information obtained in Step 2. You do not need to specify all OBServer nodes if multiple nodes exist.$user_name: the dedicated user for accessing views, which is created in Step 1.$tenant_name: the name of the primary tenant or source standby tenant to connect to.$password: the password of the dedicated user for accessing views.
An example is as follows:
obclient > ALTER SYSTEM SET LOG_RESTORE_SOURCE = 'SERVICE=11.xx.xx.22:17855;11.xx.xx.23:17857;11.xx.xx.24:17859 USER=rep_user@mysql PASSWORD=******' TENANT = standby_tenant;obclient > ALTER SYSTEM SET LOG_RESTORE_SOURCE = 'SERVICE=11.xx.xx.22:17855;11.xx.xx.23:17857;11.xx.xx.24:17859 USER=rep_user@mysql PASSWORD=******';After successful configuration, you can query the
CDB_OB_LOG_RESTORE_SOURCEview in thesystenant or theDBA_OB_LOG_RESTORE_SOURCEview in a user tenant to verify whether the log restore source has been updated. For more information, see View log restore source information.
