# pkg-static: sqlite error ... database disk image is malformed



## linux->bsd (Jan 22, 2017)

I'm getting the following 'database disk image is malformed' error messages that are preventing `portmaster -a` from updating any ports. Does anyone know of a fix for this?:


```
portmaster -a
[[ snip ]]

===>>> All >> (19)

===>>> The following actions will be taken if you choose to proceed:
        Upgrade pkgconf-1.1.1 to pkgconf-1.2.0_2
        Upgrade libdevq-0.0.2_1 to libdevq-0.0.4
        Install devel/autoconf
        Install devel/autoconf-wrapper
        Upgrade m4-1.4.17_1,1 to m4-1.4.18,1
        Upgrade perl5-5.24.1.r5_1 to perl5-5.24.1
        Install misc/help2man
        Install devel/p5-Locale-gettext
        Install devel/automake
        Install devel/automake-wrapper
        Install devel/libtool
        Upgrade cups-2.2.1 to cups-2.2.2_1
        Upgrade dbus-1.10.14_1 to dbus-1.10.14_2
        Upgrade libdrm-2.4.66,1 to libdrm-2.4.74,1
        Upgrade libfontenc-1.1.3 to libfontenc-1.1.3_1
        Upgrade libtasn1-4.9 to libtasn1-4.10
        Upgrade bash-4.4.5 to bash-4.4.7
        Upgrade bison-2.7.1_1,1 to bison-3.0.4,1
        Upgrade vim-8.0.0149_2 to vim-8.0.0209

===>>> Proceed? y/n [y]
[[ snip ]]

pkgconf-1.1.1: missing file /usr/local/share/licenses/pkgconf-1.1.1/catalog.mk
[1/1] Deleting files for pkgconf-1.1.1: 100%
pkg: sqlite error while executing DELETE FROM packages WHERE id = ?1; in file pkgdb.c:2305: database disk image is malformed

===>>> Starting check for runtime dependencies
===>>> Gathering dependency list for devel/pkgconf from ports
===>>> No dependencies for devel/pkgconf

===>  Installing for pkgconf-1.2.0_2
===>  Checking if pkgconf already installed
===>   An older version of pkgconf is already installed (pkgconf-1.1.1)
      You may wish to ``make deinstall'' and install this port again
      by ``make reinstall'' to upgrade it properly.
      If you really wish to overwrite the old port of pkgconf
      without deleting it first, set the variable "FORCE_PKG_REGISTER"
      in your environment or the "make install" command line.
*** Error code 1

Stop.
make: stopped in /usr/ports/devel/pkgconf

===>>> A backup package for pkgconf-1.1.1 should
       be located in /usr/ports/packages/portmaster-backup

===>>> Installation of pkgconf-1.2.0_2 (devel/pkgconf) failed
===>>> Aborting update

===>>> Update for devel/pkgconf failed
===>>> Aborting update


===>>> You can restart from the point of failure with this command line:
       portmaster <flags> devel/pkgconf devel/libdevq devel/autoconf devel/autoconf-wrapper devel/m4 lang/perl5.24 misc/help2man devel/p5-Locale-gettext devel/automake devel/automake-wrapper devel/libtool print/cu
ps devel/dbus graphics/libdrm x11-fonts/libfontenc security/libtasn1 shells/bash devel/bison editors/vim
```

I did a bit of web searching for possible fixes to the `pkg-static: sqlite error while executing ... in file pkgdb.c:...: database disk image is malformed` error, but they required using sqlite. Installing sqlite3 from ports and using `pkg` fails.

Attempting to reinstall pkgconf fails with a similar error message:

```
[root@freebsd_pc /usr/ports/devel/pkgconf]# make deinstall && make install
===>  Deinstalling for pkgconf
===>   Deinstalling pkgconf-1.1.1
pkg-static: sqlite error while executing DROP INDEX IF EXISTS pkg_digest_id;BEGIN TRANSACTION; in file pkgdb.c:2340: database disk image is malformed
pkg-static: sqlite error while executing DROP INDEX IF EXISTS pkg_digest_id;BEGIN TRANSACTION; in file pkgdb.c:3062: database disk image is malformed
pkg-static: sqlite error while executing END TRANSACTION;PRAGMA synchronous = NORMAL;PRAGMA journal_mode = DELETE; in file pkgdb.c:2340: cannot commit - no transaction is active
Checking integrity... done (0 conflicting)
Deinstallation has been requested for the following 1 packages (of 0 packages in the universe):

Installed packages to be REMOVED:
        pkgconf-1.1.1

Number of packages to be removed: 1
[1/1] Deinstalling pkgconf-1.1.1...
[1/1] Deleting files for pkgconf-1.1.1:   0%
pkgconf-1.1.1: missing file /usr/local/bin/pkg-config
[1/1] Deleting files for pkgconf-1.1.1:   5%
 [[ snip ]]
pkgconf-1.1.1: missing file /usr/local/share/licenses/pkgconf-1.1.1/LICENSE
[1/1] Deleting files for pkgconf-1.1.1:  94%
pkgconf-1.1.1: missing file /usr/local/share/licenses/pkgconf-1.1.1/catalog.mk
[1/1] Deleting files for pkgconf-1.1.1: 100%
pkg-static: sqlite error while executing DELETE FROM packages WHERE id = ?1; in file pkgdb.c:2305: database disk image is malformed
*** Error code 3

Stop.
make: stopped in /usr/ports/devel/pkgconf
```


----------



## SirDice (Jan 23, 2017)

Looks like your local package database got corrupted somehow. I'm not sure if this is fixable or not.


----------



## linux->bsd (Jan 24, 2017)

SirDice said:


> Looks like your local package database got corrupted somehow. I'm not sure if this is fixable or not.



I tried a bunch of different approaches, all of which only partially succeeded, and in the end restored from backups. On the plus side, I found out that my current backups strategy is potentially vulnerable to corruption, so I'll be switching to `dar` or `dump` soon. Better to find out now than much farther down the road.


----------



## SirDice (Jan 24, 2017)

linux->bsd said:


> On the plus side, I found out that my current backups strategy is potentially vulnerable to corruption, so I'll be switching to  dar or  dump soon. Better to find out now than much farther down the road.


People often forget to actually test their backups. You wouldn't be the first to diligently backup everything only to find out those backups are useless at the worst possible moment.


linux->bsd said:


> Better to find out now than much farther down the road.


Definitely!


----------

