Sometimes you may end up with apps that are not fully installed or uninstalled in univention and can linger and cause issues when trying to uninstall, update or re-install the apps. This post will guide you on how to manually clean up UCS apps. As always recommended when making changes, make sure that you have a snapshot or backup of the Univention infrastructure before following these steps in case you need to revert.
Log in to your UCS server as administrator via shell and change to a super user be executing su -i command.
Run the command univention-app remove nextcloud (or whatever app is the problematic one). Once this is done, you will see that the App has been removed from the UCS portal. You will also see the following message:

Press enter for the uninstaller to run. When the uninstaller completes, we will need to remove the UCR variables, the database entry and the Nextcloud application folder.
Use the following command to remove the Nextcloud application folder.
rm -Rf “/var/lib/univention-appcenter/apps/nextcloud”
Use the following command to remove the UCR variables:
ucr unset
`ucr search --key "^nextcloud" | cut -d ":" -f 1 | grep nextcloud | tr '\n' ' '
Run the following commands to remove the nextcloud database from Postgres:
su -c “psql -c \”drop database nextcloud\”” – postgres
su -c “dropuser \”nextcloud\”” – postgres
rm /etc/postgresql-nextcloud.secret

You can check orphaned databases in Postgres with the following commands:
Enter the command psql -U postgres then \l to list the databases.

After identifying the database name, run the following command to delete the database or simply insert the correct database name into the previous step.
dropdb nextcloud
You can also follow these instruction to clean up or recreate the appcache.
https://help.univention.com/t/problem-univention-app-shows-wrong-information/12517