Hoping for help with DB corruption

So I’ve been having some odd issues getting things playing with Plex. I figured I’d check on the database. It seems hosed beyond my ability to repair (but PMS is up and limping). I’ve tried the repair a corrupt db article on the db itself as well as all four of the backups. I get the following error from the integrity check. If I ignore the errors, the dump restore returns a db size of 0kb (with no errors).

Please help.

*** in database main ***
On tree page 18986 cell 12: Rowid 53 out of order
On tree page 18986 cell 10: Rowid 56 out of order
On tree page 18986 cell 8: Rowid 102 out of order
On tree page 18986 cell 7: Rowid 117 out of order
On tree page 18986 cell 5: Rowid 100 out of order
On tree page 18986 cell 3: Rowid 98 out of order
On tree page 18986 cell 2: Rowid 121520 out of order
Fragmentation of 2272 bytes reported as 0 on page 18986
Page 78715: btreeInitPage() returns error code 11
Page 78714: btreeInitPage() returns error code 11
Page 78713: btreeInitPage() returns error code 11
On tree page 78712 cell 10: Rowid 58 out of order
On tree page 78712 cell 9: Rowid 58 out of order
On tree page 78712 cell 7: Rowid 100 out of order
On tree page 78712 cell 4: Rowid 51 out of order
On tree page 78712 cell 2: Rowid 52 out of order
On tree page 78712 cell 1: Rowid 12814 out of order
Multiple uses for byte 3908 of page 78712
On tree page 44 cell 31: Rowid 1403 out of order
Page 72800: btreeInitPage() returns error code 11
Page 72799: btreeInitPage() returns error code 11
Page 72798: btreeInitPage() returns error code 11
Page 72246: btreeInitPage() returns error code 11
Page 72245: btreeInitPage() returns error code 11
Page 72244: btreeInitPage() returns error code 11
Page 71990: btreeInitPage() returns error code 11
Page 71989: btreeInitPage() returns error code 11
Page 71988: btreeInitPage() returns error code 11
Fragmentation of 673 bytes reported as 0 on page 71987
On tree page 71886 cell 269: Rowid 264177 out of order
Page 71957: btreeInitPage() returns error code 11
Page 71956: btreeInitPage() returns error code 11
On tree page 71955 cell 0: Rowid 105 out of order
Fragmentation of 1998 bytes reported as 0 on page 71955
On tree page 71886 cell 237: Rowid 264008 out of order
Page 71953: btreeInitPage() returns error code 11
Page 71952: btreeInitPage() returns error code 11
Fragmentation of 1333 bytes reported as 0 on page 71951
On tree page 71886 cell 233: Rowid 263980 out of order
database disk image is malformed

Based on another thread, I also edited the dump.sql file to COMMIT rather than ROLLBACK. This gave me a full .db file, but did have the following error:

Error: near line 1790425: no such collation sequence: icu_root

What are you using to try to do the repair? I’m told you need to use the built in sqlite rather than an external one

Using sqlite3. I followed the kb article

I too am seeing icu_root errors trying to use sqlite3 on Fedora 32. This only started happening very recently. I even tried to compile the icu extension for sqlite, which loads fine, but does not seem to fix the problem.

you need to use the built in sqlite rather than an external one

Unfortunately only the library files are included in the plex RPM package:

$ rpm -ql plexmediaserver  | egrep "(sqlite|icu)"
/usr/lib/plexmediaserver/Resources/Python/lib/python2.7/lib-dynload/_sqlite3.so
/usr/lib/plexmediaserver/Resources/Python/lib/python2.7/sqlite3
/usr/lib/plexmediaserver/Resources/Python/lib/python2.7/sqlite3/__init__.py
/usr/lib/plexmediaserver/Resources/Python/lib/python2.7/sqlite3/dbapi2.py
/usr/lib/plexmediaserver/Resources/Python/lib/python2.7/sqlite3/dump.py
/usr/lib/plexmediaserver/lib/libicudataplex.so.67
/usr/lib/plexmediaserver/lib/libicui18nplex.so.67
/usr/lib/plexmediaserver/lib/libicuioplex.so.67
/usr/lib/plexmediaserver/lib/libicuucplex.so.67
/usr/lib/plexmediaserver/lib/libsoci_sqlite3.so
/usr/lib/plexmediaserver/lib/libsqlite3.so

Is there any way to get a compiled client binary that utilizes these files?

Is this manifesting itself in other ways in your PMS? I’ve suddenly had a ton of shows that I can’t get to play, which is what got me started looking at the database.

Wait, I missed the second part of your post. What is the ‘built in’ one?

If I may help here?

To invoke the resident SQLite3 module.

"/usr/lib/plexmediaserver/Plex Media Server" --sqlite

If you wish to go further in to Plex Media Server/Plug-in Support/Databases to save typing of the path, that’s fine.

[/share/CACHEDEV3_DATA/.qpkg/PlexMediaServer] # ./Plex\ Media\ Server --sqlite
SQLite version 3.26.0 2018-12-01 12:34:55
Enter ".help" for usage hints.
Connected to a transient in-memory database.
Use ".open FILENAME" to reopen on a persistent database.
sqlite> 

You now have the SQLite3 extras which PMS uses already resident.

2 Likes

Hmmm… I’m running this on Unraid. So I need to shutdown Plex to run the commands, but if I shutdown Plex, I don’t have access to the Docker file system to run the commands.

Can I do this from my Windows machine, remotely?

You can’t open the database and repair it while live. SQLite does not tolerate / support it

Yeah, that’s what I meant. Any suggestions for how to do this when Plex is running in a container?

I don’t know where unraid puts its container storage (need to look at the shell level).

All docker installations have the same structure once inside.

You will find usr/lib/plexmediaserver to get to the Plex Media Server executable
the databases will be under wherever “config” is. config/Library/Application Support/Plex Media Server/Plug-in Support/Databases

If this is of any help, here’s the installation scripting.

[chuck@lizum install.331]$ cat doinst.sh 
#!/bin/bash

CONFIG_FILE="/boot/config/plugins/plexmediaserver/settings.ini"
PLEX_MEDIA_SERVER_HOME="/usr/local/plexmediaserver"
UNRAID_PLEX_GUI="/usr/local/emhttp/plugins/plexmediaserver"

#create plex user if necessary
/bin/id unraid-plex > /dev/null
if  [ $? -ne 0 ]; then
  logger -t pms "create user unraid-plex"
  useradd -r -g users -s /sbin/nologin unraid-plex
  cp /etc/passwd /etc/shadow /boot/config
fi

if [ ! -f $CONFIG_FILE ]; then
  logger -t pms "creating default config file ($CONFIG_FILE)"

  echo "#[PMS Settings]" >> $CONFIG_FILE
  echo "#START_CONFIGURATION" >> $CONFIG_FILE
  echo "#Set autostart with array" >> $CONFIG_FILE
  echo "ENABLED=\"false\"" >> $CONFIG_FILE
  echo "RUNAS=\"unraid-plex\"" >> $CONFIG_FILE
  echo "#Set home of Plex Media Server" >> $CONFIG_FILE
  echo "PLEX_MEDIA_SERVER_HOME=\"$PLEX_MEDIA_SERVER_HOME\"" >> $CONFIG_FILE
  echo "#Set home for Plex metadata" >> $CONFIG_FILE
  echo "PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR=\"/tmp/Library\"" >> $CONFIG_FILE
  echo "#the number of plugins that can run at the same time" >> $CONFIG_FILE
  echo "PLEX_MEDIA_SERVER_MAX_PLUGIN_PROCS=6" >> $CONFIG_FILE
  echo "#ulimit -s $PLEX_MEDIA_SERVER_MAX_STACK_SIZE" >> $CONFIG_FILE
  echo "PLEX_MEDIA_SERVER_MAX_STACK_SIZE=10000" >> $CONFIG_FILE
  echo "#ulimit -l $PLEX_MEDIA_SERVER_MAX_LOCK_MEM" >> $CONFIG_FILE
  echo "#PLEX_MEDIA_SERVER_MAX_LOCK_MEM=3000" >> $CONFIG_FILE
  echo "#ulimit -n $PLEX_MEDIA_SERVER_MAX_OPEN_FILES" >> $CONFIG_FILE
  echo "PLEX_MEDIA_SERVER_MAX_OPEN_FILES=4096" >> $CONFIG_FILE
  echo "#where the mediaserver should store the transcodes" >> $CONFIG_FILE
  echo "PLEX_MEDIA_SERVER_TMPDIR=\"/tmp\"" >> $CONFIG_FILE
  echo "#STOP_CONFIGURATION" >> $CONFIG_FILE
fi

if [ -f /boot/config/plugins/plexmediaserver/plex_settings.cfg ];then
  logger -t pms "converting old config file into the new"
  source /boot/config/plugins/plexmediaserver/plex_settings.cfg
  sed -i "/START_CONFIGURATION/,/STOP_CONFIGURATION/ {
    /ENABLED/ c\ENABLED=\"$DEFAULT_ENABLED\"
    /PLEX_MEDIA_SERVER_TMPDIR/ c\PLEX_MEDIA_SERVER_TMPDIR=\"$DEFAULT_TMPDIR\"
    /PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR/ c\PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR=\"$DEFAULT_PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR\"
  }
  " $CONFIG_FILE
  rm -f /boot/config/plugins/plexmediaserver/plex_settings.cfg

  #remove old plex_default.cfg if it exists
  if [ -f /boot/config/plugins/plexmediaserver/plex_default.cfg ];then
    rm -f /boot/config/plugins/plexmediaserver/plex_default.cfg
  fi
fi

#set permissions
chown -R root:root $PLEX_MEDIA_SERVER_HOME
chown -R root:root $UNRAID_PLEX_GUI
chown -R root:root /etc/rc.d/rc.plexmediaserver
[chuck@lizum install.332]$```

Yeah, my question is how to stop Plex, so that I can run the commands. I don’t expect you to know the answer, so I’ve asked in the binhex-plex support thread.

edit: I assume that I could just install PMS on Windows, shutdown Unraid Plex, drag the DB over to Windows, and run the repair from there.

My team member who did this packaging is, unfortunately, on the other side of the world (literally) and still asleep. He did the packaging for unraid and uses unraid himself.

I’m sorry that I don’t know the answer.

I was able to copy the DB to another Ubuntu instance to run the commands. Except the commands listed in the KB article won’t work here.

edit: Got it working, but still getting the same error:

sqlite> PRAGMA integrity_check;
Error: no such collation sequence: icu_root

@ChuckPa - I think the Repair a Corrupt Database | Plex Support instructions need to be updated.

Maybe to refer to the built-in SQLite, and/or maybe to address the index_title_sort_icu index, and maybe the fts4*icu tables & triggers?

@Volts

There is already an open ticket about updating the procedure.

I haven’t spoken to the folks who do documentation but usually updated documentation goes live when software goes Public.

1 Like

That, like, makes perfect sense.

Also perfect sense?

“Support is the last to be informed” :slight_smile:

2 Likes

Informed? Back in my day we were lucky to get two rocks to bang together!