Abd*_*ull 7 postgresql pg-restore
我在Ubuntu 14.04 LTS生产机器上有一个 PostreSQL 9.x 数据库。我的开发机器是基于Windows 7的,提供 PostreSQL 9.y。
我想在我的开发机器上恢复 Ubuntu PostreSQL 数据库。
我注意到 Ubuntu 数据库使用以下语言环境设置:
UTF8en_US.UTF-8en_US.UTF-8当我在没有指定语言环境的情况下在 Windows 机器上恢复数据库时,它将被设置为
UTF8German_Germany.1252German_Germany.1252我的计划是让我的开发机器上的数据库尽可能类似于我的 Ubuntu 机器上的数据库。所以我的想法是首先在我的 Windows 机器上创建一个具有生产匹配语言环境的数据库,然后将我的 Ubuntu 数据库prod-db.backup备份文件恢复到该创建的数据库中:
createdb --host=localhost --username=postgres --encoding=Unicode --lc-collate=en_US.UTF-8 --lc-ctype=en_US.UTF-8 --owner=prod prod-db
pg_restore --host=localhost --username=postgres --format=custom prod-db.backup --dbname=prod-db
Run Code Online (Sandbox Code Playgroud)
这个想法不起作用,因为createdb在 Windows 上会抱怨错误无效的语言环境名称 en_US.UTF-8。
我去了一个狩猎找到Windows区域名称相匹配的Ubuntu的语言环境名称,其中包括使用的解决方案template0中模板的数据库,不同的区域设置标识符,如实验en_US.UTF-8和en_us_utf8我发现散落在互联网...但没有办法解决的作品。
en_US.UTF-8?German_Germany.1252相同(足够),en_US.UTF-8以便我可以坚持使用它而不用担心语言环境 - 我想确保数据库查询在查询结果集排序等方面表现相同。这些是我将 PostgreSQL 9.5 数据库的副本(在 Linux 上使用en_US.UTF-8编码导出)导入 Windows 7 上的 PostgreSQL 9.3 或 Windows 8.1 上的 PostgreSQL 9.5的确切步骤。在加载 SQL 文件之前,您需要使用适当的编码创建数据库,否则来自 Linux ( en_US.UTF-8)的编码将提示 Windows 使用默认编码。
REM WARNING: Console code page (65001) differs from Windows code page (1252) 8-bit characters might not work correctly. See psql reference page "Notes for Windows users" for details.
chcp 1252
C:\PostgreSQL\9.5\bin\psql.exe -U postgres -d postgres_password -c "CREATE DATABASE my_db WITH TEMPLATE=template0 ENCODING='UTF-8' LC_COLLATE='american_usa' LC_CTYPE='american_usa'"
REM Grant privileges to the appropriate database user.
C:\PostgreSQL\9.5\bin\psql.exe -U postgres -d postgres_password -c "GRANT ALL PRIVILEGES ON DATABASE my_db TO myuser"
REM Import my_db.sql. Ignore the following error (it comes from a line in the SQL file, but we have already created the database with the correct locale, so we are ok):
REM psql:my_db.sql:22: ERROR: invalid locale name: "en_US.UTF-8"
C:\PostgreSQL\9.5\bin\psql.exe -o nul --quiet -U postgres -d postgres_password -f my_db.sql
Run Code Online (Sandbox Code Playgroud)
正如这里所讨论的,Windows 上的区域设置应该是american_usa(在 Windows 7 上)。在 Windows 8.1 上,american_usa或en-US(en_US与 Unix 不同)都可以工作。
| 归档时间: |
|
| 查看次数: |
8979 次 |
| 最近记录: |