Bug 2073061

Summary: dnf upgrade: Error: SQLite error on "/var/lib/dnf/history.sqlite": Reading a row failed: UNIQUE constraint failed: rpm.name, rpm.epoch, rpm.version, rpm.release, rpm.arch
Product: [Fedora] Fedora Reporter: Matti Linnanvuori <mattilinnanvuori>
Component: dnfAssignee: Lukáš Hrázký <lhrazky>
Status: CLOSED DUPLICATE QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: high Docs Contact:
Priority: unspecified    
Version: 36CC: daniel.mach, jmracek, jrohel, lhrazky, mblaha, mhatina, packaging-team-maint, pkratoch, rpm-software-management, vmukhame
Target Milestone: ---Keywords: Triaged
Target Release: ---   
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2022-04-26 09:27:32 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Matti Linnanvuori 2022-04-07 15:01:33 UTC
Description of problem:
dnf --refresh upgrade fails with the following error.

Version-Release number of selected component (if applicable):
4.11.1-2

How reproducible:
Run dnf --refresh upgrade

Steps to Reproduce:
1. Install Fedora Workstation 35
2. Upgrade to Fedora Workstation 36 Beta
3. Run dnf --refresh upgrade

Actual results:
The downloaded packages were saved in cache until the next successful transaction.
You can remove cached packages by executing 'dnf clean packages'.
Error: SQLite error on "/var/lib/dnf/history.sqlite": Reading a row failed: UNIQUE constraint failed: rpm.name, rpm.epoch, rpm.version, rpm.release, rpm.arch

Expected results:
Running dnf --refresh upgrade succeeds.

Comment 1 Lukáš Hrázký 2022-04-26 09:27:32 UTC
Hello, apologies for the inconvenience. We're getting these reports quite rarely, they are nondeterministic (unless you can reproduce this, a reproducer would be very helpful to us) and we don't know the cause.

You can remove (or, better, back up and remove) the /var/lib/dnf/history.sqlite file, dnf will keep working but you'll lose your userinstalled / groupinstalled packages, meaning dnf will no longer know which packages you installed explicitly and which were pulled in as a dependency.

You can also attempt to repair the corrupted database following these steps (under root, you may need to install the sqlite3 binary via `dnf install -y sqlite`):
# cd /var/lib/dnf
# ls
history.sqlite  history.sqlite-shm  history.sqlite-wal  repos
# mkdir db-backup
# mv history.sqlite* db-backup
# echo .recover | sqlite3 db-backup/history.sqlite > recover.sql
# sqlite3 history.sqlite < recover.sql

I'm marking this as a duplicate as we already have a bug for this.

*** This bug has been marked as a duplicate of bug 1868860 ***