# pkg2ng: Is it safe to delete directories out /var/db/pkg?



## Xenomorph (Feb 11, 2014)

Based on what I've seen in other threads, I'm confused as to what the expected behavior is of pkg2ng:

pkg2ng simply renames /var/db/pkg to /var/db/pkg.bak:
https://mebsd.com/make-build-your-freeb ... nager.html (Feb 2012)

pkg2ng deletes everything in /var/db/pkg:
http://www.freebsd.org/cgi/query-pr.cgi?pr=171833 (Sep 2012)

pkg2ng does nothing to /var/db/pkg:
http://forums.freebsd.org/viewtopic.php?t=43963 (Dec 2013)

As of right now (February 11th, 2014 w/ FreeBSD 9.2-RELEASE), when moving from pkg_* tools to pkg, you end up with *two* databases of installed packages. Based on the above linked forum posts and web page, it seemed that in the past, someone working on pkg2ng apparently tried to correct this, but it was later changed to leave it how it works now.

That presents a minor issue with the two databases:

One database will continue to grow, and show the current package versions (what pkg uses).
One database will never grow, and just get stale (leftovers from pkg_*, which should have been removed).

Once converted from pkg_* tools to pkg, is it OK to delete the old package information directories from /var/db/pkg?


```
# cd /var/db
# cp -pr pkg pkg.bak
# cd pkg
# find . -type d -exec rm -r {} \;
```
It looks like the only two files I need in /var/db/pkg are "local.sqlite", and "repo-*.sqlite". All the other directories (and their files) were for the pkg_* tools.

Is this going to come back and bite me later? Why does pkg2ng no longer try to clean up /var/db/pkg?


----------



## wblock@ (Feb 12, 2014)

*Re: pkg2ng: Is it safe to delete directories out /var/db/pkg*

`pkg2ng` just reads the data in /var/db/pkg and creates similar values in the new package database.  It does not remove the old data.

portmaster(8) also keeps some data in there.  I just delete the + files out of the directories.


----------



## SirDice (Feb 12, 2014)

*Re: pkg2ng: Is it safe to delete directories out /var/db/pkg*



			
				wblock@ said:
			
		

> `pkg2ng` just reads the data in /var/db/pkg and creates similar values in the new package database.  It does not remove the old data.


Unless something has changed recently `pkg2ng` will definitely _remove_ the old registrations if it successfully registered in the new system.


----------



## Xenomorph (Feb 12, 2014)

*Re: pkg2ng: Is it safe to delete directories out /var/db/pkg*



			
				SirDice said:
			
		

> wblock@ said:
> 
> 
> 
> ...



How exactly does it "remove" old registration? 

In a VM, I tested a clean install of FreeBSD 9.2, installed _one_ thing with `pkg_add` ("pkg_add -rv bash"), then ran `pkg2ng`. All it seemed to do was create /var/db/pkg/local.sqlite, and it left everything else alone. Nothing seemed to be removed, so programs like `pkg_info` still listed the same installed packages.


----------



## wblock@ (Feb 12, 2014)

*Re: pkg2ng: Is it safe to delete directories out /var/db/pkg*



			
				Xenomorph said:
			
		

> In a VM, I tested a clean install of FreeBSD 9.2, installed _one_ thing with `pkg_add` ("pkg_add -rv bash"), then ran `pkg2ng`. All it seemed to do was create /var/db/pkg/local.sqlite, and it left everything else alone. Nothing seemed to be removed, so programs like `pkg_info` still listed the same installed packages.



Same here, and I've done two conversions in the last week or so.  I assumed this was done so the user could switch back or re-run `pkg2ng` if necessary.


----------



## kpa (Feb 12, 2014)

*Re: pkg2ng: Is it safe to delete directories out /var/db/pkg*

I guess it was changed because blowing away the old /var/db/pkg/* entries without offering any option to revert the change is kind of dangerous and invasive.


----------

