Subject: apk rebuild database?

From: Arjan Bouter <[email-masked]>
Date: Mon, 6 Jan 2025 18:56:51 +0100

Hi there,

when I try to use apk to update, add or remove applications I get the
following error:

ERROR: Unable to read database state: package file format error
ERROR: Failed to open apk database: package file format error

Strace shows a bit more info:

read(7, "C:Q1DAq8+0eVL2Ce+rsHzYHUPCmuEy8="..., 131072) = 131072
close(7)                                = 0
munmap(0x7f5d4fdd3000, 135168)          = 0
writev(2, [{iov_base="", iov_len=0}, {iov_base="ERROR: ", iov_len=7}],
2) = 7 writev(2, [{iov_base="Unable to read database state: p"...,
iov_len=56}, {iov_base=NULL, iov_len=0}], 2) = 56 writev(2,
[{iov_base="", iov_len=0}, {iov_base="\n", iov_len=1}], 2) = 1

Is there a way to recreate the database state file?

-- 

Kind regards,
Arjan Bouter

---

From: Timo Teras <[email-masked]>
Date: Tue, 7 Jan 2025 10:42:48 +0200

On Mon, 6 Jan 2025 18:56:51 +0100

> Is there a way to recreate the database state file?

Generally only by reinstalling the system. Any idea how it went to this
state? Maybe its possible to fix it manually.

Timo

---

From: Arjan Bouter <[email-masked]>
Date: Tue, 07 Jan 2025 10:32:28 +0000

Not what I wanted to hear, lol.

after a bit of digging it looks like apk fails to read scripts.tar.
Removing the offending entry mentioned by strace, the first entry, makes it complain about the next entry
Renaming lets me "apk update" again, but apk throws "error: unabe to select packages", which makes sense.

from the looks of it, there is nothing strange about the contents of scripts.tar.
Is there any way to learn why and on what it trips?

As for the cause, an empty battery in my laptop during an update.
One of these I-m-sure-it's-plugged-in moments...

Thanks for the help,
Arjan

---

From: Timo Teras <[email-masked]>
Date: Tue, 7 Jan 2025 12:48:50 +0200

Hi,

You can also just wipe the database, and reinstall everything.
Something like:

mv /lib/apk/db /lib/apk/db.backup
mkdir /lib/apk/db
apk fix

Which should reinstall everything you had, unless you have packages
that are no longer available in the repositories.

Timo

On Tue, 07 Jan 2025 10:32:28 +0000
Arjan Bouter <[email-masked]> wrote:

> Removing the offending entry mentioned by strace, the first entry,
> makes it complain about the next entry Renaming lets me "apk update"
> again, but apk throws "error: unabe to select packages", which makes
> sense.
> 
> from the looks of it, there is nothing strange about the contents of
> scripts.tar. Is there any way to learn why and on what it trips?
> 
> >> when I try to use apk to update, add or remove applications I get
> >> the following error:
> >> 
> >> writev(2, [{iov_base="", iov_len=0}, {iov_base="ERROR: ",
> >> iov_len=7}], 2) = 7 writev(2, [{iov_base="Unable to read database
> >> state: p"..., iov_len=56}, {iov_base=NULL, iov_len=0}], 2) = 56
> >> writev(2, [{iov_base="", iov_len=0}, {iov_base="\n", iov_len=1}],
> >> 2) = 1
> >> 
> >Generally only by reinstalling the system. Any idea how it went to
> >this state? Maybe its possible to fix it manually.
> >
> >Timo
> >

---

From: Arjan Bouter <[email-masked]>
Date: Tue, 07 Jan 2025 12:28:37 +0000

It should, but doesn't.
That would be too easy.

The error is now: unable to select packages 
It also complains about what appears to be the contents of /etc/apk/world which looks like /etc/resolv.conf

---

From: "Sertonix" <[email-masked]>
Date: Tue, 07 Jan 2025 12:30:28 +0000

Would you mind sharing the contents of /etc/apk/world?