Upgrading mariadb when managed by Nextcloud

Hi all,

I’ve been running my NixOS server with the Nextcloud module for a couple of weeks now. I allowed Nextcloud to create a mariadb database locally, I notice the update from 23.05 to 23.11 will see a reasonable jump for mariadb versions.

I can find info regarding upgrading between version for mariadb on the internet , but I’m not sure how it works when created and managed by Nextcloud in NixOS ?

Does the database version get fixed with each nextcloud version ? How would you upgrade between major versions ?

Thanks for any tips and advice

I’m more used to postgresql, but I expect this to be similar for mariadb as well. The idea is to upgrade the database like you would do without NixOs, knowing that by default the data is in /var/lib/mysql. You can follow instructions in https://mariadb.com/kb/en/upgrading-between-major-mariadb-versions/, but basically it’s a matter of doing a backup in case, and run mariadb-upgrade once mariadb has been updated.

You can also check NixOS 23.11 manual | Nix & NixOS

1 Like

Thanks for this, this confirms what I thought I had to do and although created locally by Nextcloud it’s still managed as mariadb server would be.

so do database dump, stop server with systemctl, rebuild nixos on new channel version mariadb-upgrade and then start database server again

for others who need help, this is what I did to upgrade to NixOS 23.11 and with the Mariadb upgrade to 10.11.6.

although I should note that 10.11 is not a recommended version for Nextcloud in the system requirements docs at the moment however I tested in a VM and it worked perfectly

also don’t copy and paste commands blindly understand what they do before attempting

sudo -i nextcloud-occ maintenance:mode --on  ## put Nextcloud into maintenance mode 

sudo -u nextcloud mariadb-dump --single-transaction -h localhost -u nextcloud nextcloud > /home/user/nextcloud-sqlbkp_`date +"%Y%m%d"`.bak     ## backup Nextcloud database

sudo nix-channel --list    ## check NixOS channels currently subscribed to 
sudo nix-channel --add https://channels.nixos.org/nixos-23.11 nixos  ## subscribe to 23.11 channel 

sudo systemctl stop mysql    ## stop MariaDB
sudo nixos-rebuild boot --upgrade   ##upgrade NixOS but with boot option not switch 
sudo reboot

sudo systemctl status mysql.service   ## check MariaDB is running 
journalctl -r | grep mysql  ## check errors are only for tables positions   

## for example  [ERROR] Incorrect definition of table mysql.column_stats: expected column 'histogram' at position 10 to have type longblob, found type varbinary(255)

sudo mariadb-upgrade    ## Fix Table issues
sudo systemctl restart mysql.service   ## restart MariaDB

sudo -i nextcloud-occ maintenance:mode --off   ## disable Nextcloud Maintenance mode
journalctl -r | grep mysql  ## check table errors are gone 

##check Nextcloud is working as expected.

thankyou @tobiasBora for your help with this issue

2 Likes