Skip to content

nix-collect-garbage: error getting outputs of ... database disk image is malformed #1353

Open

Description

@ambrop72

I started getting these errors and I can no longer collect garbage.

# nix-collect-garbage 
finding garbage collector roots...
deleting garbage...
deleting '...'
...
deleting '...'
error: error getting outputs of ‘/nix/store/3zhh42kb125zmxi9kfqn6c6xxbzvggi2-gtk2-engines.deb.drv’: database disk image is malformed
0 store paths deleted, 0.00 MiB freed

The error is not always for the same file. Attached are 3 example drv files for which the error occurs.
errors.zip

Activity

  1. ambrop72 commented on Apr 22, 2017

    @ambrop72
    Author

    I ran nix-store --verify --check-contents --repair and it succeeded without finding any issue.

  2. edolstra commented on Apr 24, 2017

    @edolstra
    Member

    Can you try

    sqlite3 /nix/var/nix/db/db.sqlite 'pragma integrity_check'
    

    This should print ok.

  3. ambrop72 commented on Apr 24, 2017

    @ambrop72
    Author

    Hi,
    I actually already worked around this issue (by deleting the GC root that was pulling in the problematic drvs and manually deleting these drvs, don't know if the latter was necessary). So while I don't know what this test would have done before I did that, now it does say ok.

  4. sjmackenzie commented on Nov 23, 2018

    @sjmackenzie
    > sqlite3 /nix/var/nix/db/db.sqlite 'pragma integrity_check' 
    *** in database main ***
    Page 957: btreeInitPage() returns error code 11
    Page 13391: btreeInitPage() returns error code 11
    Page 6178: btreeInitPage() returns error code 11
    Page 10204: btreeInitPage() returns error code 11
    Page 7794: btreeInitPage() returns error code 11
    Error: database disk image is malformed
    
  5. clacke commented on Nov 23, 2018

    @clacke

    I'll try the solution the original reporter used -- track down the derivations responsible and evict them.

  6. clacke commented on Nov 23, 2018

    @clacke

    It wasn't possible. This fixed the issue:

    # cd /nix/var/nix/db
    # nix-shell -p sqlite
    
    [nix-shell:/nix/var/nix/db]# sqlite3 db.sqlite ".backup 'db.bak.sqlite' "
    
    [nix-shell:/nix/var/nix/db]# sqlite3 db.sqlite 
    SQLite version 3.24.0 2018-06-04 19:24:41
    Enter ".help" for usage hints.
    sqlite> .output db.sql
    sqlite> .dump
    sqlite> 
    
    [nix-shell:/nix/var/nix/db]# sqlite3 db.new.sqlite < db.sql
    
    [nix-shell:/nix/var/nix/db]# mv db.new.sqlite db.sqlite
    

    I was hoping that simply using the backup would be good enough, but it retained the corruption. It was necessary to make a textual export and rebuild the database.

  7. 573 commented on Apr 4, 2019

    @573

    It wasn't possible. This fixed the issue:

    # nix-shell -p sqlite
    
    [nix-shell:/nix/var/nix/db]# sqlite3 db.sqlite ".backup 'db.bak.sqlite' "
    
    [nix-shell:/nix/var/nix/db]# sqlite3 db.sqlite 
    SQLite version 3.24.0 2018-06-04 19:24:41
    Enter ".help" for usage hints.
    sqlite> .output db.sql
    sqlite> .dump
    sqlite> 
    
    [nix-shell:/nix/var/nix/db]# sqlite3 db.new.sqlite < db.sql
    
    [nix-shell:/nix/var/nix/db]# mv db.new.sqlite db.sqlite
    

    I was hoping that simply using the backup would be good enough, but it retained the corruption. It was necessary to make a textual export and rebuild the database.

    At first I forgot the cd /nix/var/nix/db step before running that but that fixed it indeed.

  8. clacke commented on Apr 4, 2019

    @clacke

    Oh yes! Sorry for not being explicit. Edited my previous comment to include the cd step.

  9. ghuntley commented on Sep 6, 2020

    @ghuntley
    Member

    This issue could be closed. I also experienced corruption but that was related to running out of disk space on /nix (future folx, make sure you check this!)

  10. stale commented on Mar 5, 2021

    @stale

    I marked this as stale due to inactivity. → More info

  11. stale commented on Apr 21, 2022

    @stale

    I closed this issue due to inactivity. → More info

  12. pmiddend commented on Aug 28, 2023

    @pmiddend

    I'm still seeing this. Note that I had to change the actual .sql file produced by @573's answer. I had to remove BEGIN TRANSACTION and ROLLBACK, save the file, and then apply it. This took ages to complete, and then led me to issue 2218 which I could fix with @sondnm's solution there.

  13. blurgyy commented on Aug 30, 2023

    @blurgyy

    I'm also seeing this, @pmiddend I kept the BEGIN TRANSACTION and changed the ROLLBACK to COMMIT in the dumped db.sql, then sqlite3 newdb.sqlite <db.sql ran pretty fast, and after moving newdb.sqlite to the location, it seems to fix my problem.

  14. nixos-discourse commented on Nov 23, 2023

    @nixos-discourse

    This issue has been mentioned on NixOS Discourse. There might be relevant details there:

    https://discourse.nixos.org/t/an-easier-way-to-repair-corrupted-nix-db/35915/1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions