PostgreSQL Locale 问题

  1. en_US.UTF-8 缺失
  2. en_HK.UTF-8 缺失

en_US.UTF-8 缺失

系统语言调整后,psql 只显示套接字不存在:

psql: 错误: 连接到套接字 "/var/run/postgresql/.s.PGSQL.5432" 上的服务器失败:
没有那个文件或目录

/var/log/postgresql/ 中的实际启动错误:

LOG: invalid value for parameter "lc_messages": "en_US.UTF-8"
LOG: invalid value for parameter "lc_monetary": "en_US.UTF-8"
LOG: invalid value for parameter "lc_numeric": "en_US.UTF-8"
LOG: invalid value for parameter "lc_time": "en_US.UTF-8"
FATAL: configuration file "/etc/postgresql/14/main/postgresql.conf" contains errors
pg_ctl: could not start server

系统中已经没有 en_US.UTF-8

locale -a | rg -i '^en_US'

Debian 重新生成 Locale:

sudo dpkg-reconfigure locales

直接生成:

sudo locale-gen en_US.UTF-8

en_HK.UTF-8 缺失

另一台数据库使用 en_HK.UTF-8 初始化,切换系统环境后报错:

FATAL: database locale is incompatible with operating system
DETAIL: The database was initialized with LC_COLLATE "en_HK.UTF-8",
which is not recognized by setlocale().
HINT: Recreate the database with another locale or install the missing locale.

恢复与数据库初始化时一致的 Locale:

sudo localedef -i en_HK -f UTF-8 en_HK.UTF-8

检查结果:

locale -a | rg -i '^en_HK'
en_HK.utf8

原记录中第二处命令生成的是 en_US.UTF-8,与报错里的 en_HK.UTF-8 不一致,本次已修正。


转载请注明来源,欢迎对文章中的引用来源进行考证,欢迎指出任何有错误或不够清晰的表达。

文章标题:PostgreSQL Locale 问题

字数:282

本文作者:

发布时间:2022-11-27, 03:57:00

最后更新:2026-08-26, 14:57:00

原始链接:https://cnlnn.pages.dev/posts/postgresql-locale-issues/

版权声明: "署名-非商用-相同方式共享 4.0" 转载请保留原文链接及作者。