Guidelines

This site is for tech Q&A. Please keep your posts focused on the subject at hand.

Ask one question at a time. Don't conflate multiple problems into a single question.

Make sure to include all relevant information in your posts. Try to avoid linking to external sites.

Links to documentation are fine, but in addition you should also quote the relevant parts in your posts.

0 votes
416 views
416 views

After a failed attempt to install PostgreSQL the package was left in an incomplete state:

root@server:~# dpkg -l | grep postgresql-14
iF  postgresql-14                  14.6-1.pgdg22.04+1  ...

Neither could the installation be forced:

root@server:~# apt-get install -f
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following package was automatically installed and is no longer required:
  postgresql-client-11
Use 'apt autoremove' to remove it.
0 upgraded, 0 newly installed, 0 to remove and 82 not upgraded.
1 not fully installed or removed.
After this operation, 0 B of additional disk space will be used.
Setting up postgresql-14 (14.6-1.pgdg22.04+1) ...
Failed to connect to bus: No such file or directory
dpkg: error processing package postgresql-14 (--configure):
 installed postgresql-14 package post-installation script subprocess returned error exit status 1
Errors were encountered while processing:
 postgresql-14
E: Sub-process /usr/bin/dpkg returned an error code (1)

nor could the package be removed:

root@server:~# apt-get remove --auto-remove --purge postgresql-14
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages will be REMOVED:
  postgresql-14* postgresql-client-11*
0 upgraded, 0 newly installed, 2 to remove and 82 not upgraded.
1 not fully installed or removed.
After this operation, 58.1 MB disk space will be freed.
(Reading database ... 51465 files and directories currently installed.)
Removing postgresql-14 (14.6-1.pgdg22.04+1) ...
Failed to connect to bus: No such file or directory
dpkg: error processing package postgresql-14 (--remove):
 installed postgresql-14 package pre-removal script subprocess returned error exit status 1
dpkg: too many errors, stopping
Errors were encountered while processing:
 postgresql-14
Processing was halted because there were too many errors.
E: Sub-process /usr/bin/dpkg returned an error code (1)

How do I force removal of a broken package without re-installing the entire system?

in Sysadmin
by (115)
2 19 33
edit history

Please log in or register to answer this question.

1 Answer

0 votes
 

First thing you could try (after normal removal fails) is to force removal with dpkg:

dpkg --remove --force-remove-reinstreq postgresql-14

If that also fails you have to dig deeper. According to the error messages the problem is with the maintainer scripts of the package. These (among other things) are unpacked to /var/lib/dpkg/info when a package is installed and get invoked from that directory.

If you want to debug the issue, check the content of the respective maintainer script (pre-removal script for your PostgreSQL package for instance would be postgresql-14.prerm) and follow the trail from there, i.e. check what commands the script invokes and/or what other files it sources to pinpoint what exactly is failing¹.

If you just want the package removed, simply replace the code after the shebang with an exit 0

#!/bin/sh
exit 0

and then re-run package removal

apt-get remove --auto-remove --purge postgresql-14

¹ TWIMC: In our case the root cause turned out to be an artifact from replacing Systemd with a different init (s6). PostgreSQL maintainer scripts apparently distinguish between Systemd and other inits by the presence of a directory /run/systemd/system, which had not been removed after replacing the init on the system in question. After manually removing that directory the package could be (un)installed normally.

by (115)
2 19 33
edit history
...