Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 30 Aug 2022 10:45:32 -0700
From:      "Dan Mahoney (Ports)" <freebsd@gushi.org>
To:        Pete Wright <pete@nomadlogic.org>
Cc:        Kevin Oberman <rkoberman@gmail.com>, FreeBSD Ports ML <freebsd-ports@freebsd.org>
Subject:   Re: Recover from a corrupt pkg DB
Message-ID:  <0BDF281F-B485-4EE6-B0A5-698F5B134C99@gushi.org>
In-Reply-To: <20220830172613.bl4q3ynadyktstgw@shelly.nomadlogic.org>
References:  <CAN6yY1vGf=LdXQ4DZjJRxho2t%2BNcGd0jt2-T7nhm84YjtCKN5g@mail.gmail.com> <20220830172613.bl4q3ynadyktstgw@shelly.nomadlogic.org>

next in thread | previous in thread | raw e-mail | index | archive | help


> On Aug 30, 2022, at 10:26 AM, Pete Wright <pete@nomadlogic.org> wrote:
>=20
> On Tue, Aug 30, 2022 at 09:36:52AM -0700, Kevin Oberman wrote:
>> I had a crash while building ffmpeg on a new system. The build had =
not
>> begun, so I don't think ffmpeg is really an issue. portmaster(8) was
>> walking the dependency tree when the system panicked and, after a =
reboot
>> and full fsck, I get the error:
>> pkg: sqlite error while executing PRAGMA user_version; in file
>> pkgdb.c:2357: database disk image is malformed

So, I don=E2=80=99t know what tools are available in sqlite3 to dump a =
malformed db file and reimport it.  I think that=E2=80=99s probably =
beyond the scope of this, but as I=E2=80=99ve in the past hit pkg =
issues, I=E2=80=99ve always wanted to know if there was an online =
description of the schema somewhere.  (Obviously, you could peruse the =
schema on a second non-corrupt system, but that doesn=E2=80=99t describe =
how it=E2=80=99s used).

>>=20
>> Is there any way to rebuild the DB or, if not, how do I remove it and =
start
>> from scratch?

I mean, this is a *very* brute force approach, but if you know precisely =
what packages you had installed, you can always just reinstall pkg and =
pkg install -f those packages.

>=20
> I ran into a similar issue a while back, I discovered I was able to
> recover by using one of the automated backups generated at:
> /var/backups/pkg.sql.xz*
>=20
> I can't remember the details, but I think it involved replacing
> repo-FreeBSD.sqlite in /var/db/pkg/.

I=E2=80=99ve dealt with this on another OS that did things far, far =
worse (RPM, in the days before Yum).  It always stymied me that there =
was no online tool that could look at all the files you had in =
/usr/local/*, look at checksums of historical packages, and glean a =
=E2=80=9Chey, it looks like these are the packages you had installed, =
but *these files* are the ones that don=E2=80=99t match any checksum on =
record.=E2=80=9D

-Dan






Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?0BDF281F-B485-4EE6-B0A5-698F5B134C99>