Dnf remove with keeping dependecies

I while ago i needed to remove an loder version of mariadb. It remove every depen. even the ones that other repos needed, thus these repos where ols removed.

Ho can I tell dnf to leave all dependecies and only remove the packaged that I want to remove?

Base principle: If A does depend on B, then A cannot be installed if B is not installed.

I don’t recall any repo that would depend on something, like MariaDB.
Could you give more details about that transaction (fer example from dnf history info transID)?

I believe the following should do what you need ?

dnf --noautoremove erase mariadb

The original post is too vague; it would be better to see the exact command line output of what it wants to remove. The MariaDB in the official repo should not need any special command to uninstall it.

1 Like

When you tpy dnf remove mariadb you will see wat is removed. There is no need to remove its dependecies because other rpm need them like open dmarc. Had to reinstall this unwatend removed packages.

I know how installing works first dependcies from bottom to top.

just dnf remove mariadb or watever you want to get rid off.

Removing:
MariaDB-client x86_64 10.6.20-1.el9 @mariadb-main 76 M
Removing dependent packages:
MariaDB-server x86_64 10.6.20-1.el9 @mariadb-main 121 M
Removing unused dependencies:
boost-program-options x86_64 1.75.0-8.el9 @appstream 278 k
galera-4 x86_64 26.4.20-1.el9 @mariadb-main 5.5 M
lsof x86_64 4.94.0-3.el9 @baseos 624 k
rsync x86_64 3.2.3-20.el9_5.1 @devel 743 k
socat x86_64 1.7.4.1-6.el9 @appstream 1.1 M

This is now shorter. The removal was 10.5.22.
I dont have it in my logs any more.

The main question was How to avoid deinstalling depencies even dnf thinks thy are unused.

In other words, we are talking about “unused dependencies”.

If I had mariadb installed … found one:

# dnf rm mariadb
Dependencies resolved.
================================================================================
 Package                Arch    Version                   Repository       Size
================================================================================
Removing:
 mariadb                x86_64  3:10.5.22-1.el9_2.alma.1  @appstream   18 M
Removing dependent packages:
 mariadb-server         x86_64  3:10.5.22-1.el9_2.alma.1  @appstream   63 M
Removing unused dependencies:
 mariadb-backup         x86_64  3:10.5.22-1.el9_2.alma.1  @appstream   24 M
 mariadb-common         x86_64  3:10.5.22-1.el9_2.alma.1  @appstream  179 k
 mariadb-errmsg         x86_64  3:10.5.22-1.el9_2.alma.1  @appstream  2.6 M
 mariadb-gssapi-server  x86_64  3:10.5.22-1.el9_2.alma.1  @appstream   20 k
 mariadb-server-utils   x86_64  3:10.5.22-1.el9_2.alma.1  @appstream  801 k
 mysql-selinux          noarch  1.0.10-1.el9              @appstream   50 k
 perl-DBD-MariaDB       x86_64  1.21-16.el9_0             @appstream  383 k
 perl-DBI               x86_64  1.643-9.el9               @appstream  1.9 M
 perl-File-Copy         noarch  2.34-481.el9              @appstream   21 k
 perl-Math-BigInt       noarch  1:1.9998.18-460.el9       @appstream  709 k
 perl-Math-Complex      noarch  1.59-481.el9              @appstream   86 k

Transaction Summary
================================================================================
Remove  13 Packages

Nothing much in that. Granted, I could have “source installed” Perl programs that do need those Perl modules.


The man dnf tells that dnf

removes all packages from the system that were originally installed as dependencies of user-installed packages, but which are no longer required by any such package.

There is interesting term: user-installed

The doc continues to tell that dnf rq --userinstalled (or dnf history userinstalled) shows the user-installed packages. I wonder what does not count as “user”?
Perhaps something like dnf group install Base
(The dnf has all kinds of murky “mark” features, particularly about groups.)


Not even in dnf history ?

Only this:
[root@server5 log]# ll dnf*
-rw-r–r–. 1 root root 665542 Feb 5 16:56 dnf.librepo.log
-rw-r–r–. 1 root root 1048560 Jan 18 10:22 dnf.librepo.log.1
-rw-r–r–. 1 root root 1048438 Dec 17 19:03 dnf.librepo.log.2
-rw-r–r–. 1 root root 887681 Feb 5 16:56 dnf.log
-rw-r–r–. 1 root root 1048530 Jan 22 01:56 dnf.log.1
-rw-r–r–. 1 root root 1048545 Jan 5 03:26 dnf.log.2
-rw-r–r–. 1 root root 1048394 Dec 20 16:02 dnf.log.3
-rw-r–r–. 1 root root 429309 Feb 5 16:56 dnf.rpm.log

Found it:

2024-12-17T20:33:51+0100 SUBDEBUG Erase: MariaDB-server-10.5.22-1.el9.x86_64
2024-12-17T20:33:51+0100 INFO warning: /etc/my.cnf.d/server.cnf saved as /etc/my.cnf.d/server.cnf.rpmsave
2024-12-17T20:33:52+0100 SUBDEBUG Erase: MariaDB-client-10.6.19-1.el9.x86_64
2024-12-17T20:33:52+0100 SUBDEBUG Erase: MariaDB-backup-10.6.19-1.el9.x86_64
2024-12-17T20:33:52+0100 SUBDEBUG Erase: MariaDB-devel-10.6.19-1.el9.x86_64
2024-12-17T20:33:52+0100 SUBDEBUG Erase: galera-4-26.4.19-1.el9.x86_64
2024-12-17T20:33:52+0100 SUBDEBUG Erase: lua-dbi-0.7.4-1.el9.x86_64
2024-12-17T20:33:52+0100 SUBDEBUG Erase: opendmarc-1.4.2-22.el9.x86_64
2024-12-17T20:33:56+0100 INFO Removed “/etc/systemd/system/multi-user.target.wants/opendmarc.service”.
2024-12-17T20:33:56+0100 INFO warning: file /run/opendmarc: remove failed: No such file or directory
2024-12-17T20:33:56+0100 SUBDEBUG Erase: perl-DBD-MySQL-4.050-13.el9.x86_64
2024-12-17T20:33:56+0100 SUBDEBUG Erase: postfix-mysql-2:3.5.25-1.el9.x86_64
2024-12-17T20:33:56+0100 SUBDEBUG Erase: php-snmp-8.2.26-1.el9.remi.x86_64
2024-12-17T20:33:56+0100 SUBDEBUG Erase: net-snmp-1:5.9.1-17.el9.x86_64
2024-12-17T20:33:56+0100 SUBDEBUG Erase: net-snmp-agent-libs-1:5.9.1-17.el9.x86_64
2024-12-17T20:33:57+0100 SUBDEBUG Erase: perl-DBD-MariaDB-1.21-16.el9_0.x86_64
2024-12-17T20:33:57+0100 SUBDEBUG Erase: dovecot-mysql-1:2.3.16-14.el9.x86_64
2024-12-17T20:33:57+0100 SUBDEBUG Erase: MariaDB-shared-10.6.19-1.el9.x86_64
2024-12-17T20:33:57+0100 INFO warning: /etc/my.cnf.d/client.cnf saved as /etc/my.cnf.d/client.cnf.rpmsave
2024-12-17T20:33:57+0100 SUBDEBUG Erase: MariaDB-common-10.6.19-1.el9.x86_64
2024-12-17T20:33:57+0100 SUBDEBUG Erase: libopendmarc-1.4.2-22.el9.x86_64
2024-12-17T20:33:57+0100 SUBDEBUG Erase: perl-Term-ReadLine-1.17-481.el9.noarch
2024-12-17T20:33:57+0100 SUBDEBUG Erase: libspf2-1.2.11-11.20210922git4915c308.el9.x86_64
2024-12-17T20:33:57+0100 SUBDEBUG Erase: net-snmp-libs-1:5.9.1-17.el9.x86_64
2024-12-17T20:33:57+0100 SUBDEBUG Erase: lm_sensors-libs-3.6.0-10.el9.x86_64
2024-12-17T20:33:57+0100 SUBDEBUG Erase: libpq-13.15-1.el9.x86_64
2024-12-17T20:33:57+0100 SUBDEBUG Erase: boost-program-options-1.75.0-8.el9.x86_64
2024-12-17T20:33:57+0100 SUBDEBUG Erase: lsof-4.94.0-3.el9.x86_64
2024-12-17T20:33:57+0100 SUBDEBUG Erase: rsync-3.2.3-20.el9.x86_64
2024-12-17T20:33:57+0100 SUBDEBUG Erase: socat-1.7.4.1-6.el9.x86_64
2024-12-17T20:33:57+0100 SUBDEBUG Erase: libaio-0.3.111-13.el9.x86_64
2024-12-17T20:35:13+0100 INFO — logging initialized —
2024-12-17T20:35:40+0100 INFO — logging initialized —
2024-12-17T20:39:04+0100 INFO — logging initialized —
2024-12-17T20:39:45+0100 INFO — logging initialized —
2024-12-17T20:52:15+0100 INFO — logging initialized —
2024-12-17T20:52:16+0100 INFO — logging initialized —
2024-12-17T20:53:15+0100 INFO — logging initialized —
2024-12-17T20:54:55+0100 INFO — logging initialized —
2024-12-17T20:58:58+0100 INFO — logging initialized —
2024-12-17T21:04:16+0100 INFO — logging initialized —
2024-12-17T21:04:27+0100 SUBDEBUG Upgrade: gstreamer1-plugins-base-1.22.1-3.el9_5.x86_64
2024-12-17T21:04:28+0100 SUBDEBUG Upgraded: gstreamer1-plugins-base-1.22.1-2.el9.x86_64
2024-12-17T21:07:01+0100 INFO — logging initialized —
2024-12-17T21:07:02+0100 INFO — logging initialized —
2024-12-17T21:07:04+0100 INFO — logging initialized —
2024-12-17T21:08:03+0100 INFO — logging initialized —
2024-12-17T21:08:45+0100 SUBDEBUG Installed: MariaDB-shared-10.6.20-1.el9.x86_64
2024-12-17T21:08:45+0100 SUBDEBUG Installed: MariaDB-common-10.6.20-1.el9.x86_64
2024-12-17T21:08:45+0100 SUBDEBUG Installed: libaio-0.3.111-13.el9.x86_64
2024-12-17T21:08:45+0100 SUBDEBUG Installed: MariaDB-client-10.6.20-1.el9.x86_64
2024-12-17T21:08:46+0100 SUBDEBUG Installed: boost-program-options-1.75.0-8.el9.x86_64
2024-12-17T21:08:46+0100 SUBDEBUG Installed: galera-4-26.4.20-1.el9.x86_64
2024-12-17T21:08:46+0100 SUBDEBUG Installed: socat-1.7.4.1-6.el9.x86_64
2024-12-17T21:08:46+0100 SUBDEBUG Installed: rsync-3.2.3-20.el9.x86_64
2024-12-17T21:08:46+0100 SUBDEBUG Installed: lsof-4.94.0-3.el9.x86_64
2024-12-17T21:08:46+0100 SUBDEBUG Installed: MariaDB-server-10.6.20-1.el9.x86_64
2024-12-17T21:08:46+0100 INFO usermod: no changes
2024-12-17T21:09:10+0100 INFO
2024-12-17T21:09:10+0100 SUBDEBUG Installed: MariaDB-backup-10.6.20-1.el9.x86_64
2024-12-17T21:19:57+0100 INFO — logging initialized —
2024-12-17T21:20:03+0100 SUBDEBUG Installed: postfix-mysql-2:3.5.25-1.el9.x86_64
2024-12-17T21:20:15+0100 INFO — logging initialized —
2024-12-17T21:20:20+0100 SUBDEBUG Installed: libpq-13.15-1.el9.x86_64
2024-12-17T21:20:21+0100 SUBDEBUG Installed: lua-dbi-0.7.4-1.el9.x86_64
2024-12-17T21:26:27+0100 INFO — logging initialized —
2024-12-17T21:26:58+0100 SUBDEBUG Upgrade: php-common-8.2.27-1.el9.remi.x86_64
2024-12-17T21:26:58+0100 SUBDEBUG Upgrade: php-pdo-8.2.27-1.el9.remi.x86_64
2024-12-17T21:26:58+0100 SUBDEBUG Installed: net-snmp-libs-1:5.9.1-17.el9.x86_64
2024-12-17T21:26:58+0100 SUBDEBUG Upgrade: php-cli-8.2.27-1.el9.remi.x86_64
2024-12-17T21:26:58+0100 SUBDEBUG Upgrade: php-fpm-8.2.27-1.el9.remi.x86_64
2024-12-17T21:26:58+0100 SUBDEBUG Upgrade: php-mbstring-8.2.27-1.el9.remi.x86_64
2024-12-17T21:26:58+0100 SUBDEBUG Upgrade: php-opcache-8.2.27-1.el9.remi.x86_64
2024-12-17T21:26:58+0100 SUBDEBUG Upgrade: php-sodium-8.2.27-1.el9.remi.x86_64
2024-12-17T21:26:58+0100 SUBDEBUG Upgrade: php-xml-8.2.27-1.el9.remi.x86_64
2024-12-17T21:26:59+0100 SUBDEBUG Installed: perl-Term-ReadLine-1.17-481.el9.noarch
2024-12-17T21:26:59+0100 SUBDEBUG Installed: perl-DBD-MySQL-4.050-13.el9.x86_64
2024-12-17T21:26:59+0100 SUBDEBUG Installed: lm_sensors-libs-3.6.0-10.el9.x86_64
2024-12-17T21:26:59+0100 SUBDEBUG Installed: net-snmp-agent-libs-1:5.9.1-17.el9.x86_64
2024-12-17T21:26:59+0100 SUBDEBUG Installed: net-snmp-1:5.9.1-17.el9.x86_64
2024-12-17T21:26:59+0100 SUBDEBUG Installed: libspf2-1.2.11-11.20210922git4915c308.el9.x86_64
2024-12-17T21:26:59+0100 SUBDEBUG Installed: libopendmarc-1.4.2-22.el9.x86_64
2024-12-17T21:26:59+0100 SUBDEBUG Installed: opendmarc-1.4.2-22.el9.x86_64
2024-12-17T21:26:59+0100 SUBDEBUG Installed: php-snmp-8.2.27-1.el9.remi.x86_64

You are looking at files. How about these commands:

dnf history
dnf history list MariaDB-server

(One has to run them as root.)

[root@server5 ~]# dnf history list MariaDB-server
ID | Command line | Date and time | Action(s) | Altered

127 | install MariaDB-server MariaDB-backup | 2024-12-17 21:08 | Install | 11 E<
125 | remove MariaDB-* | 2024-12-17 20:33 | Removed | 27 ><
51 | -y update --allowerasing | 2024-09-04 22:32 | E, I, O, U | 26 >E

Blockquote
I believe the following should do what you need ?

dnf --noautoremove erase mariadb

Thats the answer I was looking for. Used it on prosody. Its now update.

Are you sure the issue was really caused by something like “dnf remove <mariadb_package”?
If I look at your logs I see that someone installed a bunch of packages at the same time,
e.g. mariadb, but also extra stuff like rsync and lsof.
Later all that stuff was removed again at the same time.
So maybe someone tried to undo a mariadb installation with a tool like
“dnf history undo <transaction_number>” and accidentially removed too much as the transaction contained more than only mariadb.

Are you sure the issue was really caused by something like “dnf remove <mariadb_package”?
Yes.

I needed to upgrade to 10.6 mariadb. So I had to remove 10.5.22 first and select a newer version.

It removed as I said earlier that things got removed that shouldn’t. So I reinstall sevarall packages like open dmarc and others that where removed so things start working again. What is shown in the log. These packages also use some of the mariadb 10.5.22 dependecies.

If they are not dependencies to MariaDB then they won’t get removed. It’s not possible for a package to remove other packages that it doesn’t depend on.

The dnf history command would roll back changes made. Also dnf autoremove will remove packages it thinks the system no longer needs.

If you want us to verify it, post the entire log file here without editing it or removing evidence of what commands were ran. @james-p gave the command to use with dnf, which you could also have used rpm -e --nodeps although it’s not recommended to use rpm commands outside of yum/dnf (but I guess sometimes you just have to).

Thus it is possible to look at past transaction. Example:

dnf history info 125

The dnf history undo would roll back a transaction, if it can. That is not always possible. Example: transaction did update el9_4 package to el9_5 version. Repo does not have el9_4 package, and therefore the roll back (remove el9_5; install el9_4) is not possible.

If one does use the --noautoremove, then the “unused dependencies” are not removed.
The dnf autoremove seems to be for later “cleaning out” those packages (that noautoremove did leave).


Something like rsync (that was on the earlier post as “unused dependency”) is a command that one can very well need for something without any other package (than that version of MariaDB) requiring it.

The dnf has no way to know that user uses rsync. That is not an “explicit dependency”. Something like dnf group install Base would probably mark rsync as “needed by more than just MariaDB”.


I do install (and remove) packages primarily with Ansible. Therefore, I do have a list in “inventory” of groups/packages that I require. If “dnf rm” of some package predicts removal of packages that I know that I need, then I add them to the inventory.