Details
-
Bug
-
Status: Closed (View Workflow)
-
Minor
-
Resolution: Fixed
-
5.5.46, 10.0.22, 10.1.8
-
None
-
Debian
Description
I recently experienced a slow MariaDB upgrade/migration from MySQL 5.5 to MariaDB 5.5, after the server has been stopped it took maybe one or two minutes before starting the new one.
A process doing a "chown mysql -R /var/lib/mysql" was runing for quite a long time.
This particular server has about 350000 files on its datadir, while its far from being the best practice its not easy to change that (its a shared hosting server).
Replacing the line on "mariadb-server-*.postinst" :
chown -R mysql $mysql_datadir
|
With something like (there is probably a better alternative) :
find /var/lib/mysql/ ! -uid $(id -u mysql) -print0 |xargs -0 -r chown mysql
|
It seems to be marginally slower (less than 1/100th of a second on my tests) on small directories but faster on directories with many files on it (about 20-40% faster on a directory with only 25k files on a software raid1 with 2* 7200k HDDs).
I did some better testings on the same system with 850,000 unique files on a directory (3.3G of space) located on an ext4 partition and all files are already owned by "mysql" (or the target user).
It takes between 1min30s and 1min40s to run the classic "chown -R" while the "find" variant only takes around 1.8 seconds, which is significantly faster.
I did repeat the test multiple times and got a similar result every times.
Having only one file owned by a different owner (for example "debian-10.0.flag" owned by root) on the folder wont make an significant difference.
The main drawback of the "find" alternative, is that it will be slower if an important number of files in the folder are owned by a different user than "mysql" (or the target one).
This case should not be a common one as by default files are created by "mysqld" using the "mysql" user.
Using "find" and "xargs" would require to add a dependency to the "findutils" package (both files are in it) but its possible to stick to the old behavior in case the package is not present on the system.