Fixing a Messed Up Package Database
From time to time, the package database gets for some unknown reason messed up, and the result is some strange errors about 'pkgdb'. It's easy to fix, though.
The package database is vital for a FreeBSD system. Whether the software on the system is installed from packages or ports, this database keeps track of it all. You cannot upgrade or install new software if something is wrong with the database.
When I first experienced a messed up package database, I got this strange error message:
Updating the pkgdb in /var/db/pkg ... - 456 packages found (-1 +0) (...)Cannot allocate memory: Cannot update the pkgdb!Regenerating the Database
To get back on track with your FreeBSD you'll need to regenerate the package database from scratch to fix this.
Run the following three commands with superuser privileges:
# cd /var/db/pkg
# mv pkgdb.db pkgdb.db.bak
# pkgdb -uThe first command changes the directory to where all installed packages are stored. The second command renames the actual database file so we can reverse it if something goes wrong.
The last command regenerates the package database from scratch.
If that last command doesn't output any error messages, you have successfully fixed a messed up package database.
