Database is malformed but no further information

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Database is malformed but no further information

mailing lists
Hi,

when I load my database into sqlite3 and run an integrity check I only get the error message: Error: database disk image is malformed

I do not get any further information. What causes this simple error message? I expected to get some more information what is actually the reason why SQLite3 thinks that it is malformed. Interestingly I can do a dump to a SQL file for the (whole?) database.

I would really like to find out the root cause of this issue because I experience a corrupt database once a while on iOS. This only happens when the app is terminated while running when the iDevice switches off due to low battery issues.

Best regards,
Hartwig

_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|

Re: Database is malformed but no further information

Chris Brody
My understanding is that mobile apps are not 100% predictable since
they may be randomly suspended or terminated, at any point of time.
The operating system should give a signal before suspending or
terminating but I would not trust it. Goes for Android, iOS, Windows
Mobile, and others.

To be extra safe I would use custom SQLite3 build with
-DSQLITE_DEFAULT_SYNCHRONOUS=3 build setting as documented in the
following places:
* https://www.sqlite.org/compile.html#extra_durable
* https://www.sqlite.org/compile.html#default_synchronous

Here is some recommended reading:
* https://www.sqlite.org/howtocorrupt.html
* http://sqlite.1065341.n5.nabble.com/Is-WAL-mode-more-robust-against-corruption-td99624.html
* http://sqlite.1065341.n5.nabble.com/Integrity-Check-Failure-Handling-td70289.html
* http://blog.niklasottosson.com/?p=852
* http://www.froebe.net/blog/2015/05/27/error-sqlite-database-is-malformed-solved/

Chris

https://www.linkedin.com/in/chrisbrody/

On Tue, Jun 12, 2018 at 6:21 PM skywind mailing lists
<[hidden email]> wrote:

>
> Hi,
>
> when I load my database into sqlite3 and run an integrity check I only get the error message: Error: database disk image is malformed
>
> I do not get any further information. What causes this simple error message? I expected to get some more information what is actually the reason why SQLite3 thinks that it is malformed. Interestingly I can do a dump to a SQL file for the (whole?) database.
>
> I would really like to find out the root cause of this issue because I experience a corrupt database once a while on iOS. This only happens when the app is terminated while running when the iDevice switches off due to low battery issues.
>
> Best regards,
> Hartwig
>
> _______________________________________________
> sqlite-users mailing list
> [hidden email]
> http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|

Re: Database is malformed but no further information

Simon Slavin-3
In reply to this post by mailing lists
On 12 Jun 2018, at 11:20pm, skywind mailing lists <[hidden email]> wrote:

> when I load my database into sqlite3 and run an integrity check I only get the error message: Error: database disk image is malformed
>
> I do not get any further information. What causes this simple error message?

It means that there's no obvious cause.  Which usually means that rather than a tiny detail being wrong (a single row pointer points to the wrong row) a big important thing is wrong (a page belongs to an index when it should belong to a table).

However, this is often caused by the database not being closed properly. Which suggests the database was written on a small device with no warning of quit (e.g. mobile phone) rather than a computer with a 'Quit' command.

So copy the database to a computer, and use the shell tool to make a trivial change to it, for example create a new table.  Then quit the shell tool properly with ".quit".

Then reopen the database and do another integrity check.  Does it still report the same error ?

Simon.
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|

Re: Database is malformed but no further information

Clemens Ladisch
In reply to this post by Chris Brody
Chris Brody wrote:
> My understanding is that mobile apps are not 100% predictable since
> they may be randomly suspended or terminated, at any point of time.

But SQLite is designed so that even killing the process will not
corrupt the database, as long as the storage device works correctly.

> On Tue, Jun 12, 2018 at 6:21 PM skywind mailing lists <[hidden email]> wrote:
>> This only happens when the app is terminated while running when the
>> iDevice switches off due to low battery issues.

Some flash devices corrupt not only the pages currently being written
to, but also other, unrelated data.  There's nothing software can do
to protect against that.

>> when I load my database into sqlite3 and run an integrity check
>> I only get the error message: Error: database disk image is malformed

Try the latest version of the sqlite3 shell.


Regards,
Clemens
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users