My advice is to upgrade to >=2.18.1. Version 2.18.1 introduced a feature where right clicking a layer and selecting save as, then choosing an existing gpkg file, now gives you the choice of either overwriting the whole file or instead appending the layer as a new layer within the geopackage. [1] (ie don't use the DB Manager plugin, just use the built in 'save as' layer function)
[1] See https://github.com/qgis/QGIS/commit/85fbc4a7d902c12794fbbfeec5ce43d8a2c0887e
You can remove raster from GeoPackage with ogrinfo but it is a bit tricky because each raster table has also references in several metadata tables.
EDIT
GeoPackage has foreign key constraints which can prevent user from deleting some data. There are two alternatives to make deletes to success:
- Delete stuff in right order, or
- Disable foreign key check from SQLite database before deletes.
Here are ogrinfo commands ordered so that foreign keys don't make any trouble.
ogrinfo -sql "delete from gpkg_tile_matrix_set where table_name='raster2'" droptest.gpkg
ogrinfo -sql "delete from gpkg_tile_matrix where table_name='raster2'" droptest.gpkg
ogrinfo -sql "delete from gpkg_metadata_reference where table_name='raster2'" droptest.gpkg
ogrinfo -sql "delete from gpkg_contents where table_name='raster2'" droptest.gpkg
ogrinfo -sql "drop table raster2" droptest.gpkg
In my original answer I deleted things from the database in alphabetic order and I had to disable the foreign key check with a specific GDAL config option.
Drop the tiles
ogrinfo -sql "drop table raster2" droptest.gpkg
Remove line from gpkg_contents
ogrinfo -sql "delete from gpkg_contents where table_name='raster2'" droptest.gpkg
Remove references from gpkg_metadata_reference table. Ogrinfo does not accept the command with the same syntax as above because the SQLite database is now in invalid state because of orphaned foreign key constraints and you must use a special GDAL configuration option to override the validity check.
ogrinfo -sql "delete from gpkg_metadata_reference where table_name='raster2'" droptest.gpkg --config OGR_GPKG_FOREIGN_KEY_CHECK OFF
Remove references from gpkg_tile_matrix table.
ogrinfo -sql "delete from gpkg_tile_matrix where table_name='raster2'" droptest.gpkg --config OGR_GPKG_FOREIGN_KEY_CHECK OFF
Remove references from gpkg_tile_matrix_set table
ogrinfo -sql "delete from gpkg_tile_matrix_set where table_name='raster2'" droptest.gpkg --config OGR_GPKG_FOREIGN_KEY_CHECK OFF
Now the raster table and all the references have been deleted. As a final step it might be good to vacuum the database.
ogrinfo -sql "VACUUM" droptest.gpkg
However, if the database is very big VACUUM will be slow. It could actually be faster to copy all the raster layers except the one that you want to drop into a new GeoPackage with gdal_translate. If you have also lots of vector layers in your GeoPackage that option may not be so fascinating. For simplifying the deletion you can save all the ogrinfo commands into a batch file and give the name of the raster file that you want to drop as a variable.
Best Answer
Use gdal_translate to convert your raster data set to geopackage you will need to also use gdaladdo to build zoom levels/overviews. You can also convert you folder of XYZ Google tiles to geopackage with tiles2gpkg_parallel.py