This topic describes the preparations for log archiving.
(Optional) Configure the log archiving concurrency
Before you enable the ARCHIVELOG mode for a tenant, you can configure the log archiving concurrency to accelerate log archiving for the tenant.
Log on to the database as an administrator of the
systenant or a user tenant.Configure the
log_archive_concurrencyparameter by using a proper statement.The tenant-level parameter
log_archive_concurrencyspecifies the total number of worker threads for log archiving. The modification of this parameter takes effect immediately without restarting the OBServer node. The value range of this parameter is [0, 100]. The default value is0, which means using the adaptive log archiving concurrency of OceanBase Database. We recommend that you use the default value.Notice
If the tenant is configured with two or four CPU cores, we recommend that you retain the default value of this parameter.
Methods for adjusting the log archiving concurrency are as follows:
Execute the following statement in the
systenant to adjust the log archiving concurrency of a specified tenant:ALTER SYSTEM SET log_archive_concurrency = 10 TENANT = mysql_tenant;Execute the following statement in the
systenant to adjust the log archiving concurrency of all tenants:ALTER SYSTEM SET log_archive_concurrency = 10 TENANT = ALL;Execute the following statement in a user tenant to adjust its log archiving concurrency:
ALTER SYSTEM SET log_archive_concurrency = 10;
For more information about the
log_archive_concurrencyparameter, see log_archive_concurrency.
Configure the archive destination
Before you initiate a log archiving job, you must execute the ALTER SYSTEM statement to configure the LOG_ARCHIVE_DEST parameter. The sys tenant is used for managing clusters and does not contain user data or support backup or restore. Therefore, you do not need to configure an archive destination for the sys tenant.
Set the LOCATION, PIECE_SWITCH_INTERVAL, and BINDING attributes of the archive destination.
Log on to the database as an administrator of the
systenant or a user tenant.Note
The administrator user of a MySQL tenant is
rootand that of an Oracle tenant isSYS.Configure the archive destination.
At present, OceanBase Database allows you to select Network File System (NFS) or Alibaba Cloud Object Storage Service (OSS) as the archive destination.
Configure the archive destination for a specified tenant in the
systenant:ALTER SYSTEM SET LOG_ARCHIVE_DEST='LOCATION=xxx [PIECE_SWITCH_INTERVAL=xxx] [BINDING=xxx]' TENANT = tenant_name;Configure the archive destination for a user tenant from the current tenant:
ALTER SYSTEM SET LOG_ARCHIVE_DEST='LOCATION=xxx [PIECE_SWITCH_INTERVAL=xxx] [BINDING=xxx]';
Notice
After upgrading OceanBase Database from V4.0.x to V4.1.0, it is necessary to change the archive path. However, when upgrading from V4.1.x to V4.2.0, there is no need to modify the archive path. Moreover, during the upgrade process from V4.1.x to V4.2.0, you have the option to archive logs.
You can query the
CDB_OB_ARCHIVE_DESTview from thesystenant or theDBA_OB_ARCHIVE_DESTview from a user tenant for the settings. For more information, see View the archiving parameter settings.The procedure is as follows:
(Required) Set
LOCATION.The
LOCATIONattribute specifies the archive destination. OceanBase Database supports two types of media as the archive destination: Network File System (NFS) and Alibaba Cloud Object Storage Service (OSS).NFS
Notice
When you use NFS as the archive destination, note that:
- The value of
LOCATIONcannot be a string with a question mark (?). - The value of
LOCATIONmust be an absolute path, and the OBServer node must have read and write privileges on the destination specified byLOCATION. - Ensure that all OBServer nodes are mounted to NFS of the same server and use the parameter settings recommended in this topic. For more information about the procedure of deploying NFS, see Deploy NFS.
To set NFS as the archive destination, execute the following statement:
ALTER SYSTEM SET LOG_ARCHIVE_DEST='LOCATION=file:///data/nfs/backup/archive' TENANT = mysql_tenant;ALTER SYSTEM SET LOG_ARCHIVE_DEST='LOCATION=file:///data/nfs/backup/archive';In this example,
file://specifies that NFS is used as the media for the archive destination, and the archive path is/data/nfs/backup/archive.- The value of
OSS
When you use OSS as the archive destination, besides the archive path and the
host,access_key, andaccess_idparameters, you can also set thedelete_modeparameter to configure the cleanup mode for archived files.The
delete_modeparameter has two values:deleteandtagging. If you do not specify this parameter, the default valuedeletetakes effect.delete: Archived files that meet the cleanup requirements are directly deleted.In this mode, when you enable automatic cleanup for archived files in automatic mode, the system directly deletes the archived files that meet the requirements.
Notice
This is the default cleanup mode. If you do not specify
delete_mode, the default cleanup modedeletetakes effect.tagging: The archived files that meet the cleanup requirements are tagged and retained.In this mode, when you enable automatic cleanup for archived files, the system directly tags the archived files that meet the cleanup requirements. The key of the tag is
delete_modeand the value istagging. In this way, you can manage the lifecycle of these files on OSS based on the tags.
For more information about the automatic cleanup of archived data in
deleteortaggingmode, see Automatic cleanup of archived data.To set OSS as the archive destination and configure the
taggingcleanup mode, execute the following statement:ALTER SYSTEM SET LOG_ARCHIVE_DEST='LOCATION=oss://oceanbase-test-bucket/backup/archive?host=xxx.aliyun-inc.com&access_id=xxx&access_key=xxx&delete_mode=tagging' TENANT = mysql_tenant;ALTER SYSTEM SET LOG_ARCHIVE_DEST='LOCATION=oss://oceanbase-test-bucket/backup/archive?host=xxx.aliyun-inc.com&access_id=xxx&access_key=xxx&delete_mode=tagging';In this example,
oss://specifies that OSS is the archive destination. The storage bucket is namedoceanbase-test-bucket. The path in the storage bucket is/backup/archive. The question mark (?) is used to separate other parameters of the path. Thehostparameter specifies the host address of the storage bucket. Theaccess_idandaccess_keyparameters specify the access key of OSS. The cleanup mode is set totagging.
(Optional) Set the
BINDINGattribute.The
BINDINGattribute specifies the prioritizing mode for archiving and businesses. TheBINDINGattribute has two values:OptionalandMandatory. If you do not specify this attribute, the default valueOptionaltakes effect.The
Optionalmode prioritizes user businesses. In this mode, when log archiving falls behind log generation, logs may be recycled before being archived. This causes an interruption.The
Mandatorymode prioritizes archiving. In this mode, you may be unable to write more data before existing data is archived.
Here is an example:
ALTER SYSTEM SET LOG_ARCHIVE_DEST='LOCATION=file:///data/nfs/backup/archive BINDING = Optional' TENANT = mysql_tenant;ALTER SYSTEM SET LOG_ARCHIVE_DEST='LOCATION=file:///data/nfs/backup/archive BINDING = Optional';(Optional) Set the
PIECE_SWITCH_INTERVALattribute.The
PIECE_SWITCH_INTERVALattribute specifies the switching interval for pieces. The value range is[1d, 7d]. If you do not specify this attribute, the default value1dtakes effect.To configure an archive path and generate a log piece every two days, execute either of the following statements:
ALTER SYSTEM SET LOG_ARCHIVE_DEST='LOCATION=file:///data/nfs/backup/archive BINDING=Optional PIECE_SWITCH_INTERVAL=1d' TENANT = mysql_tenant;ALTER SYSTEM SET LOG_ARCHIVE_DEST='LOCATION=file:///data/nfs/backup/archive BINDING=Optional PIECE_SWITCH_INTERVAL=1d';
Considerations
After you configure the LOG_ARCHIVE_DEST parameter, by default, the system creates a file named format in the directory to which the specified destination belongs. This file is used to verify the validity information of the archive destination and ensure the integrity of data in the destination. Therefore, note the following when you configure the log archive destination:
If the
formatfile does not exist, the directory where the configured destination is located must be empty so that theLOG_ARCHIVE_DESTparameter can be set. If this directory is not empty, the system returns the-9080error to indicate that theformatfile does not exist.If the
formatfile exists, its content must be verified so that the parameter can be set. Otherwise, the system returns the-9081error to indicate that theformatfile does not match. The content of theformatfile is verified to check whether the types of the cluster, tenant, and backup destination in the file match those of the current cluster, tenant, and backup destination.When you execute a backup job, the job fails to be initiated if the
formatfile does not exist or fails the verification.
In addition, incremental configuration is not supported after the archive destination is configured. Assume that the BINDING attribute is set to Mandatory and the PIECE_SWITCH_INTERVAL attribute is set to 1d for the archive path /data/nfs/backup/archive in NFS. To change the value of PIECE_SWITCH_INTERVAL to 2d and keep the setting of the BINDING attribute to Mandatory, you still need to specify the values of other attributes in the statement. If you do not specify a value for an attribute, the default value is used for the attribute.
Execute the following statement to modify the attribute settings:
ALTER SYSTEM SET LOG_ARCHIVE_DEST = 'LOCATION=file:///data/nfs/backup/archive BINDING=Mandatory PIECE_SWITCH_INTERVAL=2d' TENANT = mysql_tenant;
Set the archiving status of the archive destination
By default, the archiving status of a newly configured archive destination is ENABLE. You can query the DBA_OB_ARCHIVE_DEST view for the archiving status of the archive destination. For more information, see View the archiving parameter settings. If ARCHIVELOG has been enabled for this tenant, the system automatically triggers an archiving job to archive logs to the specified path of the destination.
The following table describes the archiving status of the archive destination.
| State | Description |
|---|---|
| ENABLE | Archiving is enabled at the archive destination. If no archiving job is initiated, the system will initiate an archiving job. |
| DEFER | Archiving is stopped at the archive destination. If an archiving job is in progress, the system will stop the archiving job. |
Perform the following steps to set the archiving status of the archive destination to DEFER or ENABLE based on the actual situation.
Log on to the database as an administrator of the
systenant or a user tenant.Note
The administrator user of a MySQL tenant is
rootand that of an Oracle tenant isSYS.Enable or disable archiving at the archive destination based on the actual situation.
Enable archiving at the archive destination.
Enable archiving for a user tenant from the
systenant.ALTER SYSTEM SET LOG_ARCHIVE_DEST_STATE='ENABLE' TENANT = tenant_name;Enable archiving for a user tenant.
ALTER SYSTEM SET LOG_ARCHIVE_DEST_STATE='ENABLE';
After archiving is enabled at the archive destination, an archiving job will be triggered after
ARCHIVELOGis enabled for the tenant, to archive logs to the specified path of the destination. IfARCHIVELOGhas been enabled for the tenant, an archiving job is automatically triggered.Disable archiving at the archive destination.
Disable archiving for a user tenant from the
systenant.ALTER SYSTEM SET LOG_ARCHIVE_DEST_STATE='DEFER' TENANT = tenant_name;Disable archiving for a user tenant.
ALTER SYSTEM SET LOG_ARCHIVE_DEST_STATE='DEFER';
After archiving is disabled at the archive destination, the ongoing archiving job will be suspended. You can set the archiving status of the archive destination to
ENABLEto resume the archiving job.