MariaDB Enterprise Server Configure the InnoDB Undo Log
This page is part of MariaDB's Documentation.
The parent of this page is: MariaDB Enterprise Server InnoDB Operations
Topics on this page:
Overview
The InnoDB undo log is a transaction log used by InnoDB to keep track of multiple row versions for multi-version concurrency control (MVCC). When a row's value changes, InnoDB stores old versions of the row in the Undo Log.
When transactions are committed and the old row versions are no longer necessary, the InnoDB Purge Threads asynchronously delete old row versions from the Undo Log in the background.
When a transaction is rolled back, InnoDB uses the Undo Log to rollback the transaction's changes.
For additional information, see "InnoDB Undo Log".
This page describes how to configure the InnoDB Undo Log.
Configure InnoDB Undo Log Tablespaces
By default, the InnoDB undo log is located in the InnoDB system tablespace, which is defined by the innodb_
InnoDB can be configured to use separate undo log tablespaces by setting the innodb_undoN
, where N
is an integer.
When you configure separate undo log tablespaces, you can also configure the separate undo log tablespaces to go to a specific directory by setting the innodb_
Separate InnoDB undo log tablespaces must be configured prior to the initialization of the server's InnoDB data directory. If you try to configure separate InnoDB undo log tablespaces when the InnoDB data directory has already been initializes, you will see errors in the error log during startup similar to the following:
[ERROR] InnoDB: Expected to open innodb_undo_tablespaces=8 but was able to find only 0
[ERROR] InnoDB: Plugin initialization aborted with error Generic error
To safely configure separate InnoDB undo log tablespaces:
If you have preexisting data, backup your data with MariaDB Dump.
Ensure that the server is stopped:
$ sudo systemctl stop mariadb
Choose a configuration file for custom changes to system variables and options.
It is not recommended to make custom changes to Enterprise Server's default configuration files, because your custom changes can be overwritten by other default configuration files that are loaded after.
Ensure that your custom changes will be read last by creating a custom configuration file in one of the included directories. Configuration files in included directories are read in alphabetical order. Ensure that your custom configuration file is read last by using the
z-
prefix in the file name.Some example configuration file paths for different distributions are shown in the following table:
Distributions
Example configuration file path
CentOSRHELRocky LinuxSLES/etc/my.cnf.d/z-custom-mariadb.cnf
DebianUbuntu/etc/mysql/mariadb.conf.d/z-custom-mariadb.cnf
Set the innodb_
undo_ system variable in the configuration file.tablespaces It needs to be set in a group that will be read by MariaDB Server, such as
[mariadb]
or[server]
.For example, to set the number of tablespaces to 8:
[mariadb] ... innodb_undo_tablespaces=8
If you want your InnoDB undo log tablespaces to be in a specific directory, then also set the innodb_
undo_ system variable in the configuration file:directory For example, to set the directory to
/innodb/undo
:[mariadb] ... innodb_undo_directory=/innodb/undo
If you want your InnoDB undo log tablespaces to be in a specific directory, then also create the directory, and give it the proper permissions:
$ sudo mkdir -p /innodb/undo $ sudo chown mysql:mysql /innodb/undo
Delete the current contents of the datadir and innodb_
data_ .home_ dir For example, if the default value of
/var/lib/mysql
is used for both:$ sudo rm -fr /var/lib/mysql/*
Reinitialize the data directory using the MariaDB Install DB command.
For example, on ES 10.4, CS 10.4, and later, use
mariadb-install-db
:$ sudo mariadb-install-db --user=mysql --datadir=/var/lib/mysql/
And on ES 10.3, CS 10.3, and before, use
mysql_install_db
:$ sudo mysql_install_db --user=mysql --datadir=/var/lib/mysql/
Start the server:
$ sudo systemctl start mariadb
Connect to the server using MariaDB Client:
$ mariadb --user=root
If your server had preexisting data, then reload the backup taken at the beginning of the procedure.
Confirm that the configuration changes were properly applied by checking the values of the system variables using the SHOW GLOBAL VARIABLES statement:
SHOW GLOBAL VARIABLES WHERE Variable_name IN ( 'innodb_undo_tablespaces', 'innodb_undo_directory' );
+-------------------------+--------------+ | Variable_name | Value | +-------------------------+--------------+ | innodb_undo_directory | /innodb/undo | | innodb_undo_tablespaces | 8 | +-------------------------+--------------+
Consider also enabling undo log truncation to increase performance of the InnoDB Purge Threads.
Enable InnoDB Undo Log Truncation
If a server is configured to have 2 or more separate InnoDB undo log files, then InnoDB undo log truncation can be enabled by setting the innodb_SUPER
privilege.
When InnoDB undo log truncation is enabled, the InnoDB purge threads can truncate an entire undo log at once, rather than individually freeing each rollback segment within the undo log.
An undo log is truncated when its size exceeds the innodb_
The frequency at which the InnoDB purge threads check for undo logs to truncate is configured by setting the innodb_
To ensure that the changes survive server restarts, the system variables should also be set in a configuration file.
To enable InnoDB undo log truncation:
Connect to the server using MariaDB Client as the
root@localhost
user account or another user account with theSUPER
privilege:$ mariadb --user=root
Set the innodb_
undo_ system variable tolog_ truncate ON
using the SET GLOBAL statement.For example:
SET GLOBAL innodb_undo_log_truncate=ON;
If you would like to change the size at which undo logs are truncated, then also set the innodb_
max_ system variable to the new size using the SET GLOBAL statement.undo_ log_ size For example, to set the size to 2 GB:
SET GLOBAL innodb_max_undo_log_size=(2 * 1024 * 1024 * 1024);
If you would like the InnoDB purge threads to check the undo logs more frequently, then also set the innodb_
purge_ system variable to a lower value using the SET GLOBAL statement.rseg_ truncate_ frequency For example, to configure the purge threads to check the undo logs for truncation every 64 iterations:
SET GLOBAL innodb_purge_rseg_truncate_frequency=64;
Choose a configuration file for custom changes to system variables and options.
It is not recommended to make custom changes to Enterprise Server's default configuration files, because your custom changes can be overwritten by other default configuration files that are loaded after.
Ensure that your custom changes will be read last by creating a custom configuration file in one of the included directories. Configuration files in included directories are read in alphabetical order. Ensure that your custom configuration file is read last by using the
z-
prefix in the file name.Some example configuration file paths for different distributions are shown in the following table:
Distributions
Example configuration file path
CentOSRHELRocky LinuxSLES/etc/my.cnf.d/z-custom-mariadb.cnf
DebianUbuntu/etc/mysql/mariadb.conf.d/z-custom-mariadb.cnf
Set the system variables in the configuration file.
It needs to be set in a group that will be read by MariaDB Server, such as
[mariadb]
or[server]
.When set in a configuration file, the innodb_
max_ value supports units, such as "M", "G", etc.undo_ log_ size For example:
[mariadb] ... innodb_undo_log_truncate=ON innodb_max_undo_log_size=2G innodb_purge_rseg_truncate_frequency=64