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.
Asked
Active
Viewed 5,907 times
22
Yaroslav
- 854
- 6
- 17
1 Answers
24
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-walfile holds the WAL for the current connection; this file keeps a progressive data log of the transactional state of the DB betweenCOMMITs (orROLLBACKs) - the
*.gpkg-shmSHhared Memory file manages concurrent access to the DB via an index to the WAL
geozelot
- 30,050
- 4
- 32
- 56
-
4The "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;https://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. – user30184 Apr 15 '21 at 08: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? – Yaroslav Apr 16 '21 at 09: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,UPDATEor 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. – geozelot Apr 16 '21 at 10:50
walis the write ahead log, no idea whatshmis though – Ian Turton Apr 15 '21 at 07:29