Category: Other

Synology DSM 6.2 Photo Station 6 – Failed to Load Data Fix

I'm a quite happy Synology user. For the past years I've been using it mostly to backup my things, so I didn't pay much of an attention to the fact, that the Photo Station software would get slower and slower up to the point when I would end up with "Failed to load data" message each time I would access it.

Some articles suggested that you have to drop and re-create the media indexing database to fix it. However, this won't help you in the long run. Your Photo Station 6 database will become bloated once again after a while.

The reason, why Photo Station 6 gets slower and slower, is the fact that Synology, for any crazy reason disabled the PostgreSQL AutoVacuum functionality. Vacuuming is suppose to keep your database in a good state

How to fix that once and for all? You need to enable the PostgreSQL AUTOVACUUM and for an immediate effect, you should also run the vacuuming manually.

SSH into your server and then:

sudo su
cd /volume1/@database/pgsql
vim postgresql.conf

Within the postgresql.conf file replace (or add if they don't not exist) following settings:

wal_buffers =128MB
autovacuum = on
checkpoint_segments = 10

save, exit the file and reboot.

If you want to run vacuuming manually, log in into the PostgreSQL console:

psql -U postgres

List available databases:

postgres=# \l
                                       List of databases
    Name     |           Owner            | Encoding  | Collate | Ctype |   Access privileges   
-------------+----------------------------+-----------+---------+-------+-----------------------
 mediaserver | MediaIndex                 | SQL_ASCII | C       | C     | 
 ong         | SynologyApplicationService | SQL_ASCII | C       | C     | 
 photo       | PhotoStation               | SQL_ASCII | C       | C     | 
 postgres    | postgres                   | SQL_ASCII | C       | C     | 
 synosnmp    | postgres                   | SQL_ASCII | C       | C     | 
 template0   | postgres                   | SQL_ASCII | C       | C     | =c/postgres          +
             |                            |           |         |       | postgres=CTc/postgres
 template1   | postgres                   | SQL_ASCII | C       | C     | postgres=CTc/postgres+
             |                            |           |         |       | =c/postgres

Connect to the photo DB:

postgres=# \c photo;
You are now connected to database "photo" as user "postgres".

Check the tables size by running the following query:

SELECT nspname || '.' || relname AS "relation",
    pg_size_pretty(pg_total_relation_size(C.oid)) AS "total_size"
  FROM pg_class C
  LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace)
  WHERE nspname NOT IN ('pg_catalog', 'information_schema')
    AND C.relkind <> 'i'
    AND nspname !~ '^pg_toast'
  ORDER BY pg_total_relation_size(C.oid) DESC
  LIMIT 5;
       relation       | total_size 
----------------------+------------
 public.photo_image   | 1097 MB
 public.photo_log     | 5912 kB
 public.video_convert | 936 kB
 public.photo_share   | 928 kB
 public.video         | 864 kB
(5 rows)

and the potential vacuuming candidate should be obvious by now:

photo=# vacuum full public.photo_image;
VACUUM

Re-run the size checking query again just to see 93% size reduction of the images table:

       relation       | total_size 
----------------------+------------
 public.photo_image   | 72 MB
 public.photo_log     | 5912 kB
 public.video_convert | 936 kB
 public.photo_share   | 928 kB
 public.video         | 864 kB
(5 rows)

After that, everything will work blazing fast!

Extracting the device token from Xiaomi Air Purifier 2S EU for Domoticz usage

Xiaomi Air Purifier is one of the best on the market in the price/value category. Like many other Xiaomi devices, it can be controlled using a great home automation system called Domoticz.

The only problem that I had is that for the 2S version, there is no way to obtain the device token needed for controlling the device using the miIO library.

Here are the steps needed to obtain this token using a Linux machine and a non-rooted Android phone.

Getting the Mi Home data backup

  1. Download and install the Mi Home application. You need to have the 5.0.19 version of this app. The newer versions don't persist the token locally in the SQLite database. You can get it from the APKMirror page. Note, that you will have to allow the Unknown sources to do that. Here's a description on how to do that.
  2. Enable developer mode and USB debugging on your phone (instruction).
  3. Download and extract the Android Platform tools for Linux from here.
  4. Install the most recent Java version if you don't have it.
  5. Enable developer mode and USB debugging on your phone and connect it to your computer.
  6. Unlock the phone and allow the computer for data transfers (not USB charging only).
  7. Authorize the Linux machine on your Android phone.
  8. Run the following command from your Linux machine:
    ./adb backup -noapk com.xiaomi.smarthome -f backup.ab
    
  9. Unlock your device and confirm the backup operation. If your phone is encrypted, you will also have to provide the backup password.
  10. If everything went smooth, you should have a backup.ab file in the platform tools for further processing. From this moment, you won't need the phone to be connected to your laptop.

Getting the device token out of the Mi Home backup

  1. Download and unpack the ADB extractor.
  2. Navigate to the android-backup-tookit/android-backup-extractor/android-backup-extractor-20180521-bin directory.
  3. Copy the abe.jar file to where your backup.ab is.
  4. Run the following command and follow the instructions (if any):
    java -jar abe.jar unpack backup.ab backup.tar
    
  5. Unpack the extracted backup:
    tar -xvf backup.tar
    
  6. Go to the apps/com.xiaomi.smarthome/db directory.
  7. Install and run the DB Browser for SQLite:
    sudo apt-get install sqlitebrowser
    
  8. Open the miio2.db file using the DB Browsers for SQLite.
  9. Click on the Execute SQL tab and run the following query:
    SELECT localIP, token FROM devicerecord
    

    As a result, you will get a list of the tokens with the IPs of the devices in your networks to which they belong (I've blurred the tokens just in case in the picture):

Now you can take the appropriate token and use it within your Domoticz setup.

Copyright © 2024 Closer to Code

Theme by Anders NorenUp ↑