升级Lubuntu到24.04时因postgresql-12报错,手动删除相关文件后系统损坏求助
别着急,我来帮你一步步解决这个问题。先梳理下你遇到的完整情况:
首先你收到了Lubuntu 24.04的升级提示,但执行升级时弹出了以下错误:
Error when trying to upgrade to 24.04
Could not determine the upgradeAn unresolvable problem occurred while calculating the upgrade.
The package 'postgresql-12' is marked for removal but it is in the removal deny list.
To prevent data loss, postgresql packages are not removed automatically during the upgrade. If you are certain you no longer need postgresql-12, you can manually remove it and try the upgrade again.
If none of this applies, then please report this bug using the command 'ubuntu-bug ubuntu-release-upgrader-core' in a terminal. If you want to investigate this yourself the log files in '/var/log/dist-upgrade' will contain details about the upgrade. Specifically, look at 'main.log' and 'apt.log'.
看到提示后,你手动删除了PostgreSQL的相关目录:
james@shire $ sudo rm -R /usr/lib/postgresql james@shire $ sudo rm -R /etc/postgresql james@shire $ sudo rm -R /usr/share/postgresql
现在系统出现损坏,咱们可以按以下步骤修复:
第一步:修复APT依赖与系统数据库
手动删除文件会导致APT的包数据库和实际文件系统不一致,这是系统损坏的核心原因,先修复这个:
- 打开终端,执行命令强制重新配置所有已安装的包:
sudo dpkg --configure -a - 接着修复损坏的依赖关系:
sudo apt --fix-broken install
第二步:补全PostgreSQL相关组件(按需操作)
如果之后你还需要使用PostgreSQL,或者只是为了让系统包状态恢复正常,可以重新安装对应组件:
- 如果PostgreSQL 12在当前源中还能获取,直接安装:
sudo apt install postgresql-12 - 要是12版本已经不在24.04的官方源里了,可以安装系统默认支持的新版本(比如14或16):
sudo apt install postgresql
第三步:重新尝试系统升级
等依赖修复完成、包状态正常后,重新启动升级流程:
- 先更新软件源和已安装包到最新状态:
sudo apt update && sudo apt upgrade -y - 启动官方升级工具:
sudo do-release-upgrade
额外排查建议
如果升级仍然失败,一定要去查看升级日志文件,里面会有更详细的错误细节,帮助定位问题:
- 主升级日志:
/var/log/dist-upgrade/main.log - APT操作日志:
/var/log/dist-upgrade/apt.log
可以用less命令查看(按q退出查看):
less /var/log/dist-upgrade/main.log
备注:内容来源于stack exchange,提问作者James Cobb

