A guide for compiling older versions of MariaDB (specifically 5.3) with the original XtraDB engine from Percona Server, useful for testing purposes.
Sometimes, one needs to have MariaDB compiled with Vanilla XtraDB. This page describes the process to do this. The process is rather crude, as my goal was just a once-off compile for testing (that is, not packaging or shipping) purposes.
The process is applicable to and XtraDB from Percona Server 5.1.61.
wget http://s.petrunia.net/scratch/make-vanilla-xtradb-work-with-mariadb.diff
bzr branch /path/to/mariadb-5.3 5.3-vanilla-xtradb-r3
cd 5.3-vanilla-xtradb-r3/storage/
tar czf innodb_plugin.tgz innodb_plugin/
rm -rf innodb_plugin
tar czf xtradb.tgz xtradb/
rm -rf xtradb
cd ../../
tar zxvf ~/Percona-Server-5.1.61.tar.gz
cp -r Percona-Server-5.1.61/storage/innodb_plugin 5.3-vanilla-xtradb-r3/storage/
patch -p1 -d 5.3-vanilla-xtradb-r3/storage/innodb_plugin/ < make-vanilla-xtradb-work-with-mariadb.diff
cd 5.3-vanilla-xtradb-r3/
BUILD/autorun.sh
./configure --with-plugin-innodb_plugin
makeThis page is licensed: CC BY-SA / Gnu FDL
Explains how to use CMake options like `PLUGIN_xxx` to control which plugins are built statically, dynamically, or not at all during compilation.
By default all plugins are enabled and built as dynamic .so (or .dll) modules. If a plugin does not support dynamic builds, it is not built at all.
Use PLUGIN_xxx cmake variables. They can be set on the command line with -DPLUGIN_xxx=value or in the cmake gui. Supported values are
Instructions on building and configuring MariaDB to use alternative memory allocators like TCMalloc or jemalloc for improved performance and profiling.
Read the page for more information on how to debug high memory consumption.
is a malloc replacement library optimized for multi-threaded usage. It also features a built-in heap debugger and profiler.
Another malloc replacement that may speed up MariaDB is .
The procedures to use one of these libraries with MariaDB are the same. Many other malloc replacement libraries (as well as heap debuggers and profilers) can be used with MariaDB in a similar fashion.
STATIC
the plugin will be compiled statically, if supported. Otherwise it will be not compiled.
DYNAMIC
the plugin will be compiled dynamically, if supported. Otherwise it will be not compiled. This is the default behavior.
AUTO
the plugin will be compiled statically, if supported. Otherwise it will be compiled dynamically.
YES
same as AUTO, but if plugin prerequisites (for example, specific libraries) are missing, it will not be skipped, it will abort cmake with an error.
Note that unlike autotools, cmake tries to configure and build incrementally. You can modify one configuration option and cmake will only rebuild the part of the tree affected by it. For example, when you do cmake -DWITH_EMBEDDED_SERVER=1 in the already-built tree, it will make libmysqld to be built, but no other configuration options will be changed or reset to their default values.
In particular this means that if you have run, for examplecmake -DPLUGIN_OQGRAPH=NO
and later you want to restore the default behavior (with OQGraph being built) in the same build tree, you would need to runcmake -DPLUGIN_OQGRAPH=DYNAMIC
Alternatively, you might simply delete the CMakeCache.txt file — this is the file where cmake stores current build configuration — and rebuild everything from scratch.
This page is licensed: CC BY-SA / Gnu FDL
NO
the plugin will be not compiled at all
If you are unsure which malloc implementation is in use, or if you used one of the procedures explained in this page and you want to verify if it succeeded, you can run this query:
A value of "system" indicates the system default, which is normally malloc. If another library is used, this query will return the name and version of the library.
To build with TCMalloc, you need to use the following command
To use jemalloc, the option should be -ljemalloc.
If you want to do this only one time, as a test, you can also start a standard MariaDB server with TCmalloc with:
If you want to configure mariadbd-safe to use tcmalloc or jemalloc, edit your configuration file, in the [mariadbd-safe] group:
First, locate the library file that needs to be used:
Now pass it to mariadbd using the LD_PRELOAD variable:
For example, on OpenSuse 15.4 one would do:
If you use systemd to run MariaDB, first locate the library as explained above. The locate the service configuration file:
Now edit the mariadb.service file by adding a line to the [Service] group:
For example:
Now you should reload the configuration, so that the news setting will take effect, and restart MariaDB:
If you run MariaDB on Docker and use an image from a Dockerfile that is publicly available, most probably you have an entrypoint that is a Bash script, which starts mariadbd directly. You can edit this Bash script as explained above. Or you can set the LD_PRELOAD variable from the Dockerfile:
To find the library file you can run one of these commands while the container is running:
Example:
Usually Vagrant is used to start a complete system in a virtual machine. If this is your case, you can use one of the methods above, for example you can modify your Vagrantfile to copy a modified version of the mariadb.service file into the guest system to configure systemd.
If you use Vagrant with the Docker provider, you can follow the instructions above to modify the Dockerfile.
jemalloc can provide a report of memory leaks at program exit:
This will produce something like:
You can learn more about the memory leaks with jeprof, that is included with jemalloc:
You can also generate a PDF call graph of the leak:
This page is licensed: CC BY-SA / Gnu FDL
SHOW GLOBAL VARIABLES LIKE 'version_malloc_library';cmake -DCMAKE_EXE_LINKER_FLAGS='-ltcmalloc' -DWITH_SAFEMALLOC=OFF/usr/sbin/mariadbd-safe --malloc-lib=tcmallocmalloc-lib=tcmalloc# jemalloc
find /usr/lib -name "libjemalloc.so.*"
# tcmalloc
find /usr/lib -name "libtcmalloc.so.*"LD_PRELOAD=/path/to/library mariadbdsystemctl status mariadb |grep LoadedEnvironment=LD_PRELOAD=<path-to-library>[Service]
Environment=LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libjemalloc.so.2systemctl daemon-reload
systemctl restart mariadbENV LD_PRELOAD=<path-to-library># jemalloc
docker exec -ti <container-name> find /usr/lib -name "libjemalloc.so.*"
# tcmalloc
docker exec -ti <container-name> find /usr/lib -name "libtcmalloc.so.*"docker run -P -d --name mariadb --env LD_PRELOAD="/usr/lib/x86_64-linux-gnu/libjemalloc.so.2" --env MARIADB_ROOT_PASSWORD=Password123! mariadb:latestMALLOC_CONF=prof_leak:true,lg_prof_sample:0,prof_final:true \
LD_PRELOAD=${JEMALLOC_PATH}/lib/libjemalloc.so.2 path-to-mariadbd<jemalloc>: Leak summary: 267184 bytes, 473 objects, 20 contexts
<jemalloc>: Run jeprof on "jeprof.19678.0.f.heap" for leak detailjeprof --show_bytes path-to-mariadbd jeprof.19678.0.f.heapjeprof --show_bytes --pdf path-to-mariadbd jeprof.19678.0.f.heap > /tmp/mariadbd.pdfCompile MariaDB Server with extra modules and options. This section details how to customize your build from source, enabling specific features or optimizations for your deployment.