Postgresql:将模式从一台服务器复制到另一台服务器时如何避免编码问题?

Dav*_*ker 5 postgresql pg-dump pg-restore

我正在使用 pg_dump 和 pg_restore 将模式从一个 Postgresql 9.5 服务器移动到另一个。在目标服务器上:

$ pg_dump -h source.example.com -n my_schema -v --no-owner -F c -f my_schema.dump
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
    LANGUAGE = (unset),
    LC_ALL = (unset),
    LC_CTYPE = "UTF-8",
    LANG = (unset)
    are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
...
pg_dump: saving encoding = UTF8
(dump completes with no other errors or warnings)

$ pg_restore -h 127.0.0.1 -e -v --no-owner -d my_db my_schema.dump
...
perl: warning: Falling back to the standard locale ("C").
...
pg_restore: [archiver (db)] Error while PROCESSING TOC:
pg_restore: [archiver (db)] Error from TOC entry 2211; 0 6549333 TABLE DATA mention chicken
pg_restore: [archiver (db)] COPY failed for table "mention": ERROR:  invalid byte sequence for encoding "UTF8": 0xcd 0x2e
Run Code Online (Sandbox Code Playgroud)

关于如何解决这个问题的任何想法?我想要的是数据的精确二进制副本。似乎有一些编码问题让我感到紧张,因为即使我没有收到任何错误,恢复的内容也可能与转储不完全相同。

小智 0

这看起来像是您正在从一个操作系统迁移到另一个操作系统(例如 Linux / Windows 或类似的操作系统),因为不同的操作系统具有不同的区域设置名称。

我这样做的一种方法是找出目标系统上与源上的区域设置名称相对应的确切区域设置名称,然后使用文本转储(pg_dump 的“正常”输出)并在目标系统上使用 psql 来登录并将“客户端编码”设置为第一步中的任何区域设置名称,然后使用\i.