In QGIS, if I open some GeoPackage file like mylayers.gpkg
, it will create two files named mylayers.gpkg-shm
and mylayers.gpkg-wal
in the same folder. After I close QGIS, these files disappear. I understand that they are temporary files, but I wonder what their purpose is.
1 Answer
As the SQLite core of a GeoPackage is a single-file based RDB, it needs to utilize temporary support structures to guarantee atomic transaction management.
SQLite supports different mechanics to achieve this, and the QGIS specific GPKG implementation defaults to Write Ahead Logging (WAL), available in SQLite > 3.7, where
- the
*.gpkg-wal
file holds the WAL for the current connection; this file keeps a progressive data log of the transactional state of the DB betweenCOMMIT
s (orROLLBACK
s) - the
*.gpkg-shm
SHhared Memory file manages concurrent access to the DB via an index to the WAL
-
3The "GPKG implementation" above refers specifically to QGIS GPKG implementation. It sets the GeoPackage databases into WAL mode, if they are not already, with pragma command
PRAGMA journal_mode=WAL;
sqlite.org/wal.html#activating_and_configuring_wal_mode. What users should know is not to send .gpkg files to other users before the .wal and .shm files have disappeared. Apr 15, 2021 at 8:08 -
-
1Does it mean that two or more desktop users can simultaneously edit the same GeoPackage file - stored, for example, on a shared network disk - without corrupting data?– YaroslavApr 16, 2021 at 9:28
-
2@Yaroslav Yes, SQLite is ACID compliant and concurrency save for readers, but supports only a single writer process at a time; if a transaction is open running
INSERT
,UPDATE
or DDL statements, other transactions have to wait until the current transaction was committed/rollback-ed. In practice, though, in a QGIS edit session, the lock happens at save time, so you won't feel much of this limitation.– geozelotApr 16, 2021 at 10:50
wal
is the write ahead log, no idea whatshm
is though