# pkgng unable to open database sqlite corrupt



## drhowarddrfine (Sep 1, 2013)

In /usr/ports/UPDATING, as we all know, we were told about changes to portmaster and we should do the following:



> It's possible that you may have tested pkgng in the past, ran pkg2ng, and
> never fully committed to it by setting WITH_PKGNG. If this is the case,
> uninstall pkg with pkg_info/pkg_delete and also remove the stale database,
> rm /var/db/pkg/local.sqlite.
> ...



Running `pkg info pkg` returned nothing so I did as instructed. Perhaps it was the wrong thing to do but I don't feel the instructions were quite clear. 

In any case, whenever I run portmaster to upgrade a port, I'm given a warning or error that portmaster(?) is unable to find the database and, _IIRC_, portsnap says the SQLite database is corrupt. 

I tried uninstalling/re-installing ports-mgmt/pkg to no avail but, despite all this, I've been able to upgrade and install ports without issue that I'm aware of.

So, a little help on this, please.


----------



## kpa (Sep 1, 2013)

The main question is do you want to use PKGNG or not? If you don't want to use it now the solution is to delete the database as instructed in UPDATING and make sure you don't have WITH_PKGNG in make.conf and then delete the pkg package with `pkg_delete -x pkg`.


----------



## ShelLuser (Sep 1, 2013)

drhowarddrfine said:
			
		

> Running `pkg info pkg` returned nothing so I did as instructed. Perhaps it was the wrong thing to do but I don't feel the instructions were quite clear.


Well, if you read the section above the one you quoted you'll notice that the main difference here is that portmaster no longer depends on WITH_PKGNG to be defined in /etc/make.conf.

Then comes the section you quoted, where the question is basically if you started using pkgng for real or if you (quote): "_never fully committed to it by setting WITH_PKGNG._".



			
				drhowarddrfine said:
			
		

> In any case, whenever I run portmaster to upgrade a port, I'm given a warning or error that portmaster(?) is unable to find the database and, _IIRC_, portsnap says the SQLite database is corrupt.


I'm afraid you worked yourself into a huge problem here because it seems you removed the pkgng database while you were actually using pkgng as your main package manager (I assume you have WITH_PKGNG defined in /etc/make.conf?).

From what I understand of pkgng it is possible that it will create a new (empty) database during run, but that obviously won't help you.

The best option here is restore a backup, if you have one.

If you kept the previous ports database around then you might be able to undo the damage by running `# pkg2ng` again after which I'd suggest using something like `# portmaster --check-depends` to make sure all dependencies are met. However, this provides no guarantees at all; if you installed any ports after the initial conversion then it's very likely that those won't find their way back into the package database when using this approach.

Another option could be using `# pkg check` (see pkg-check(8)) but that's where my expertise on pkgng ends because I'm still using the previous package management tools.

Hope this can give you some leads to work on.


----------



## freethread (Sep 1, 2013)

On one of my FreeBSD VM I installed ports-mgmt/pkg and converted the packages database with pkg2ng to test the new package maintenance system, but really I never installed packages [x86 VM], I always use ports, however pkg is a bit faster than counterparts pkg_info & Co. to retreive ports/packages information/versions/etc.

I've seen on some man page the way to revert the new packages database format to old version, but I don't find where it is, pkg2ng has no help or man page, I remember an -r or -R switch to go back and forth into database formats, so before uninstalling the new package system binaries it's better to restore the old package database format.


----------



## drhowarddrfine (Sep 1, 2013)

No, I've never used pkgng and I've not installed any packages though it is my understanding portmaster will install packages when they are dependencies and a port is not available. No, I never modified my make.conf file either.

So I'm not sure what went wrong but I did this four or more weeks ago. I'm also not sure if I need to do anything about it or what harm may be done. This is for my workstation only and I can reinstall when I have the time unless someone has a better idea.

The problem I have with the text in /usr/ports/UPDATING is the "if you never used it or if you never committed to it" part which requires us to remember what we've done in the past. As I said, `pkg info pkg` returned nothing so I did what I was told to do.


----------



## ShelLuser (Sep 1, 2013)

drhowarddrfine said:
			
		

> No, I've never used `pkgng` and I've not installed any packages though it is my understanding `portmaster` will install packages when they are dependencies and a port is not available. No, I never modified my make.conf file either.


Well, you have done something because if you never used pkgng before then it would return specific text when you used the `# pkg info pkg` command:


```
smtp2:/usr $ pkg info pkg
The package management tool is not yet installed on your system.
Do you want to fetch and install it now? [y/N]:
```
So the fact that it didn't return anything on your end tells me that you somehow must have installed pkgng. *** My theory now is that after you did so portmaster started using it as well, because of the change in behaviour which was addressed in the section you've quoted above.

So my suggestion would be to remove pkgng as follows: `# pkg_delete pkg` after which portmaster should return to it's normal behaviour.

Just in case I'd still use `# portmaster --check-depends` after you removed pkgng just to make sure that the integrity of the previous package management database is still intact.

*Edit:*

***: There is something weird going on it seems. Thing is; I misread; having just set up a jail which uses pkgng I noticed my mistake, it actually should return something:


```
# pkg info pkg
pkg-1.1.4_1
```
So if `pkg info pkg` didn't return anything on your end then something doesn't quite make sense to me.


----------



## drhowarddrfine (Sep 1, 2013)

Yes, I had uninstalled pkg already. I DO get the install dialog you show now. I recall I did NOT get it back when the UPDATING post went out.

Running `# portmaster --check-depends` gives only this one warning


> ===>>> Checking local.sqlite
> ===>>> Warning: No +CONTENTS file!



I'm aware I may come across as a blithering idiot and screw up but I'm being pulled in so many directions for the last few months I have trouble recalling what I've done and how to do things so I guess I have to apologize for that. Right now I have my underwear on over my pants.


----------



## kpa (Sep 1, 2013)

Delete the local.sqlite file as instructed in UPDATING. The old pkg_* tools do not recognize it as being anything special, neither does portmaster when operating in non-PKGNG mode.


----------



## drhowarddrfine (Sep 1, 2013)

I did. Unless it's somewhere other than /var/db/pkg?


----------



## ShelLuser (Sep 1, 2013)

Still wondering what happened but I'd like to address this one right away:



			
				drhowarddrfine said:
			
		

> I'm aware I may come across as a blithering idiot and screw up but I'm being pulled in so many directions for the last few months I have trouble recalling what I've done and how to do things so I guess I have to apologize for that.


You don't come across like that at all and you really don't need to apologize. We've all been in situations where we did something utterly stupid and where the solution was so darn obvious (not insinuating that this is what you did by the way, just used as an expression).

Heck, I still recall @kpa pointing out to me that using spaces in /etc/rc.conf isn't the best of ideas   Yet there I was, and even though my rc.conf was already filled with several other entries I still managed to overlook the obvious. For several hours even.

Makes you feel like an idiot for sure, but doesn't turn you into one


----------



## kpa (Sep 1, 2013)

Do a search for local.sqlite under the /var directory: `find /var -name local.sqlite`


----------



## drhowarddrfine (Sep 1, 2013)

@ShelLuser, thanks for that.

@kpa I had just done a whereis which found it, as did find, but doing a `ls` never showed but `ls -a` does. So I deleted that.

But now I'm wondering if I'm in trouble with anything anywhere and what happens if I decide to use PKGNG later?


----------



## ShelLuser (Sep 1, 2013)

drhowarddrfine said:
			
		

> Running # portmaster --check-depends gives only this one warning


I think I know what's up.

I started looking into portmaster to find the origin of this error message, and I found it:


```
if [ -n "$CHECK_DEPENDS" ]; then
        if [ -n "$use_pkgng" ]; then
                # TODO
                pkg check -adv
                exit
        fi
        PM_VERBOSE=pmv_check_depends
IFS='
'
        for pkg in $pdb/*; do
                [ -d "$pkg" ] || continue

                iport=${pkg#$pdb/}

                echo "===>>> Checking $iport"

                if [ ! -r "$pkg/+CONTENTS" ]; then
                        echo "  ===>>> Warning: No +CONTENTS file!"
                        continue
                fi
```
So it's safe to conclude that you're no longer using pkgng and I think the error doesn't come from pkgng but from an entry in /var/db/pkg.

I wonder if this directory exists: /var/db/pkg/local.sqlite. If so; remove it.


----------



## ShelLuser (Sep 1, 2013)

drhowarddrfine said:
			
		

> But now I'm wondering if I'm in trouble with anything anywhere and what happens if I decide to use pkgng later?


Well, seems you guys beat me to it by a second, though I would appreciate it if you could share where that entry resided.

You should be fine for now but there is one small risk; any port which you installed between the moment when portmaster started using pkgng and now is most likely invisible to the system. Because the (now deleted) pkgng database was updated instead of the current one.

I don't think you'll run into major problems though because all package dependencies are met (portmaster told you as much). However, because those ports are invisible you also won't be getting any updates for them.

So I'd simply keep that in mind. If you suddenly notice an entry in /usr/ports/UPDATING talking about things to do when updating something you're using while portmaster doesn't detect a new version then the only thing you need to do is re-install that port. That will then register itself with the old database again after which you'll be back to normal.

Finally; this will have no consequences for you if you later decide to switch to pkgng. Just follow the instructions and you'll be fine.


----------

