14

I have a file, polygons.gpkg that I am using in QGIS. Its original file size is 48MB.

When I do nothing except delete a handful of the attribute table's fields, I expect the file size to decrease. However, it instead increases to 85MB.

After deleting the fields, if I export as a new gpkg (Export > Save Features As), the new file is only 38MB. This result makes sense to me.

Is there a way to "clean up" whatever extra data is getting stored in the original polygons.gpkg so that its size on disk is reduced? That would be a more convenient solution than exporting anew...

1 Answer 1

22

** EDIT: You can now do this in the QGIS file browser by right clicking on the .gpkg and selecting vacuum **

You should VACUUM your database to reduce the size of the database after deleting rows/ dropping tables.

You can use the DB Manager core plugin. Open DB Manager and select your GeoPackage connection from the tree on the left. Select the spanner icon and input the SQL command.

DB Manager SQL window

Alternatively you can use ogrinfo from the command line:

ogrinfo your_db_file.gpkg -sql "VACUUM"

or sqlite

sqlite3 your_db_file.gpkg 'VACUUM;'

The latter solutions are useful to create a cron job (Linux) or scheduled task (Windows) to VACUUM your database automatic.

1
  • 7
    I've noticed that you can now do this in the QGIS file browser by right clicking on the .gpkg and selecting vacuum.
    – Baswein
    Commented Apr 30, 2020 at 20:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.