# pkg database spoiled?



## hruodr (May 24, 2019)

I installed much, much more than this!!!!


```
% pkg info
boehm-gc-8.0.4                 Garbage collection and memory leak detection for C and C++
gettext-runtime-0.19.8.1_2     GNU gettext runtime libraries and programs
indexinfo-0.3.1                Utility to regenerate the GNU info page index
libX11-1.6.7,1                 X11 library
libXau-1.0.9                   Authentication Protocol library for X11
libXdmcp-1.1.3                 X Display Manager Control Protocol library
libevent-2.1.8_3               API for executing callback functions on events or timeouts
libpthread-stubs-0.4           This library provides weak aliases for pthread functions
libxcb-1.13.1                  The X protocol C-language Binding (XCB) library
libxml2-2.9.8                  XML parser library for GNOME
nasm-2.14.02,1                 General-purpose multi-platform x86 and amd64 assembler
nsd-4.1.27                     Authoritative only non-recursive name server
perl5-5.28.1_1                 Practical Extraction and Report Language
rdesktop-1.8.4                 RDP client for Windows NT/2000/2003 Terminal Server
w3m-0.5.3.20190105             Pager/text-based WWW browser
xorgproto-2018.4               xorg protocol headers

% ll /var/db/pkg/
total 34562
-rw-r--r--  1 root  wheel       246 May 23 03:36 FreeBSD.meta
-rw-r--r--  1 root  wheel   1880064 May 24 15:46 local.sqlite
-rw-r--r--  1 root  wheel  54030336 May 23 03:36 repo-FreeBSD.sqlite
```


----------



## hruodr (May 24, 2019)

It seems that something deleted my database at some point. But I do not see dates in the tables of the DB I have.

Is such a problem known? I do not think that I deleted it with `rm`.

Now I must save my files. It seems that I will need to install FreeBSD again and tune my system again.


----------



## zirias@ (May 24, 2019)

hruodr said:


> Now I must save my files. It seems that I will need to install FreeBSD again and tune my system again.


Well, if it's really messed up, you don't have to reinstall the whole system, just the packages. You might want to backup /usr/local/etc somewhere, then you could simply remove /usr/local and the pkg databases completely and start reinstalling your packages.


----------



## hruodr (May 24, 2019)

Zirias said:


> Well, if it's really messed up, you don't have to reinstall the whole system, just the packages.



Unfortunately that is not enough. I do not remember all what was installed. Upgrading means also deinstal files that are 
not anymore necessary. The information of what files was installed by what package is lost.


----------



## ShelLuser (May 24, 2019)

Did you by any chance mix the installation of binary packages (`# pkg install ...`) with ports? (`# make install clean`)? Because that would explain quite a bit.


----------



## malavon (May 24, 2019)

hruodr said:


> Unfortunately that is not enough. I do not remember all what was installed. Upgrading means also deinstal files that are
> not anymore necessary. The information of what files was installed by what package is lost.


Almost all files installed by packages go into /usr/local  (exception are kernel modules installed by packages). By removing that directory (or its contents), all packages
will be effectively uninstalled.
From that point on you can just `pkg install -f ...` whatever you need. No need to install more anyway, you'll know you need something when you notice it's not on your
system. A good starting point is probably xorg and the window manager you wanted to use (assuming it's a desktop).


----------



## shkhln (May 24, 2019)

There might be a copy of the local package database in the _/var/backups_ directory. Specifically, _/usr/local/etc/periodic/daily/411.pkg-backup_ will be executed at roughly 3 a.m. if it's not disabled and the computer is powered up (I only mention that because at that time desktops usually aren't).



ShelLuser said:


> (`# make install clean`)? Because that would explain quite a bit.



Isn't that supposed to work through pkg anyway?


----------



## hruodr (May 24, 2019)

Now I understand: I can delete /usr/local and install all again. And yes, there is something in /var/backups. 

But I hope once to know how the database shrank.


----------



## malavon (May 24, 2019)

hruodr said:


> But I hope once to know how the database shrank.


Agreed. I wouldn't be surprised if it happens again, although I have no idea what might cause such a thing. Nonetheless, you'll probably have an 'Aha' moment followed by an urge
to headslap yourself when it does


----------



## malavon (May 24, 2019)

Have you removed any packages by chance? If you have, you might have also removed all packages that depend on it recursively (which is default behaviour and intended).
e.g. if I were to `pkg remove wayland` - which I currently don't use - then almost all graphical ports on my system will be removed including even nvidia-driver.


----------



## hruodr (May 25, 2019)

malavon said:


> Have you removed any packages by chance?



I had a lot of packages and only remain 16. Firefox that I installed not as dependency and I am using, also disappeared from the db. Dependencies are taken away when they are not anymore used. 
My backups seems to contain a lot of packages, but are from end of 2017.

I will keep the calm, backup my data. I bought I a new hd, I will install FreeBSD 12.0, or 12.1 if it comes soon, and then try to repair this disk.

Is FreeBSD 12.0 as stable as 11.2?


----------



## hruodr (Jun 23, 2019)

Zirias said:


> and the pkg databases completely and start reinstalling your packages.



Indeed better not to forget to delete /var/db/pkg/*. I forgot and got a broken system. Well, I noted it early.


----------

