Good day,
I have seen some disk “sqlite3.DatabaseError: database disk image is malformed” errors on kolibri installations. Is there a way to repair or run a command to fix this error?
Thank you kindly.
Good day,
I have seen some disk “sqlite3.DatabaseError: database disk image is malformed” errors on kolibri installations. Is there a way to repair or run a command to fix this error?
Thank you kindly.
Hi Bryan, you can find the instructions to fix the malformed database in Kolibri user guide.
Hi @jredrejo,
After running the two commands, (this is usually the command we use when you get the error message when your db is corrupted after updating to a new kolibri version), but please see the output below after rebooting:
kolibri@tsp:~$ sqlite3 ~/.kolibri/db.sqlite3 .dump | sqlite3 fixed.db
kolibri@tsp:~$ cp fixed.db ~/.kolibri/db.sqlite3
kolibri@tsp:~$ sudo reboot now
Connection to 172.18.0.2 closed by remote host.
Connection to 172.18.0.2 closed.
[~/Documents] $ ssh kolibri@172.18.0.2
kolibri@172.18.0.2’s password:
Welcome to Ubuntu 16.04.5 LTS (GNU/Linux 4.4.0-138-generic x86_64)
0 packages can be updated.
0 updates are security updates.
New release ‘18.04.1 LTS’ available.
Run ‘do-release-upgrade’ to upgrade to it.
Last login: Fri Nov 9 10:20:09 2018 from 172.18.0.254
kolibri@tsp:~$ kolibri status
INFO Running Kolibri with the following settings: kolibri.deployment.default.settings.base
Stopped (1)
kolibri@tsp:~$ kolibri start
INFO Running Kolibri with the following settings: kolibri.deployment.default.settings.base
INFO Sqlite database Vacuum finished.
INFO Running update routines for new version…
0 static files copied to ‘/var/kolibri/.kolibri/static’, 770 unmodified.
Operations to perform:
Apply all migrations: admin, auth, content, contenttypes, device, discovery, exams, kolibriauth, lessons, logger, morango, sessions
Running migrations:
No migrations to apply.
Installed 2 object(s) from 1 fixture(s)
INFO Importing ContentTag data
INFO Importing ContentNode_tags data
INFO Importing ContentNode_related data
INFO Importing ContentNode_has_prerequisite data
INFO Importing ContentNode data
INFO Importing Language data
INFO Importing File data
INFO Importing LocalFile data
INFO Importing AssessmentMetaData data
Traceback (most recent call last):
File “/usr/lib/python3/dist-packages/kolibri/dist/sqlalchemy/engine/base.py”, line 1193, in _execute_context
context)
File “/usr/lib/python3/dist-packages/kolibri/dist/sqlalchemy/engine/default.py”, line 509, in do_execute
cursor.execute(statement, parameters)
sqlite3.DatabaseError: database disk image is malformed
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File “/usr/bin/kolibri”, line 9, in
load_entry_point(‘kolibri==0.11.0’, ‘console_scripts’, ‘kolibri’)()
File “/usr/lib/python3/dist-packages/kolibri/utils/cli.py”, line 664, in main
start(port, daemon=daemon)
File “/usr/lib/python3/dist-packages/kolibri/utils/cli.py”, line 273, in start
update()
File “/usr/lib/python3/dist-packages/kolibri/utils/cli.py”, line 253, in update
update_channel_metadata()
File “/usr/lib/python3/dist-packages/kolibri/core/content/utils/annotation.py”, line 46, in update_channel_metadata
import_channel_from_local_db(channel_id)
File “/usr/lib/python3/dist-packages/kolibri/core/content/utils/channel_import.py”, line 675, in import_channel_from_local_db
import_manager.import_channel_data()
File “/usr/lib/python3/dist-packages/kolibri/core/content/utils/channel_import.py”, line 522, in import_channel_data
raise e
File “/usr/lib/python3/dist-packages/kolibri/core/content/utils/channel_import.py”, line 513, in import_channel_data
unflushed_rows = self.table_import(model, row_mapper, table_mapper, unflushed_rows)
File “/usr/lib/python3/dist-packages/kolibri/core/content/utils/channel_import.py”, line 371, in table_import
result = self.raw_attached_sqlite_table_import(model, row_mapper, table_mapper, unflushed_rows)
File “/usr/lib/python3/dist-packages/kolibri/core/content/utils/channel_import.py”, line 292, in raw_attached_sqlite_table_import
self.destination.session.execute(text(query))
File “/usr/lib/python3/dist-packages/kolibri/dist/sqlalchemy/orm/session.py”, line 1176, in execute
bind, close_with_result=True).execute(clause, params or {})
File “/usr/lib/python3/dist-packages/kolibri/dist/sqlalchemy/engine/base.py”, line 948, in execute
return meth(self, multiparams, params)
File “/usr/lib/python3/dist-packages/kolibri/dist/sqlalchemy/sql/elements.py”, line 269, in _execute_on_connection
return connection._execute_clauseelement(self, multiparams, params)
File “/usr/lib/python3/dist-packages/kolibri/dist/sqlalchemy/engine/base.py”, line 1060, in _execute_clauseelement
compiled_sql, distilled_params
File “/usr/lib/python3/dist-packages/kolibri/dist/sqlalchemy/engine/base.py”, line 1200, in _execute_context
context)
File “/usr/lib/python3/dist-packages/kolibri/dist/sqlalchemy/engine/base.py”, line 1413, in _handle_dbapi_exception
exc_info
File “/usr/lib/python3/dist-packages/kolibri/dist/sqlalchemy/util/compat.py”, line 265, in raise_from_cause
reraise(type(exception), exception, tb=exc_tb, cause=cause)
File “/usr/lib/python3/dist-packages/kolibri/dist/sqlalchemy/util/compat.py”, line 248, in reraise
raise value.with_traceback(tb)
File “/usr/lib/python3/dist-packages/kolibri/dist/sqlalchemy/engine/base.py”, line 1193, in _execute_context
context)
File “/usr/lib/python3/dist-packages/kolibri/dist/sqlalchemy/engine/default.py”, line 509, in do_execute
cursor.execute(statement, parameters)
sqlalchemy.exc.DatabaseError: (sqlite3.DatabaseError) database disk image is malformed [SQL: ‘REPLACE INTO content_assessmentmetadata (id, assessment_item_ids, number_of_assessments, mastery_model, randomize, is_manipulable, contentnode_id) SELECT source.id, source.assessment_item_ids, source.number_of_assessments, source.mastery_model, source.randomize, source.is_manipulable, source.contentnode_id FROM sourcedb.content_assessmentmetadata AS source’] (Background on this error at: http://sqlalche.me/e/4xp6)
kolibri@tsp:~$ kolibri status
INFO Running Kolibri with the following settings: kolibri.deployment.default.settings.base
Stopped (1)
kolibri@tsp:~$
Hi, it seems the automatic repair has not worked.
If your database does not contain confidential data, can you attach the ~/.kolibri/db.sqlite3
file here so I can take a look?
One side note: you don’t need to reboot the whole server after doing the db repair commands,
sudo service kolibri restart
will restart Kolibri.
Hi,
I will upload the db file shortly.
Thanks for the side not. I like to start fresh and be sure everything is intact, hence the reboot
Hi,
Please see link with db file.
Please let me know.
Thank you.
Hi @jredrejo
Don’t look into this any further, I will let you know on an update.
I was troubleshooting and wanted to know which Django version is installed. I switched to root user and ran the command: “kolibri manage import django” then the below output was displayed. It might be a permission error where kolibri user might not have all the needed permissions.
I am re-installing the image and starting from scratch. I will let you know the outcome and what the error was. [I don’t want you to waste unnecessary time due to my uncertainty].
oot@tsp:/var/kolibri# kolibri manage import django
INFO Running Kolibri with the following settings: kolibri.deployment.default.settings.base
INFO Kolibri running for the first time.
INFO We don’t yet use pre-migrated database seeds, so you’re going to have to wait a bit while we create a blank database…
Operations to perform:
Apply all migrations: admin, auth, content, contenttypes, device, discovery, exams, kolibriauth, lessons, logger, morango, sessions
Running migrations:
Applying kolibriauth.0001_initial… OK
Applying contenttypes.0001_initial… OK
Applying admin.0001_initial… OK
Applying admin.0002_logentry_remove_auto_add… OK
Applying contenttypes.0002_remove_content_type_name… OK
Applying auth.0001_initial… OK
Applying auth.0002_alter_permission_name_max_length… OK
Applying auth.0003_alter_user_email_max_length… OK
Applying auth.0004_alter_user_username_opts… OK
Applying auth.0005_alter_user_last_login_null… OK
Applying auth.0006_require_contenttypes_0002… OK
Applying auth.0007_alter_validators_add_error_messages… OK
Applying auth.0008_alter_user_username_max_length… OK
Applying content.0001_initial… OK
Applying content.0002_channelmetadatacache_last_updated… OK
Applying content.0003_auto_20170607_1212… OK
Applying content.0004_auto_20170825_1038… OK
Applying content.0005_auto_20171009_0903… OK
Applying content.0006_auto_20171128_1703… OK
Applying content.0007_auto_20180212_1155… OK
Applying content.0008_contentnode_coach_content… OK
Applying content.0009_auto_20180410_1139… OK
Applying content.0008_auto_20180429_1709… OK
Applying content.0010_merge_20180504_1540… OK
Applying content.0011_auto_20180907_1017… OK
…
…
Copying ‘/usr/lib/python3/dist-packages/kolibri/plugins/style_guide/static/style_guide_module/style_guide_module-0.11.0.js’
Copying ‘/usr/lib/python3/dist-packages/kolibri/plugins/style_guide/static/style_guide_module/style_guide_module0.9.0b3.dev+git-5-g1c6ec06.css.dpkg-new’
Copying ‘/usr/lib/python3/dist-packages/kolibri/plugins/style_guide/static/style_guide_module/style_guide_module0.8.0b2.css.dpkg-new’
Copying ‘/usr/lib/python3/dist-packages/kolibri/plugins/style_guide/static/style_guide_module/style_guide_module-0.8.0b1.dev+git-161-g3db1e6f.js.dpkg-new’
Copying ‘/usr/lib/python3/dist-packages/kolibri/plugins/style_guide/static/style_guide_module/style_guide_module0.11.0.css’
767 static files copied to ‘/root/.kolibri/static’.
Operations to perform:
Apply all migrations: admin, auth, content, contenttypes, device, discovery, exams, kolibriauth, lessons, logger, morango, sessions
Running migrations:
No migrations to apply.
Installed 2 object(s) from 1 fixture(s)
Unknown command: ‘import’
Type ‘kolibri manage help’ for usage.
root@tsp:/var/kolibri# kolibri status
INFO Running Kolibri with the following settings: kolibri.deployment.default.settings.base
Stopped (1)
root@tsp:/var/kolibri# kolibri start
INFO Running Kolibri with the following settings: kolibri.deployment.default.settings.base
INFO Sqlite database Vacuum finished.
INFO Running update routines for new version…
0 static files copied to ‘/root/.kolibri/static’, 767 unmodified.
Operations to perform:
Apply all migrations: admin, auth, content, contenttypes, device, discovery, exams, kolibriauth, lessons, logger, morango, sessions
Running migrations:
No migrations to apply.
Installed 2 object(s) from 1 fixture(s)
INFO Running ‘kolibri start’ as daemon (system service)
INFO Kolibri running on:
http://172.18.0.2:8080/
http://127.0.0.1:8080/
INFO Going to daemon mode, logging to /root/.kolibri/server.log
root@tsp:/var/kolibri# kolibri status
INFO Running Kolibri with the following settings: kolibri.deployment.default.settings.base
OK, running (0)
Kolibri running on:
http://172.18.0.2:8080/
http://127.0.0.1:8080/
But this is the root user, and can’t remember if this was still an old image, therefore i’m starting over.
Hi @jredrejo,
After installing a fresh image, updating the system, Kolibri updated to v0.11.0 successfully.
Version: 0.11.0
OS: Linux-4.4.0-138-generic-x86_64-with-Ubuntu-16.04-xenial
Installer: apt
Server: Kolibri internal server
Database: /var/kolibri/.kolibri/db.sqlite3
Device name: tsp
Free disk space: 915 GB
Server time: Fri Nov 09 2018 13:35:48 GMT+0200 (South Africa Standard Time)
Server timezone: Africa/Johannesburg
Thanks so much for your assistance in this matter. Much appreciate it.