当 .sql 文件是 ANSI 时,pg_dump 是否保留所有 Unicode 字符?

Does pg_dump preserve all Unicode characters when .sql file is ANSI?

我用

pg_dump.exe -U postgres -f "file-name.sql" database-name

备份 PostgreSQL 8.4 和 9.5 上的 UTF-8 编码数据库,Windows 主机。有些可能在字符列中存储了外来字符,例如中文、泰语等。

生成的 .sql 文件在 Notepad++ 中打开时显示 ANSI 编码(默认情况下,我不会将 ANSI 应用于打开的文件)。我如何知道 Unicode 字符是否始终保留在转储文件中?我应该改用存档(对象)备份文件吗?

Quote from the manual

By default, the dump is created in the database encoding.

如果不使用扩展字符,ANSI 编码和 UTF-8 编码的文本文件没有区别。也许您的转储没有特殊字符,因此编辑器不会将其识别为 UTF-8。

如果您想要 SQL 特定编码的转储,请使用 --encoding=encoding 参数或 PGCLIENTENCODING 环境变量