# How to force pkg to index packages



## amnixed (Sep 26, 2014)

After running portsnap(8) I tried to upgrade pkg-1.3.7 to pkg-1.3.8_2 using portupgrade(1). Although portversion(1) indicated pkg-1.3.8_2 was available to upgrade from pkg-1.3.7, `portupgrade -vR pkg-1.3.7` resulted ** None has been installed or upgraded, leaving pkg-1.3.7 apparently undisturbed.

I then did:


```
rm -v /usr/ports/INDEX*
rm -rfv /var/db/ports/*
rm -rfv /var/db/pkg/*
portsnap fetch
portsnap extract
```

Also deinstalled/reinstalled pkg() and portupgrade().

Now I have:


```
# portversion -v
[Reading data from pkg(8) ... - 2 packages found - done]
pkg-1.3.8_2                 =  up-to-date with port 
portupgrade-2.4.12_2,2      =  up-to-date with port
```

However, I have 40+ packages installed which all were built from ports.

How can I force pkg(8) and portupgrade(1) to index installed packages?

Many thanks for your suggestions.


----------



## amnixed (Sep 26, 2014)

Well, this is not the answer to my original question, but I thought I should look at /usr/local/bin which gives me a clue about what is installed on this computer with broken pkg()/portupgrade() databases, and then just (re)build/(re)install ports.

Does this seem to be a sensible approach?


----------



## kpa (Sep 27, 2014)

Well you deleted the package information and it's lost now. What you have on disk is an unrelated collection of files with no clues of which file belonged to which package. You can certainly guess what packages you had based on the contents of /usr/local/{bin|sbin|lib|libexec} and that's probably the way to go unless you can restore the package database somehow.


----------



## amnixed (Sep 27, 2014)

Well, another learning experience...


----------



## junovitch@ (Sep 27, 2014)

If you are lucky you can probably use the daily periodic backup of the package database under /var/backups/pkg.sql.xz and the `pkg backup` command to restore your database.  Haven't tried it but would advise seeing if the automatic backup is there and taking a look at `pkg help backup` for how to restore.


----------



## SirDice (Sep 29, 2014)

amnixed said:
			
		

> ```
> rm -rfv /var/db/pkg/*
> ```


Bad idea. This also deletes /var/db/pkg/local.sqlite, the database which contains your currently installed packages.


----------

