OceanBase Database supports automatic expansion of disk data files based on their actual usage.
Background information
In OceanBase Database, the file that stores data is named block_file. The file is created after each OBServer node starts up and is stored in the /OBServer installation directory/store/sstable directory. The size of the block_file file is controlled by the datafile_size or datafile_disk_percentage configuration parameter. For more information about the data files of OceanBase Database, see Structure of the OBServer node installation directory.
For OceanBase Database V4.2.0 and earlier, the system mainly pre-allocates disk space for data files. This ensures data files occupy a relatively contiguous segment of disk space, avoiding resource contention from other applications. However, this approach reserves significant disk space, which cannot be reclaimed even if not used.
To resolve the issue of pre-allocating large disk spaces that cannot be released, starting from OceanBase Database V4.2.0, a user-configurable option for data files to incrementally use disk space has been introduced. This means the system will first allocate a reasonable disk size to data files, and then automatically expand as needed based on actual disk usage and user configuration.
Related Parameters
OceanBase Database mainly uses the following configuration items to automatically expand disk data files:
datafile_size: the maximum available disk space that can be occupied by the data files. The default value is0M. For more information about the cluster-level parameterdatafile_size, see datafile_size.datafile_disk_percentage: the percentage of disk space occupied by the data file of a node. The default value is0. For more information about the cluster-level parameterdatafile_disk_percentage, see datafile_disk_percentage.datafile_next: specifies the incremental step for autoextending disk data files. The default value is0, indicating that autoextension is disabled. To enable autoextension, set this to a non-zero value. For more information about the cluster-level configuration parameterdatafile_next, see datafile_next.datafile_maxsize: specifies the maximum storage space allowed for automatic expansion of data files. The default value is0, which disables automatic expansion. For more information about the cluster-level configuration parameterdatafile_maxsize, see datafile_maxsize.
When you configure the preceding parameters, note the following:
You can use either
datafile_sizeordatafile_disk_percentageto set the data file disk space. In other cases:If both
datafile_sizeanddatafile_disk_percentageare specified as non-zero values, the value ofdatafile_sizetakes precedence.If neither
datafile_sizenordatafile_disk_percentageis configured (i.e.,datafile_sizeis set toOManddatafile_disk_percentageis set to0), the system will automatically calculate the percentage of disk space occupied by data files, based on whether logs and data share the same disk:If the disk used by logs and data is shared, data files occupy 60% of the total space available on the disk.
If the logs and data are stored on separate disks, then the data files use 90% of the disk space on which they reside.
When configuring
datafile_maxsize, the value must be greater than the current disk space occupied by the data filedatafile_size(ordatafile_disk_percentage). If the set value is less than the current disk space occupied by the data file, automatic expansion will not be triggered.The maximum size of a data file is the smaller value of the
datafile_maxsizeand the maximum available space on the disk.For
datafile_next:If
datafile_nextis set to a value less than or equal to1G, thendatafile_nextwill be set tomin (1G, datafile_maxsize * 10%).When
datafile_nextis set to a value greater than1G, the value ofdatafile_nextismin ( datafile_next, disk space available)
Limitations and considerations
Configure the initial value of the step size
datafile_nextas approximately 20% ofdatafile_maxsizeto reduce frequent expansions when configuring automatic disk data file expansion.After data file auto-expansion is enabled, ensure that the maximum size to which a data file can expand is not less than the value specified for
datafile_maxsizefor the applications deployed on the same host.Dynamic disk data file shrinking is not supported.
If you do not want to enable automatic expansion, you can directly set the value of
datafile_nextordatafile_maxsizeto0Mor leave it at its default value of0. The system will then allocate a portion of disk space to data files using the original pre-allocation method.
Enable automatic expansion of data files
Step 1: View the values of the current configuration items
Before configuring dynamic expansion of disk data files, you need to view the values of the configuration items to understand their current settings.
Log in to the
systenant of the cluster as therootuser.Execute the following command to view the values of the configuration items.
obclient> SHOW PARAMETERS LIKE '%datafile_%';
Step 2: Configure dynamic expansion of disk data files
After obtaining the values of the configuration items, you can modify the values of the configuration items based on your actual usage scenarios to enable automatic expansion of disk data files.
If datafile_size (or datafile_disk_percentage), datafile_next, and datafile_maxsize are configured to non-zero values when the cluster is started
If you have configured datafile_size (or datafile_disk_percentage), datafile_next, and datafile_maxsize to non-zero values when deploying OceanBase Database and starting the OceanBase cluster:
If the value of
datafile_maxsizeis greater than the value ofdatafile_sizeor greater than the disk space calculated based on thedatafile_disk_percentageratio, automatic expansion will take effect after the cluster is started.If the value of
datafile_maxsizeis less than the value ofdatafile_sizeor less than the disk space calculated based on thedatafile_disk_percentageratio, you need to modify the value ofdatafile_maxsizeto a value greater thandatafile_sizebefore enabling automatic expansion of data files.
If only datafile_size (or datafile_disk_percentage) is configured when the cluster is started
If you have only configured datafile_size or datafile_disk_percentage when deploying OceanBase Database and starting the OceanBase cluster, you just need to manually set the values of datafile_maxsize and datafile_next, and ensure that the value of datafile_maxsize is greater than the value of datafile_size or greater than the disk space calculated based on the datafile_disk_percentage ratio.
If datafile_size (or datafile_disk_percentage), datafile_next, and datafile_maxsize are not configured when the cluster is started
If you have not configured datafile_size (or datafile_disk_percentage), datafile_next, and datafile_maxsize when deploying OceanBase Database and starting the OceanBase cluster, you can follow the steps below to enable automatic expansion of disk data files.
Notice
Whether datafile_size or datafile_disk_percentage is set when the cluster is started for the first time mainly affects the initial size of the disk data files.
The specific operations are as follows:
Log in to the
systenant of the cluster as therootuser.Execute the following statement to confirm the pre-allocated space on the disk.
obclient> SELECT data_disk_allocated/1024/1024/1024 AS datafile_G FROM oceanbase.GV$OB_SERVERS;Here is an example of the query result.
+-------------------+ | datafile_G | +-------------------+ | 1770.000000000000 | +-------------------+ 1 row in setAccording to the query result, the pre-allocated space on the disk
data_disk_allocatedis 1770 GB, approximately 1.7 TB.For more information about the fields in the
GV$OB_SERVERSview, see GV$OB_SERVERS.Based on the result from the previous step, set the value of
datafile_maxsizeto a value greater thandata_disk_allocated, and set the value ofdatafile_nextto a non-zero value.Here is an example of the setting:
ALTER SYSTEM SET datafile_maxsize='4TB';ALTER SYSTEM SET datafile_next='1TB';After the setting is successful, execute the following statement to confirm whether automatic expansion is enabled.
SELECT data_disk_allocated/1024/1024/1024 AS datafile_G, data_disk_capacity/1024/1024/1024 AS datafile_max_G FROM oceanbase.GV$OB_SERVERS;Here is an example of the query result.
+-------------------+-------------------+ | datafile_G | datafile_max_G | +-------------------+-------------------+ | 1770.000000000000 | 4096.000000000000 | +-------------------+-------------------+ 1 row in setAccording to the query result, the maximum space for automatic expansion of disk data files
data_disk_capacityis set to the value ofdatafile_maxsize, and the value ofdata_disk_capacityis greater than the value ofdata_disk_allocated, indicating that automatic expansion is enabled.
What to do next
After the configuration is successful, the system will automatically expand the data files based on the actual usage of the data files and the values of datafile_next and datafile_maxsize, to minimize the allocation of disk space.
