It seems not all tables are restored back. I haven’t done full DB comparison yet, but at least oc_share and oc_bookmarks tables are empty after the restore. Has anyone experienced this behavior?
Yes. For example, there is COPY public.oc_share (id, share_type, ...) FROM stdin; statement with 75 lines of data, the same number as in the source table:
nextcloud=> select count(*) from oc_share;
count
-------
75
(1 row)
Yes. For example, the source oc_share has 75 records:
nextcloud=> select count(*) from oc_share;
count
-------
75
(1 row)
But the target oc_share is empty:
nextcloud=# select count(*) from oc_share;
count
-------
0
(1 row)
It is strange, because the backup data file also has 75 lines of data for oc_share. It feels something is wrong with the import, I’ll take a look at this when I have more time.
There were errors while restoring the database, which I didn’t notice initially:
ERROR: character with byte sequence 0xe2 0x80 0x94 in encoding "UTF8" has no equivalent in encoding "LATIN1"
CONTEXT: COPY oc_bookmarks, line 14
ERROR: character with byte sequence 0xd0 0xa7 in encoding "UTF8" has no equivalent in encoding "LATIN1"
CONTEXT: COPY oc_share, line 20
(and in a few other tables)
This probably explains the missing data in oc_bookmarks and oc_share, just need to figure out the encoding issue.
The issue was my destination system was configured with en_US locale instead of en_US.UTF-8 locale.
When PostgreSQL cluster was created, it used en_USto initialize itself, which cased encoding mismatch at restore time.
The fix was to drop the cluster, re-configure locale to en_US.UTF-8 with sudo dpkg-reconfigure locales, and then re-create the cluster.
Also, when testing db restoration, it is useful to run psql with --set ON_ERROR_STOP=on or --single-transactionoptions to immediately notice the errors.