PostgreSQL 错误:Windows 更新后数据库区域设置不兼容(从Turkish_Turkey.1254 到Turkish_Türkiye.1254)

问题描述 投票:0回答:1

我在尝试连接 Flask Web 应用程序中的 PostgreSQL 数据库时遇到问题。我收到一条错误消息,例如“数据库连接失败”。在调查问题根源后,我注意到 postgresql.conf 文件中的语言设置不匹配。以前,创建数据库时使用Turkish_Turkey.1254 语言,但随着最新的Windows 更新,该语言不再可用,而是使用Turkish_Türkiye.1254。

我尝试更新 postgresql.conf 文件中的语言设置,但问题仍然存在。我不确定运行 PostgreSQL 服务需要遵循的步骤或如何解决这种语言不兼容问题。

我在下面分享相关的代码片段和错误消息: postgresql.conf:

lc_messages = 'Turkish_Türkiye.1254'

lc_monetary = 'Turkish_Türkiye.1254'

lc_numeric = 'Turkish_Türkiye.1254'

lc_time = 'Turkish_Türkiye.1254'

错误信息: psycopg2.OperationalError:连接到“localhost”(::1)的服务器,端口 5432 失败:致命:数据库区域设置与操作系统不兼容 详细信息:数据库是使用 LC_COLLATE“Turkish_Turkey.1254”初始化的,setlocale() 无法识别该数据库。 提示:使用另一个区域设置重新创建数据库或安装缺少的区域设置。

我已尝试根据 PostgreSQL 文档提供的指导更新 postgresql.conf 文件中的语言设置,但问题仍然存在。我预计更新语言设置以匹配新的系统区域设置将解决连接错误并允许我成功连接到 PostgreSQL 数据库。然而,尽管进行了这些更改,我仍然遇到相同的错误消息。

database postgresql database-connection windows-update turkish
1个回答
0
投票

我找到了一个非常粗暴的解决方案,遵循你自己的危险。更好的解决方案可能是使用 Locale Builder 2.0 创建一个名为

Turkish_Turkey.1254
的新语言环境,并按照此处的规定将其安装到系统。

首先,我使用以下 C++ 程序验证了我怀疑的行为:

#include <locale.h>
#include <process.h>
#include <windows.h>
#include <stdio.h>
#include <time.h>

int main()
{
    printf("The locale is set to: %s\n", setlocale(LC_ALL, "Turkish.1254"));
    printf("The locale is set to: %s\n", setlocale(LC_ALL, "Turkish_Türkiye.1254"));
}

我得到了这个输出:

The locale is set to: Turkish_Türkiye.1254
The locale is set to: Turkish_Türkiye.1254

看到

Turkish.1254
Turkish_Türkiye.1254
在我的服务器中相同后,我执行了以下操作

  1. 卸载了有问题的更新,这对我来说是
    KB5035857
  2. 以超级用户身份连接到数据库并运行以下 SQL 语句:
    UPDATE pg_database SET datcollate='Turkish.1254', datctype='Turkish.1254'
    
  3. 重新安装更新。
  4. 运行以下sql语句:
    UPDATE pg_database SET datcollate='Turkish_Türkiye.1254', datctype='Turkish_Türkiye.1254'
    
© www.soinside.com 2019 - 2024. All rights reserved.