As pointed out in the links above, a possible solution is to add configuration option OGR_SQLITE_JOURNAL=DELETE to QGIS (and then restart QGIS), then WAL will not be used any more for the GeoPackage file and the gpkg-wal and gpkg-shm files will not be created.
Documentation seems to be rather scarce on that configuration option, so I thought I would point this out here, as part of the knowledge sharing, until it is properly documented somewhere (e.g. in the QGIS documentation).
With the default QGIS settings, when a GeoPackage file is opened, two extra files are created as well, a gpkg-wal and a gpkg-shm file. It has something to do with a feature of SQLite called Write-Ahead Log (WAL), see also https://www.sqlite.org/wal.html. In certain situations that may give issues. See e.g. https://www.mail-archive.com/qgis-user@lists.osgeo.org/msg45132.html and http://osgeo-org.1560.x6.nabble.com/Re-Something-to-think-about-GeoPackage-and-WAL-td5303139.html.
As pointed out in the links above, a possible solution is to add configuration option OGR_SQLITE_JOURNAL=DELETE to QGIS (and then restart QGIS), then WAL will not be used any more for the GeoPackage file and the gpkg-wal and gpkg-shm files will not be created.
Documentation seems to be rather scarce on that configuration option, so I thought I would point this out here, as part of the knowledge sharing, until it is properly documented somewhere (e.g. in the QGIS documentation).