TransWikia.com

QGIS: OGR error when editing Geopackage layers : database is locked

Geographic Information Systems Asked on February 12, 2021

I started to draw new polygons in a layer within an existing GeoPackage that I previously created.

However, after editing several layers, I sometimes (apart that it doesn’t happen when editing one single layer, it looks like a random phenomena) cannot save the layer and I get the error:

Errors: ERROR: feature(s) not added.

Provider errors: 
  OGR error creating feature: failed to execute insert : database is locked

The polygons drawn are then lost, which is pretty frustrating.

I googled a lot and found this rather old fix which is apparently already applied in QGIS 3.12 (my version).

Any suggestion?

3 Answers

ok unfortunately I performed 2 different resolution activities, and im not sure which activity resolved the problem.

First Action - I had previously run a python script (outside of QGIS) which had completed, but it had used the Geopackage (a different table though). I simply closed this python console window (maybe the console or process that ran inside the console had locked the DB?)

Second action - In QGIS, i went to Database > DB Manager and 'Reconnected' the database. I then reloaded the layer inside of my QGIS session, made an edit and saved. all good.

So - whether it was the first or second action. not sure.

Answered by nr_aus on February 12, 2021

In QGIS open your layers, then in database manager make a connection with the geopackage, delete all the layers, it is going to be opened in your actual project, then export each one to the same geopackage, it's going to appear the new layer with another style, so I recommend you to save each style too. It works for me.

Answered by CAMHN on February 12, 2021

When you open a geopackage, a few hidden extra file appear next to it in the directory. That basically lock the file so that no other user can change it. While geopackage is a database, its limited to one user. In this case Python had a handle on the file. If python crashes, it can sometimes keep the handle on the file until you kill the process.

Answered by Nicolas Cadieux on February 12, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP