I'm not sure if this will come up often, but I couldn't find any guidance so maybe my experience will be helpful for someone!
After an in-place 22.04 to 24.04 upgrade (enhance 12.26.6), the control panel's databases (orchd and authd) stayed on PostgreSQL 14 on port 5432. Ubuntu also creates an empty 16/main cluster on 5433.
This is the process I followed to upgrade successfully, use at your own risk etc:
1. Back up
2. Stop the panel
sudo systemctl stop orchd appcd
Warning: cPFence restarted orchd for me within a minute so you might need to disable it temporarily.
3. Remove the empty 16 cluster
pg_upgradecluster refuses to run if 16/main already exists. Check it holds only postgres, template0 and template1 first:
sudo -u postgres psql -p 5433 -c '\l'
sudo pg_dropcluster --stop 16 main
4. Upgrade
sudo pg_upgradecluster -v 16 14 main
sudo -u postgres vacuumdb -p 5432 --all --analyze-in-stages
Apparently 24.04 ships a newer glibc, which changes text sort order, and a dump and restore rebuilds every index under it. Afterwards 16 runs on 5432, and 14 sits stopped on 5433.
5. Start and check
sudo systemctl start orchd appcd filerd
pg_lsclusters
sudo grep -E 'ERROR|PANIC' /var/log/postgresql/postgresql-16-main.log
Log in to the panel and save a small change. You don't need a GRANT on the public schema: orchd's existing grant carries over in the dump. You may see ui_preferences: db error: Record not found in orchd's journal when you log in. It's harmless and only means that login has never saved any UI preferences.
6. Clean up (later)
Once backups have run cleanly:
sudo pg_dropcluster 14 main
sudo apt purge postgresql-14 postgresql-client-14