If your server log file is showing SQLite errors like the following then your library.db needs to be rebuilt in order to restore proper functionality. 


'SQLitePCL.pretty.SQLiteException'

What can cause this to happen

Typical causes of this are sudden and abrupt terminations of the Emby server process, such as a power loss, operating system crash, force killing the server process, etc. 

Find Location of Database Files

First we need to identify the location of your database files which is usually easiest to find looking at the Dashboard web view at other file locations


Windows example

Synology 7 example


If you look at the entry for "logs" you will see the path ends in "logs". Change "logs" to "data" and you would have from these two examples:


C:\Users\Administrator\AppData\Roaming\Emby-Server\programdata\data (windows)
or
/var/packages/EmbyServer/var/data (synology)


This is where you will find the Emby database files which have an extension of .db. 

Solutions to Try in This Order

Remove Database Locks

1. Shutdown Emby

2. Navigate to the folder containing your database file

3. Delete library.db-shm & library.db-wal

4. Restart Emby

Check you server log for SQLite errors and only continue to the next step if needed

Check Database Integrity and Recover Database

This step will require the use of a SQLite editor which can be downloaded from sqlite.org. If you prefer a graphical based editor you can download DB Browser for SQLite which is available for most platforms.

Run Integrity Check

Open the library.db database and run the following SQL command
PRAGMA integrity_check
If using the command line tool try the following
sqlite3 library.db "PRAGMA integrity_check"

This should return an integrity_check back of "OK" with no errors reported. If errors are reported we need to recover the database.

Recover library.db

What we need to do is dump all data from the database to a text file and then reload this back to another freshly created database. This can be done via a single command using the SQLite command line editor.

Run the following command line:


1. sqlite3 library.db ".recover" | sqlite3 library-recovered.db
(this may take a while to run so please wait for it to finish)


2. We will now check the integrity of our recovered database (as above) using


sqlite3 library-recovered.db "PRAGMA integrity_check"


This should return an integrity_check back of "OK" with no errors reported. If errors are reported please report this in the forum before proceeding to Reset the Library Database. If OK and no errors are reported continue with step 3.


3. Make a copy of both library.db and library-recovered.db

4. Rename library.db to library.old

5. Rename library-recoved.db to library.db

6. Restart Emby Server

Check you server log for SQLite errors and only continue to the next step if needed

Steps to Reset Library Database & Load Fresh

1. Shutdown Emby

2. Change to the database location found above containing your database files

3. Rename library.db to library.corrupt

4. Restart Emby

5. Run a Full Library Scan