-
-
Notifications
You must be signed in to change notification settings - Fork 79
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fails to open database if opened at any point with a third party tool #119
Comments
Well, with several different components involved it is often difficult to track down where exactly the problem lies and where it needs to be resolved.
Using WAL mode can be a bit tricky sometimes. First question: which version of SQLiteStudio are you using? There were WAL related problems in early SQLite3MultipleCiphers versions. Unfortunately, SQLiteStudio updated its SQLite3MultipleCiphers component only in version 3.4.0 (released in November 2022). Prior versions of SQLiteStudio used a SQLite3MultipleCiphers version with broken WAL support. That is, in case you still use an old SQLiteStudio version upgrading to the latest version maybe solves the problem.
Hm, there exists no
What happens, if you reopen the database repeatedly from your application (without using any other application to access the database)? Does that work? In one of your posts in m4heshd/better-sqlite3-multiple-ciphers#62 you say that the
This is a bit strange. Usually this only happens, if a database file was created without encryption and you then set a password for an already existing unencrypted database. Of course, this will fail, because no password is required to access an unencrypted database file. To encrypt an unencrypted database file you have to use
This is really weird. AFAIK this can only happen if different database connections interfer with each other.
At the moment I have not enough information to answer these questions. |
Thanks for your reply! I'm not sure what layer the problem exists at, or if it's just me being silly. However, I very much so appreciate your help! I've spent way too much time trying to solve this before opening github issues. I'm on v3.4.4 of SQLiteStudio.
I guess I need to validate things more. I was going based on https://gist.github.com/phiresky/978d8e204f77feaa0ab5cca08d2d5b27 which suggests I modified the statements to have So, I believe I've solved that?
I managed to fix the persistence of What's interesting is I may have uncovered some additional things that are breaking this, that didn't break it when I was using the non-crypto lib of SQLite. It could be all user error. When starting the application, I run So, based on the above, I made a change to how the application opens. It only runs the commands if it's a new database and has not had After a bit more testing, it seems that with the original SQLite3 build they were just ignored because they were set after the
const pragma = this.db.pragma('journal_mode');
if (pragma !== 'wal') {
this.db.pragma('mmap_size = 3000000');
this.db.pragma('page_size = 32768');
this.db.pragma('temp_store = memory');
this.db.pragma('journal_mode = WAL');
}
Good note on this, I actually have to build a migration to move existing databases to this encrypted format. |
I THINK I'VE FOUND IT. A bit more testing, the BreaksGenerate a new
Then I run the below query, and it crashes SQLiteStudio and prevents the db from ever being read again.
When you close / reopen the file it returns:
WorksSame as above, but removing the
So, I guess my question really boils down to am i using |
I'm always glad to get feedback and/or bug reports - it's quite often a chance to enhance the software or to fix subtle bugs. Yes, sometimes it's simply a misuse of a feature, but sometimes we find real bugs.
Good. So this should not be the cause of trouble.
Maybe a typo. Just
Personally, I would leave the auto commit mode at its default. If you have lots of data and massive changes (really many insertions and deletions) then it is better to explicitly run
There are occasions when WAL files remain on disk - for example, if an application crashes without closing. Removing those WAL files is calling for trouble. You may end up with corrupted database files or lost data.
Well, there may exist SQLite features that can't be combined with encryption or need special handling. There are so many SQLite options that it is hardly possible to test all possible combinations.
I have to admit that I have never tested
WAL mode is persistent. That is, if it was set once, it will automatically set on opening the database file again. Which journal mode is active, can be queried with
That's correct. For example, the page size can't be changed when WAL mode is enabled. That is, the order of pragmas matters. |
As stated in my previous post it may be that it is not possible to combine encryption with memory mapping. I will have to check the code and will report my findings here. However, this may take some time.
Yes, that's indeed the question. Looking at your experiments chances are high that |
No rush, if it's not supported it's not supported! I just didn't know that, and it was a part of my config and really throwing me off here. I spent way too much time figuring that out!
Any specific reason why? I know it's not related to this issue, but i'm curious now. |
I made a quick check of the old SQLite code (when the encryption API was still included in it). And my suspicion was confirmed that memory mapping can't be combined with encryption. I will try to add a check in the current implementation, so that memory mapping can be used for unencrypted databases, but not for encrypted ones.
Well, performing a VACUUM operation is an expensive operation - in time and space. The gain is often only small, because SQLite does a fairly good job in managing the database pages. And on SSD storage (that is very common nowadays) fragmentation plays only a minor role. Therefore enabling auto vacuum brings more costs than gain. It is even possible that fragmentation increases. For databases with a high frequency of inserts and deletes it can still make sense to manually perform a VACUUM from time to time to compact the database file. |
Thanks!
This makes sense, I have a large amount of changes that happen while the db is open. When closing I run I appreciate your help on pinning this issue! Feel free to leave this open to track adding |
I leave this issue open, until it is resolved. |
- Fixed issue #118 - tvOS/watchOS compilation errors. On Apple platforms the function SecRandomCopyBytes() will now be used instead of getentropy(). - Fixed issue #119 - "PRAGMA mmap_size" conflicts with encrypted databases, a check has been added to allow this pragma for unencrypted databases. - Added "PRAGMA memory_security" to allow to clear memory before it is freed. This feature can have a considerable impact on performance and is therefore disabled by default.
I released version 1.7.0. If So, I'm closing this issue. |
This may be an issue listed, i searched and couldn't find anything exact. Also posted in the sqlite library I use that pulls this package - m4heshd/better-sqlite3-multiple-ciphers#62
I seem to be having a problem when connecting to the database via SQLiteStudio, it breaks something. I assume it's my WAL archive.
Config when opening the db:
Steps to break it:
error: SqliteError: database disk image is malformed
Alternate steps to break (if the top has a fix, this is not relevant)
journal_mode = WAL
Here it does not fail instantly, though. It actually does half the queries and then starts to fail.
Questions:
The text was updated successfully, but these errors were encountered: