Error “invalid byte sequence” while restoring PostgreSQL database

泄露秘密 提交于 2019-12-03 20:29:24

Older versions of PostgreSQL were not as strict on UTF-8 compliance than newer versions. Presumably you're trying to restore data containing invalid UTF-8 from such an older version into a newer version.

The invalid strings must be cleaned up. You may follow that procedure for each table that wasn't imported due to these errors:

  1. Extract the contents of the table from the dump file into a SQL plain text file:

    pg_restore --table=tablename --data-only dumpfile >plaintext.sql
    
  2. Remove the invalid characters in a text editor or automatically with iconv:

    iconv -c -f UTF-8 -t UTF-8 <plaintext.sql >plaintext-cleaned.sql
    
  3. Import the sanitized data:

    psql dbname < plaintext-cleaned.sql
    
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!