Repository navigation
Description
Steps to reproduce
- On NethServer 7, have a WebTop 5 installation whose
webtop5database usesSQL_ASCIIencoding and contains a row with an invalid UTF-8 sequence. To reproduce it on a test system:
UPDATE calendar.events SET title = title || E' n\xc2' WHERE event_id = <id>;
(in our production case an event title ended withnfollowed by a dangling0xc2, i.e. a°truncated after its first byte) - Start the NS7 → NS8 migration of Mail and WebTop with the NS7 migration tool and run Sync
- Run Finish for WebTop
Expected behavior
Either the database is restored correctly on NS8, or the migration stops before Finish with a clear message pointing to the invalid data (table and row) so the administrator can fix it on NS7 and retry.
Actual behavior
The restore on NS8 fails while loading calendar.events:
ERROR: invalid byte sequence for encoding "UTF8": 0xc2 0x09
CONTEXT: COPY events, line 415
pg_restore: [archiver (db)] COPY failed for table "events": ERROR: invalid byte sequence for encoding "UTF8": 0xc2 0x09
ERROR: insert or update on table "events_attendees" violates foreign key constraint "events_attendees_event_id_fkey"
ERROR: insert or update on table "events_icalendars" violates foreign key constraint "events_icalendars_event_id_fkey"
WARNING: errors ignored on restore: 3
The migration stops with an error that does not point to the cause. The 0x09 is the COPY field separator: the actual invalid byte is a dangling 0xc2. All other data in the database was valid UTF-8, even though the DB is declared SQL_ASCII, so converting the whole DB from ISO-8859-1 would double-encode accented characters and maybe is not a valid fix.
Invalid rows can be found on NS7 with:
for t in $(runuser -u postgres -- psql webtop5 -Atc "SELECT quote_ident(schemaname)||'.'||quote_ident(tablename) FROM pg_tables WHERE schemaname NOT IN ('pg_catalog','information_schema')"); do
n=$(runuser -u postgres -- psql webtop5 -c "COPY $t TO STDOUT" | LC_ALL=en_US.UTF-8 grep -caxv '.*')
[ "$n" -gt 0 ] && echo "$t: $n invalid rows"
done; echo "done"
Possible improvements
- Add a pre-migration check in the NS7 migration tool for invalid UTF-8 in
SQL_ASCIIdatabases, before Finish. - Report a clear error pointing to the invalid table/row.
- Make
50restore_dbidempotent (recreate thepgdatavolume before restoring), so the migration can be safely retried.
Components
- WebTop 1.4.5 (NS8)
- NethServer 7 migration tool (nethserver-ns8-migration)
See also
Nethesis Helpdesk Ticket #208119
Activity