Nextcloud failed to run since recent update

I am using nixos with flake.
I updated the nixos from 23.11 to 24.05 at the beginning of this month, and after that I also upgraded services.nextcloud.package from pkgs.nextcloud28 to pkgs.nextcloud29, and the machine rebooted and nextcloud worked successfully.

I haven’t touch any other nextcloud related config since then. However nextcloud cannot be started recently after an update.

This is some of the related systemd logs

systemd[1]: Starting nextcloud-setup.service...
nextcloud-setup-start[56814]: WARNING:  database "nextcloud" has a collation version mismatch
nextcloud-setup-start[56814]: DETAIL:  The database was created using collation version 2.38, but the operating system provides version 2.39.
nextcloud-setup-start[56814]: HINT:  Rebuild all objects in this database that use the default collation and run ALTER DATABASE nextcloud REFRESH COLLATION VERSION, or build PostgreSQL with the right library version.
nextcloud-setup-start[56814]: An unhandled exception has been thrown:
nextcloud-setup-start[56814]: OCP\HintException: [0]: Downgrading is not supported and is likely to cause unpredictable issues (from 29.0.2.2 to 29.0.1.1) ()

This is the error message shown when I access nextcloud on browser:

Downgrading is not supported and is likely to cause unpredictable issues (from 29.0.2.2 to 29.0.1.1) 

I think this github issue maybe related.

I kept system.stateVersion = "23.11" unchanged. Am I doing something wrong?
What should I do now?
Thanks for your help!

Oops, it is not just nextcloud, but also some other postgres related services:

postgres[59550]: [59550] WARNING:  database "onlyoffice" has a collation version mismatch
postgres[59550]: [59550] DETAIL:  The database was created using collation version 2.38, but the operating system provides version 2.39.
postgres[59550]: [59550] HINT:  Rebuild all objects in this database that use the default collation and run ALTER DATABASE onlyoffice REFRESH COLLATION VERSION, or build PostgreSQL with the right library version.
postgres[59552]: [59552] WARNING:  database "nextcloud" has a collation version mismatch
postgres[59552]: [59552] DETAIL:  The database was created using collation version 2.38, but the operating system provides version 2.39.
postgres[59552]: [59552] HINT:  Rebuild all objects in this database that use the default collation and run ALTER DATABASE nextcloud REFRESH COLLATION VERSION, or build PostgreSQL with the right library version.
postgres[59559]: [59559] WARNING:  database "template1" has a collation version mismatch
postgres[59559]: [59559] DETAIL:  The database was created using collation version 2.38, but the operating system provides version 2.39.
postgres[59559]: [59559] HINT:  Rebuild all objects in this database that use the default collation and run ALTER DATABASE template1 REFRESH COLLATION VERSION, or build PostgreSQL with the right library version.
postgres[59563]: [59563] WARNING:  database "postgres" has a collation version mismatch
postgres[59563]: [59563] DETAIL:  The database was created using collation version 2.38, but the operating system provides version 2.39.
postgres[59563]: [59563] HINT:  Rebuild all objects in this database that use the default collation and run ALTER DATABASE postgres REFRESH COLLATION VERSION, or build PostgreSQL with the right library version.
......

I don’t even know what collation version 2.38 is.
Is the step in HINT safe?

Collation version corresponds to the glibc version (it was bumped to 2.39 in 24.05, this happens on each release with a glibc bump btw!)

fwiw this is just a warning, you identified the error correctly already:

Downgrading is not supported and is likely to cause unpredictable issues (from 29.0.2.2 to 29.0.1.1) 

My guess is that the nextcloud29 bump landed on 23.11 faster than on 24.05 and thus it thinks there’s a downgrade.
The 24.05 backported should’ve hit the channel by now (https://nixpk.gs/pr-tracker.html?pr=318112), so the issue should go away by updating your nix channel (or flake input).

For the postgresql thing, see PostgreSQL: Documentation: 16: ALTER COLLATION

Updating the flake input solve the issue!
Thank you very much!