14

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.

2
  • 1
    not sure but something related with write protection in case of concurrent/simultaneous file access ...
    – Snaileater
    Apr 15 at 7:21
  • wal is the write ahead log, no idea what shm is though
    – Ian Turton
    Apr 15 at 7:29
15

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 between COMMITs (or ROLLBACKs)
  • the *.gpkg-shm SHhared Memory file manages concurrent access to the DB via an index to the WAL
4
  • 2
    The "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.
    – user30184
    Apr 15 at 8:08
  • @user30184 amended.
    – geozelot
    Apr 15 at 8:56
  • Does 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 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.
    – geozelot
    Apr 16 at 10:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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