简体   繁体   English

Azure PostgreSQL 服务器服务排序规则创建错误

[英]Azure PostgreSQL Server Service Collation Create Error

I'm trying to import my current existing database to postgre instance that is running on Azure PostgreSQL Server我正在尝试将我当前的现有数据库导入到 Azure PostgreSQL 服务器上运行的 postgre 实例

I already configured my azure postgresql server parameters to use encoding as UTF8 (I'm not sure that it's applying without restart but even if i don't have option to restart it)我已经将我的 azure postgresql 服务器参数配置为使用 UTF8 编码(我不确定它是否在不重启的情况下应用,但即使我没有重启它的选项)

I'm trying to do this action with this command:我正在尝试使用以下命令执行此操作:

sudo -u postgres pg_dump --encoding="UTF-8" --no-owner DBNAME | psql --host=xxx.postgres.database.azure.com --port=5432 --username=xxx@yyy --dbname=DBNAME

However it's getting an error something like this:但是,它收到了这样的错误:

ERROR: could not create locale "en_US.utf8": No error错误:无法创建区域设置“en_US.utf8”:没有错误

I dive in the process and try to run it with UTF8 (Instead of UTF-8) and other options but it's got same error everytime.我深入这个过程并尝试使用 UTF8(而不是 UTF-8)和其他选项运行它,但每次都会出现相同的错误。

I created a dump file to check the contents and the line that is generating this error is:我创建了一个转储文件来检查内容,生成此错误的行是:

CREATE COLLATION "en_US.utf8" (lc_collate = 'en_US.utf8', lc_ctype = 'en_US.utf8');

This is causing that error.这是导致该错误的原因。 I tried to execute it manually on Azure postgre instance and i got same error too.我尝试在 Azure postgre 实例上手动执行它,我也遇到了同样的错误。

By the way I already created that DATABASE from console by using this SQL:顺便说一下,我已经使用以下 SQL 从控制台创建了该数据库:

create database "DBNAME" with owner=xxx encoding='UTF-8' template template0;

Also i tried other options to create and import but non of them work.我也尝试了其他选项来创建和导入,但它们都不起作用。

Can someone help me?有人能帮我吗?

I resolved my issue with this command:我用这个命令解决了我的问题:

sudo -u postgres pg_dump -Fp —no-owner DBNAME |sed “/COLLATE/s/en_US.utf8/English_United States.1252/ig”|sed "/CREATE COLLATION/s/en_US.utf8/English_United States.1252/ig"|psql --host=aaa.postgres.database.azure.com --port=5432 --username=xxx@yyy --dbname=DBNAME

The issue is coming from the server OS differences.问题来自服务器操作系统差异。 My current PostgreSQL server is using Ubuntu but Azure PostgreSQL Server is using windows so the collate names are little bit different.我当前的 PostgreSQL 服务器使用的是 Ubuntu,但 Azure PostgreSQL 服务器使用的是 Windows,因此整理名称略有不同。

CREATE COLLATION creates a operating system independent name that can be used to refer to OS locales (in queries etc). CREATE COLLATION创建一个独立于操作系统的名称,可用于引用操作系统区域设置(在查询等中)。

Here lc_collate = 'en_US.utf8' and lc_ctype = 'en_US.utf8' refer to Linux operating system locales, which are named differently on Windows, which Azure PostgreSQL uses (and they're different on MacOS, too).这里lc_collate = 'en_US.utf8'lc_ctype = 'en_US.utf8'指的是 Linux 操作系统区域设置,它们在 Windows 上的命名不同,Azure PostgreSQL 使用这些区域设置(它们在 MacOS 上也不同)。

On Windows, this should work在 Windows 上,这应该可以工作

CREATE COLLATION "en_US.utf8" (lc_collate = 'English_United States', lc_ctype = 'English_United States');

And on MacOS,而在 MacOS 上,

CREATE COLLATION "en_US.utf8" (lc_collate = 'en_US', lc_ctype = 'en_US');

But most of the time, you don't want to create your own collations with CREATE COLLATION , but can just use the pre-included collations in PostgreSQL.但是大多数时候,您不想使用CREATE COLLATION创建自己的排序规则,而可以只使用 PostgreSQL 中预先包含的排序规则。 And normally a dump created with pg_dump does not include any CREATE COLLATION statements, since you haven't created any yourself.通常,使用pg_dump创建的转储不包含任何CREATE COLLATION语句,因为您没有自己创建任何语句。

Unless you're doing something special with collations, is it possible to remove those schema-specific collations, so they won't get included in the dump?除非您对排序规则进行特殊处理,否则是否可以删除那些特定于架构的排序规则,以便它们不会包含在转储中?

We've previously run into this same issue running Atlassian's Confluence.我们之前在运行 Atlassian 的 Confluence 时遇到过同样的问题。 The application would not start due to an incorrect collation type.由于不正确的整理类型,应用程序不会启动。 We were able to resolve by assigning English_United States.1252 directly.我们可以通过直接分配English_United States.1252来解决。

CREATE DATABASE db 
  WITH ENCODING 'UTF8' 
  LC_COLLATE    'English_United States.1252' 
  LC_CTYPE      'English_United States.1252' 
  TEMPLATE      template0 
  OWNER         conf;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 MySQL到PostgreSQL表创建转换-字符集和排序规则 - MySQL to PostgreSQL table create conversion - charset and collation 尝试在PostgreSQL中创建具有UTF-8编码和pt-BR.UTF-8归类的数据库时出错 - Error trying to create a database with UTF-8 encoding and pt-BR.UTF-8 collation in PostgreSQL PostgreSQL整理 - Postgresql collation 如何在 Windows 上的 PostgreSQL 中使用 UTF-8 排序规则创建数据库? - How to create a database with UTF-8 collation in PostgreSQL on Windows? 有没有办法创建从 Azure SQL 数据库到 PostgreSQL 的链接服务器? - Is there a way to create a linked server from an Azure SQL database to PostgreSQL? 如何创建从.NET服务到远程PostgreSQL服务器的连接 - How to create a connection from .NET Service to Remote PostgreSQL server Azure 用于 PostgreSQL 灵活服务器部署的数据库因 databaseName 参数错误而失败 - Azure Database for PostgreSQL flexible server deployment fails with databaseName param error Azure PostgreSQL即服务延迟问题 - Azure PostgreSQL as a Service Latency Issues Azure PostgreSQL即服务-为每个数据库创建单独的用户将提供“权限被拒绝” - Azure PostgreSQL as service - Create separate user per database gives “Permission denied” 无法通过应用服务中的 VNet 访问我的 Azure for PostgreSQL 灵活服务器 - Unable to access my Azure for PostgreSQL Flexible Server through VNet from App Service
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM