You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is about as minimal of an example as I could extract from my code base. After terminating the process wal.db-shm and wal.db-wal are still there. The order of the close calls matters.
The WAL file is created when the first connection to the database is opened and is normally removed when the last connection to the database closes. However, if the last connection does not shutdown cleanly, the WAL file will remain in the filesystem and will be automatically cleaned up the next time the database is opened.
I assume for readonly: true the connection is not properly cleaned up? That's why closing the readonly connection last does not clean up. The code contains two places that each individually change the behavior.
constDatabase=require('better-sqlite3');constwrite=newDatabase('./wal.db');// <-----------------------// If you remove readonly then the files are properly removed.// <-----------------------constread=newDatabase('./wal.db',{fileMustExist: true,readonly: true});write.pragma('journal_mode = WAL');read.pragma('journal_mode = WAL');write.exec('CREATE TABLE my_favorite_numbers (value TEXT)');write.exec('INSERT INTO my_favorite_numbers VALUES (3)');process.on('exit',()=>{console.log('Exiting');// <------------------------------// If you switch these two lines then the files are properly removed.// <------------------------------write.close();read.close();});process.on('SIGHUP',()=>process.exit(128+1));process.on('SIGINT',()=>process.exit(128+2));process.on('SIGTERM',()=>process.exit(128+15));// Keep runningsetTimeout(function(){},100000);
The text was updated successfully, but these errors were encountered:
However, if the last client did not call sqlite3_close() before it shut down, or if the last client to disconnect was a read-only client, then the final cleanup operation does not occur and the shm and wal files may still exist on disk even when the database is not in use.
This is about as minimal of an example as I could extract from my code base. After terminating the process
wal.db-shm
andwal.db-wal
are still there. The order of theclose
calls matters.https://sqlite.org/tempfiles.html
I assume for
readonly: true
the connection is not properly cleaned up? That's why closing the readonly connection last does not clean up. The code contains two places that each individually change the behavior.The text was updated successfully, but these errors were encountered: