Fix 'signature is invalid' on a signed repo database caused by a mirror mid-sync
The libalpm claims were checked against source. be_sync.c line 181 has the comment 'force update of invalid databases to fix potential mismatched database/signature' and sets dbforce. sync_db_validate runs at registration (_alpm_db_register_sync), so a database that failed validation in a previous run is re-downloaded on the next sync. signing.c maps GPG_ERR_BAD_SIGNATURE (and the default case) to ALPM_SIGSTATUS_INVALID, which prints %s: signature from "%s" is invalid. pacman-key's verify_sig pairs <file>.sig with <file> and runs gpg --verify, so BAD signature and Good signature come from gpg as the record says. cachyos.db.sig returns 200, so CachyOS does sign its databases. One cause sentence is wrong for the common case. The record says this happens 'with a database signature required', but the stock global level on Arch and Omarchy 4 (/etc/pacman.conf line 15 here) is Required DatabaseOptional. pacman.conf(5) says Optional still checks a signature that is present and treats an invalid one as fatal. So a mismatched pair fails on a stock configuration as well. Cause rewritten to say that. Fix, verify and danger hold. Not exercised: no CachyOS repository is configured here, and no sync was run.
Do not delete /var/lib/pacman/sync with a wildcard that could reach /var/lib/pacman/local, the installed-package database. Do not set the repo to SigLevel = Never or DatabaseNever to get past it: a mismatch is temporary, and disabling verification is permanent until you remember to undo it.
Symptom
A third-party repository that signs its databases (CachyOS is one) suddenly fails to sync, with a key that worked yesterday:
error: cachyos: signature from "CachyOS <admin@cachyos.org>" is invalid
error: failed to synchronize all databases (invalid or corrupted database (PGP signature))
The keyring is current, pacman-key --list-keys shows the key locally signed, and nothing changed on your side. Sometimes it clears by itself an hour later.
Cause
pacman verifies <repo>.db against <repo>.db.sig whenever the signature is present. That is true at the stock SigLevel = Required DatabaseOptional as well as at DatabaseRequired, because pacman.conf(5) treats an invalid signature as fatal even when the level is Optional. If the mirror is mid-sync, or a CDN cached one file longer than the other, you get a new database with the old signature (or the reverse), and GnuPG reports a bad signature, which libalpm prints as signature from "..." is invalid (ALPM_SIGSTATUS_INVALID). The key is fine. pacman marks the database invalid, and the next sync force-downloads it again: libalpm's be_sync.c does this explicitly "to fix potential mismatched database/signature". So a retry against a mirror that has finished syncing clears it.
This is a different fault from a missing, untrusted or expired key (is unknown trust, key ... is unknown, is expired), and from a captive portal returning HTML (GPGME error: No data). Those have their own records and their own fixes.
Fix
Tell a mismatch from a key problem before touching the keyring:
ls -l /var/lib/pacman/sync/cachyos.db /var/lib/pacman/sync/cachyos.db.sig
sudo pacman-key --verify /var/lib/pacman/sync/cachyos.db.sig
BAD signature from ... with the key known means the two files do not match: this record. No public key or Can't check signature means a key problem: use the third-party keyring record instead.
Retry the sync. pacman re-downloads an invalid database on its own.
Omarchy 4:
omarchy update
Plain Arch:
sudo pacman -Syu
If the same mirror keeps serving a mismatched pair, see which server it is and move a different one to the top of the mirrorlist that the repo's Include line names:
pacman-conf -r cachyos Server | head -3
grep -n Include <(sed -n '/^\[cachyos\]/,/^\[/p' /etc/pacman.conf)
sudoedit /etc/pacman.d/<that-mirrorlist>
Then retry as above.
Verify
sudo pacman-key --verify /var/lib/pacman/sync/<repo>.db.sig reports Good signature, and the update syncs every database without a PGP error.
Sources
- https://gitlab.archlinux.org/pacman/pacman/-/blob/master/lib/libalpm/be_sync.c
- https://gitlab.archlinux.org/pacman/pacman/-/blob/master/lib/libalpm/signing.c
- https://man.archlinux.org/man/pacman-key.8
- https://wiki.archlinux.org/title/Pacman/Package_signing
- https://man.archlinux.org/man/pacman.conf.5
- https://gitlab.archlinux.org/pacman/pacman/-/raw/master/scripts/pacman-key.sh.in