今天早些时候,我试图使用pgAdmin I I I从生产环境中恢复我的PostgreSQL(8.1.22)数据库。但是,在恢复过程完成后,它开始抛出如下错误:
WARNING: errors ignored on restore: 4
另外,经过调查,我发现所有表中有3个表没有被还原(包含0行)。当我检查日志时,在3个表附近发现以下错误:
pg_restore: [archiver (db)] Error from TOC entry 5390; 0 442375 TABLE DATA tablename postgres
pg_restore: [archiver (db)] COPY failed: ERROR: invalid byte sequence for encoding "UTF8": 0xea0942
HINT: This error can also happen if the byte sequence does not match the encoding expected by the server, which is controlled by "client_encoding".
CONTEXT: COPY tablename , line 7875
我试着在谷歌上搜索我的问题,但没有结果。请帮助恢复这三个表没有任何错误。
最佳答案
旧版本的PostgreSQL对UTF-8的遵从性没有新版本严格。
可能您正在尝试将包含无效UTF-8的数据从这样一个旧版本还原到一个新版本。
必须清除无效字符串。对于由于以下错误而未导入的每个表,您可以执行该过程:
将表的内容从转储文件提取到SQL纯文本文件中:
pg_restore --table=tablename --data-only dumpfile >plaintext.sql
删除文本编辑器中的无效字符,或使用
iconv
自动删除:iconv -c -f UTF-8 -t UTF-8 <plaintext.sql >plaintext-cleaned.sql
导入净化数据:
psql dbname < plaintext-cleaned.sql
关于postgresql - 恢复PostgreSQL数据库时出现错误“无效字节序列”,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/17487501/