On Debian, the mariadb_upgrade process is run at every start/reboot of the mariadb-server.
This is problematic because:
most of the time it's not needed;
if maria_upgrade has to be run, as in case of a major upgrade, then check and possible fix of tables can take from a few seconds to 20-30 seconds (normally) but potentially much longer if there is was a change in a character collation;
If during this time another maria_upgrade is run then it is very likely that mariadb_upgrade will hang because of unexpected conflicts. This is because maria_upgrade was not designed to be run in parallel (should now be fixed by MDEV-27279);
If anyone else connects to mysqld/mariadbd during maria_upgrade, bad things can happen as the tables are not up to date for the system. The possible problems are hangs or wrong data from selects or errors from table updates (as the indexes may not be up to date).
Here are some questions summarized from MDEV-27068:
how to integrate this in a many packages upgrade scenario?
what is the right moment to run the mariadb_upgrade (post-install script, startup/restart), if needed?
should we split system tables upgrade (quick) and the rest of the tables upgrade (can be very long)?
is this feasible with systemd directives (man systemd.directives) or should a script handle alone the whole process?
what about sysv init?
Attachments
Issue Links
is part of
MDEV-27068running mariadb-upgrade on mariadb server with other user make it hangs forever
Closed
relates to
MDEV-27606change debian packaging to not run mariadb-upgrade at the same time as anything
I don't quite get why does the title include "Fixing debian...". How MariaDB does in-place upgrades for its data has nothing to do with distribution and packaging of files in distros, let alone anything specific to Debian?
MariaDB should not rely on deb nor rpm pre/post scripts to ensure its data files are in correct format (=upgraded). In the most simple scenario deb/rpm is just a way to download files and unpack them on the system with a couple of integrations to the distro paths and facilities. There is no guarantee for example that the MariaDB Server would be running nor restarted during the deb/rpm pre/post script execution.
The most sane solution is that the mariadbd binary itself checks that its data is on correct format, and if not, upgrades it or does whatever is needed. There should be just one way for it to do it and it should not be specific to any distro type or distro version. If mariadbd can't do it independently but needs a separate script mariadb-upgrade, then injecting a call to mariadb-upgrade in systemd and SysV init scripts is probably the best solution, as that is the way systems typically run mariadbd instead of calling it directly. You seem to be on that path already. If you choose to use PreExec or Exec is just a systemd implementation detail.
Otto Kekäläinen
added a comment - I don't quite get why does the title include "Fixing debian...". How MariaDB does in-place upgrades for its data has nothing to do with distribution and packaging of files in distros, let alone anything specific to Debian?
MariaDB should not rely on deb nor rpm pre/post scripts to ensure its data files are in correct format (=upgraded). In the most simple scenario deb/rpm is just a way to download files and unpack them on the system with a couple of integrations to the distro paths and facilities. There is no guarantee for example that the MariaDB Server would be running nor restarted during the deb/rpm pre/post script execution.
The most sane solution is that the mariadbd binary itself checks that its data is on correct format, and if not, upgrades it or does whatever is needed. There should be just one way for it to do it and it should not be specific to any distro type or distro version. If mariadbd can't do it independently but needs a separate script mariadb-upgrade, then injecting a call to mariadb-upgrade in systemd and SysV init scripts is probably the best solution, as that is the way systems typically run mariadbd instead of calling it directly. You seem to be on that path already. If you choose to use PreExec or Exec is just a systemd implementation detail.
On Debian, the mariadb_upgrade process is run at every start/reboot of the mariadb-server.
When does other distros or Windows run mariadb-upgrade if not at start of the server? As stated in MDEV-27606, mariadb-upgrade runs as part of the systemd/init.d scripts and are largely the same across all distros.
Ideally the mariadbd would itself keep track of its data directory and upgrade it when needed, and not rely on external bash scripts to do it for it, nor even have the possibility to run new mariadbd version without having the datadir also upgraded.
Otto Kekäläinen
added a comment - faust
On Debian, the mariadb_upgrade process is run at every start/reboot of the mariadb-server.
When does other distros or Windows run mariadb-upgrade if not at start of the server? As stated in MDEV-27606 , mariadb-upgrade runs as part of the systemd/init.d scripts and are largely the same across all distros.
In native Fedora they made a custom script to check for the need of running mariadb-upgrade, but it is still run as part of the server startup: https://src.fedoraproject.org/rpms/mariadb/blob/rawhide/f/mariadb-check-upgrade.sh
Ideally the mariadbd would itself keep track of its data directory and upgrade it when needed, and not rely on external bash scripts to do it for it, nor even have the possibility to run new mariadbd version without having the datadir also upgraded.
Discussed plan with faust. Finalizing the details will happen next week, but for record:
We will use systemd to automate the process where possible.
(in the future, we will have a way to --enable-networking, much like we have --skip-networking for similar automation in Docker Files)
We will use mariadb-upgrade's --check-if-upgrade-is-needed flag
check-if-upgrade-is-needed only looks at the datadir for mysql_upgrade_info file and returns 1 if there is a need to upgrade, otherwise 0. This is a fast operation, but requires read access on the datadir.
We can run --check-if-upgrade-is-needed as part of PreExec step of SystemD, provided we can save the result for the actual Exec step.
For the Exec step, we will start the server and only run mariadb-upgrade if the PreExec step returned 1.
Vicențiu Ciorbaru
added a comment - Discussed plan with faust . Finalizing the details will happen next week, but for record:
We will use systemd to automate the process where possible.
(in the future, we will have a way to --enable-networking, much like we have --skip-networking for similar automation in Docker Files)
We will use mariadb-upgrade's --check-if-upgrade-is-needed flag
check-if-upgrade-is-needed only looks at the datadir for mysql_upgrade_info file and returns 1 if there is a need to upgrade, otherwise 0. This is a fast operation, but requires read access on the datadir.
We can run --check-if-upgrade-is-needed as part of PreExec step of SystemD, provided we can save the result for the actual Exec step.
For the Exec step, we will start the server and only run mariadb-upgrade if the PreExec step returned 1.
Remember the main thread starting this this proposal ?
The conclusion was that mariadb-upgrade is only required for major and minor upgrades, but not for patchlevel upgrades.
So, you shouldn't need to run mariadb-upgrade for patchlevel upgrades. At all.
Sergei Golubchik
added a comment - Remember the main thread starting this this proposal ?
The conclusion was that mariadb-upgrade is only required for major and minor upgrades, but not for patchlevel upgrades.
So, you shouldn't need to run mariadb-upgrade for patchlevel upgrades. At all.
Dec 11 13:19:00 bark strace[184268]: information_schema
Dec 11 13:19:00 bark strace[184268]: performance_schema
Dec 11 13:19:00 bark strace[184268]: sys
Dec 11 13:19:00 bark strace[184268]: sys.sys_config OK
Dec 11 13:19:00 bark strace[184268]: test
Dec 11 13:19:00 bark strace[184268]: Phase 7/8: uninstalling plugins
Dec 11 13:19:00 bark strace[184268]: Phase 8/8: Running 'FLUSH PRIVILEGES'
Dec 11 13:19:00 bark strace[184268]: OK
Dec 11 13:19:00 bark systemd[1]: mariadb-upgrade.service: Deactivated successfully.
Dec 11 13:19:00 bark systemd[1]: Finished mariadb-upgrade.service - MariaDB Upgrade.
(note the strace here for some reason when strace was placed in the Exec*= it worked when without it was doing a EPERM on the mariadb socket. I'm sure this is solveable if the concept is ok)
To resolve MDEV-27606, SET GLOBAL read_only into the mariadb-upgrade execution and clearing after execution?
Daniel Black
added a comment - As a concept:
mariadb-upgrade.service
[Unit]
Description=MariaDB Upgrade
Documentation=man:mariadb-upgrade(1)
Documentation=https://mariadb.com/kb/en/library/systemd/
Requires=mariadb.service
[Service]
Type=oneshot
ExecCondition=/usr/bin/mariadb-upgrade --check-if-upgrade-is-needed
ExecStart=/usr/bin/mariadb-upgrade --verbose
PrivateTmp=yes
systemctl status mariadb-upgrade.service
â—‹ mariadb-upgrade.service - MariaDB Upgrade
Loaded: loaded (/etc/systemd/system/mariadb-upgrade.service; static)
Drop-In: /usr/lib/systemd/system/service.d
└─10-timeout-abort.conf, 50-keep-warm.conf
Active: inactive (dead)
Docs: man:mariadb-upgrade(1)
https://mariadb.com/kb/en/library/systemd/
Dec 11 13:19:00 bark strace[184268]: information_schema
Dec 11 13:19:00 bark strace[184268]: performance_schema
Dec 11 13:19:00 bark strace[184268]: sys
Dec 11 13:19:00 bark strace[184268]: sys.sys_config OK
Dec 11 13:19:00 bark strace[184268]: test
Dec 11 13:19:00 bark strace[184268]: Phase 7/8: uninstalling plugins
Dec 11 13:19:00 bark strace[184268]: Phase 8/8: Running 'FLUSH PRIVILEGES'
Dec 11 13:19:00 bark strace[184268]: OK
Dec 11 13:19:00 bark systemd[1]: mariadb-upgrade.service: Deactivated successfully.
Dec 11 13:19:00 bark systemd[1]: Finished mariadb-upgrade.service - MariaDB Upgrade.
(note the strace here for some reason when strace was placed in the Exec*= it worked when without it was doing a EPERM on the mariadb socket. I'm sure this is solveable if the concept is ok)
To resolve MDEV-27606 , SET GLOBAL read_only into the mariadb-upgrade execution and clearing after execution?
People
Unassigned
Faustin Lammler
Votes:
0Vote for this issue
Watchers:
7Start watching this issue
Dates
Created:
Updated:
Git Integration
Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.
{"report":{"fcp":759.8000001907349,"ttfb":219.80000019073486,"pageVisibility":"visible","entityId":107150,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":16,"apdex":1,"journeyId":"67900afa-e008-45c7-961a-63cf72618f74","navigationType":0,"readyForUser":802.3000001907349,"redirectCount":0,"resourceLoadedEnd":303.30000019073486,"resourceLoadedStart":227.30000019073486,"resourceTiming":[{"duration":3,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2bu7/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":227.30000019073486,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":227.30000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":230.30000019073486,"responseStart":0,"secureConnectionStart":0},{"duration":3.1999998092651367,"initiatorType":"link","name":"https://jira.mariadb.org/s/7ebd35e77e471bc30ff0eba799ebc151-CDN/lu2bu7/820016/12ta74/8679b4946efa1a0bb029a3a22206fb5d/_/download/contextbatch/css/jira.browse.project,project.issue.navigator,jira.view.issue,jira.general,jira.global,atl.general,-_super/batch.css?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&slack-enabled=true","startTime":227.5,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":227.5,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":230.69999980926514,"responseStart":0,"secureConnectionStart":0},{"duration":62.70000076293945,"initiatorType":"script","name":"https://jira.mariadb.org/s/fbf975c0cce4b1abf04784eeae9ba1f4-CDN/lu2bu7/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":227.5999994277954,"connectEnd":227.5999994277954,"connectStart":227.5999994277954,"domainLookupEnd":227.5999994277954,"domainLookupStart":227.5999994277954,"fetchStart":227.5999994277954,"redirectEnd":0,"redirectStart":0,"requestStart":233.39999961853027,"responseEnd":290.30000019073486,"responseStart":246.69999980926514,"secureConnectionStart":227.5999994277954},{"duration":23,"initiatorType":"script","name":"https://jira.mariadb.org/s/94c15bff32baef80f4096a08aceae8bc-CDN/lu2bu7/820016/12ta74/c92c0caa9a024ae85b0ebdbed7fb4bd7/_/download/contextbatch/js/atl.global,-_super/batch.js?locale=en","startTime":227.69999980926514,"connectEnd":227.69999980926514,"connectStart":227.69999980926514,"domainLookupEnd":227.69999980926514,"domainLookupStart":227.69999980926514,"fetchStart":227.69999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":235,"responseEnd":250.69999980926514,"responseStart":250.0999994277954,"secureConnectionStart":227.69999980926514},{"duration":75.60000038146973,"initiatorType":"script","name":"https://jira.mariadb.org/s/099b33461394b8015fc36c0a4b96e19f-CDN/lu2bu7/820016/12ta74/8679b4946efa1a0bb029a3a22206fb5d/_/download/contextbatch/js/jira.browse.project,project.issue.navigator,jira.view.issue,jira.general,jira.global,atl.general,-_super/batch.js?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&locale=en&slack-enabled=true","startTime":227.69999980926514,"connectEnd":227.69999980926514,"connectStart":227.69999980926514,"domainLookupEnd":227.69999980926514,"domainLookupStart":227.69999980926514,"fetchStart":227.69999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":233.89999961853027,"responseEnd":303.30000019073486,"responseStart":250.80000019073486,"secureConnectionStart":227.69999980926514},{"duration":36.29999923706055,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bu7/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-en/jira.webresources:calendar-en.js","startTime":227.80000019073486,"connectEnd":227.80000019073486,"connectStart":227.80000019073486,"domainLookupEnd":227.80000019073486,"domainLookupStart":227.80000019073486,"fetchStart":227.80000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":235.89999961853027,"responseEnd":264.0999994277954,"responseStart":263.5999994277954,"secureConnectionStart":227.80000019073486},{"duration":50.30000019073486,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bu7/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-localisation-moment/jira.webresources:calendar-localisation-moment.js","startTime":227.89999961853027,"connectEnd":227.89999961853027,"connectStart":227.89999961853027,"domainLookupEnd":227.89999961853027,"domainLookupStart":227.89999961853027,"fetchStart":227.89999961853027,"redirectEnd":0,"redirectStart":0,"requestStart":237.5999994277954,"responseEnd":278.19999980926514,"responseStart":277.5999994277954,"secureConnectionStart":227.89999961853027},{"duration":8.300000190734863,"initiatorType":"link","name":"https://jira.mariadb.org/s/b04b06a02d1959df322d9cded3aeecc1-CDN/lu2bu7/820016/12ta74/a2ff6aa845ffc9a1d22fe23d9ee791fc/_/download/contextbatch/css/jira.global.look-and-feel,-_super/batch.css","startTime":228,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":228,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":236.30000019073486,"responseStart":0,"secureConnectionStart":0},{"duration":10.199999809265137,"initiatorType":"link","name":"https://jira.mariadb.org/s/3ac36323ba5e4eb0af2aa7ac7211b4bb-CDN/lu2bu7/820016/12ta74/d176f0986478cc64f24226b3d20c140d/_/download/contextbatch/css/com.atlassian.jira.projects.sidebar.init,-_super,-project.issue.navigator,-jira.view.issue/batch.css?jira.create.linked.issue=true","startTime":228.19999980926514,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":228.19999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":238.39999961853027,"responseStart":0,"secureConnectionStart":0},{"duration":49.39999961853027,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":228.19999980926514,"connectEnd":228.19999980926514,"connectStart":228.19999980926514,"domainLookupEnd":228.19999980926514,"domainLookupStart":228.19999980926514,"fetchStart":228.19999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":238.69999980926514,"responseEnd":277.5999994277954,"responseStart":276.8999996185303,"secureConnectionStart":228.19999980926514},{"duration":52.19999980926514,"initiatorType":"script","name":"https://jira.mariadb.org/s/3339d87fa2538a859872f2df449bf8d0-CDN/lu2bu7/820016/12ta74/d176f0986478cc64f24226b3d20c140d/_/download/contextbatch/js/com.atlassian.jira.projects.sidebar.init,-_super,-project.issue.navigator,-jira.view.issue/batch.js?jira.create.linked.issue=true&locale=en","startTime":228.30000019073486,"connectEnd":228.30000019073486,"connectStart":228.30000019073486,"domainLookupEnd":228.30000019073486,"domainLookupStart":228.30000019073486,"fetchStart":228.30000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":240,"responseEnd":280.5,"responseStart":279.8999996185303,"secureConnectionStart":228.30000019073486},{"duration":17.800000190734863,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bu7/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-js/jira.webresources:bigpipe-js.js","startTime":240.5999994277954,"connectEnd":247.19999980926514,"connectStart":247.19999980926514,"domainLookupEnd":247.19999980926514,"domainLookupStart":247.19999980926514,"fetchStart":240.5999994277954,"redirectEnd":0,"redirectStart":0,"requestStart":247.80000019073486,"responseEnd":258.3999996185303,"responseStart":257.5999994277954,"secureConnectionStart":247.19999980926514},{"duration":15.700000762939453,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bu7/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-init/jira.webresources:bigpipe-init.js","startTime":244.0999994277954,"connectEnd":244.0999994277954,"connectStart":244.0999994277954,"domainLookupEnd":244.0999994277954,"domainLookupStart":244.0999994277954,"fetchStart":244.0999994277954,"redirectEnd":0,"redirectStart":0,"requestStart":248,"responseEnd":259.80000019073486,"responseStart":258.5999994277954,"secureConnectionStart":244.0999994277954},{"duration":161.5999994277954,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":513.5,"connectEnd":513.5,"connectStart":513.5,"domainLookupEnd":513.5,"domainLookupStart":513.5,"fetchStart":513.5,"redirectEnd":0,"redirectStart":0,"requestStart":642.5,"responseEnd":675.0999994277954,"responseStart":674.0999994277954,"secureConnectionStart":513.5},{"duration":66.69999980926514,"initiatorType":"script","name":"https://www.google-analytics.com/analytics.js","startTime":726.8000001907349,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":726.8000001907349,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":793.5,"responseStart":0,"secureConnectionStart":0},{"duration":151.9000005722046,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":741.5999994277954,"connectEnd":741.5999994277954,"connectStart":741.5999994277954,"domainLookupEnd":741.5999994277954,"domainLookupStart":741.5999994277954,"fetchStart":741.5999994277954,"redirectEnd":0,"redirectStart":0,"requestStart":861.3000001907349,"responseEnd":893.5,"responseStart":892.6999998092651,"secureConnectionStart":741.5999994277954}],"fetchStart":0,"domainLookupStart":32,"domainLookupEnd":45,"connectStart":45,"connectEnd":66,"secureConnectionStart":54,"requestStart":66,"responseStart":219,"responseEnd":243,"domLoading":223,"domInteractive":865,"domContentLoadedEventStart":871,"domContentLoadedEventEnd":912,"domComplete":1231,"loadEventStart":1231,"loadEventEnd":1231,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":834.8999996185303},{"name":"bigPipe.sidebar-id.end","time":835.5999994277954},{"name":"bigPipe.activity-panel-pipe-id.start","time":835.8999996185303},{"name":"bigPipe.activity-panel-pipe-id.end","time":838.5999994277954},{"name":"activityTabFullyLoaded","time":936.8000001907349}],"measures":[],"correlationId":"f2bf9e3ff0aa65","effectiveType":"4g","downlink":9.5,"rtt":0,"serverDuration":103,"dbReadsTimeInMs":27,"dbConnsTimeInMs":37,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}
I don't quite get why does the title include "Fixing debian...". How MariaDB does in-place upgrades for its data has nothing to do with distribution and packaging of files in distros, let alone anything specific to Debian?
MariaDB should not rely on deb nor rpm pre/post scripts to ensure its data files are in correct format (=upgraded). In the most simple scenario deb/rpm is just a way to download files and unpack them on the system with a couple of integrations to the distro paths and facilities. There is no guarantee for example that the MariaDB Server would be running nor restarted during the deb/rpm pre/post script execution.
The most sane solution is that the mariadbd binary itself checks that its data is on correct format, and if not, upgrades it or does whatever is needed. There should be just one way for it to do it and it should not be specific to any distro type or distro version. If mariadbd can't do it independently but needs a separate script mariadb-upgrade, then injecting a call to mariadb-upgrade in systemd and SysV init scripts is probably the best solution, as that is the way systems typically run mariadbd instead of calling it directly. You seem to be on that path already. If you choose to use PreExec or Exec is just a systemd implementation detail.