解决invalid value for parameter “lc_messages“: “zh_CN.UTF-8“

解决 invalid value for parameter “lc_messages”: “zh_CN.UTF-8”

起因:修改了postgresql的系统配置的lc_messages等四个字符集由en_US.UTF-8改成了zh_CN.UTF-8",然后重新启动postgresql就报如下错误,通过定位问题出在liunx系统没有中文字符编码环境导致的。*

invalid value for parameter “lc_messages”: “zh_CN.UTF-8”
invalid value for parameter “lc_monetary”: “zh_CN.UTF-8”
invalid value for parameter “lc_numeric”: “zh_CN.UTF-8”
invalid value for parameter “lc_time”: “zh_CN.UTF-8”

启动postgresql错误日志如下

[root@centos temp]# systemctl status postgresql-12.service
● postgresql-12.service - PostgreSQL 12 database server
   Loaded: loaded (/usr/lib/systemd/system/postgresql-12.service; enabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since Fri 2023-03-24 17:04:15 CST; 3min 3s ago
     Docs: https://www.postgresql.org/docs/12/static/
  Process: 2396 ExecStart=/usr/pgsql-12/bin/postmaster -D ${PGDATA} (code=exited, status=1/FAILURE)
  Process: 2258 ExecStartPre=/usr/pgsql-12/bin/postgresql-12-check-db-dir ${PGDATA} (code=exited, status=0/SUCCESS)
 Main PID: 2396 (code=exited, status=1/FAILURE)

324 17:04:15  systemd[1]: Starting PostgreSQL 12 database server...
2023-03-24 17:04:15.431 CST [2396] LOG:  invalid value for parameter "lc_messages": "zh_CN.UTF-8"
2023-03-24 17:04:15.431 CST [2396] LOG:  invalid value for parameter "lc_monetary": "zh_CN.UTF-8"
2023-03-24 17:04:15.432 CST [2396] LOG:  invalid value for parameter "lc_numeric": "zh_CN.UTF-8"
2023-03-24 17:04:15.432 CST [2396] LOG:  invalid value for parameter "lc_time": "zh_CN.UTF-8"
2023-03-24 17:04:15.432 CST [2396] FATAL:  configuration file "/extdisk/database/postgresql/data/postgresql.conf" contains errors
324 17:04:15  systemd[1]: postgresql-12.service: Main process exited, code=exited, status=1/FAILURE
324 17:04:15  systemd[1]: postgresql-12.service: Failed with result 'exit-code'.
324 17:04:15  systemd[1]: Failed to start PostgreSQL 12 database server.

1.查看当前编码


[root@centos ~]# locale
LANG=en_US.UTF-8
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=

2.修改/etc/locale.conf配置

原配置:    LANG="en_US.UTF-8"
修改为:    LANG="zh_CN.UTF-8"
输入:      source /etc/locale.conf

[root@centos ~]#  source /etc/locale.conf

3.reboot重启后系统后,输入locale再次查看

如果没有下面No such file or directory报错信息就修改成功了,如果有报错信息则继续往下走


[root@centos temp]# reboot
[root@centos ~]# locale
locale: Cannot set LC_CTYPE to default locale: No such file or directory
locale: Cannot set LC_MESSAGES to default locale: No such file or directory
locale: Cannot set LC_ALL to default locale: No such file or directory
LANG=zh_CN.UTF-8
LC_CTYPE="zh_CN.UTF-8"
LC_NUMERIC="zh_CN.UTF-8"
LC_TIME="zh_CN.UTF-8"
LC_COLLATE="zh_CN.UTF-8"
LC_MONETARY="zh_CN.UTF-8"
LC_MESSAGES="zh_CN.UTF-8"
LC_PAPER="zh_CN.UTF-8"
LC_NAME="zh_CN.UTF-8"
LC_ADDRESS="zh_CN.UTF-8"
LC_TELEPHONE="zh_CN.UTF-8"
LC_MEASUREMENT="zh_CN.UTF-8"
LC_IDENTIFICATION="zh_CN.UTF-8"
LC_ALL=

4.安装语言包

1.langpacks-zh_CN-1.0-12.el8.noarch.rpm

2.glibc-langpack-zh-2.28-164.el8.x86_64.rpm

3.glibc-locale-source-2.28-164.el8.x86_64.rpm

安装指令:rpm -ivh *.rpm --force --nodeps (nodeps的意思是忽视依赖关系。因为各个软件之间会有多多少少的联系。有了这两个设置选项就忽略了这些依赖关系,强制安装或者卸载 )


[root@centos temp]# rpm -ivh glibc-langpack-zh-2.28-164.el8.x86_64.rpm --force --nodeps
warning: glibc-langpack-zh-2.28-164.el8.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID 8483c65d: NOKEY
Verifying...                          ################################# [100%]
Preparing...                          ################################# [100%]
Updating / installing...
   1:glibc-langpack-zh-2.28-164.el8   ################################# [100%]
   
[root@centos temp]#  rpm -ivh glibc-locale-source-2.28-164.el8.x86_64.rpm --force --nodeps
warning: glibc-locale-source-2.28-164.el8.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID 8483c65d: NOKEY
Verifying...                          ################################# [100%]
Preparing...                          ################################# [100%]
Updating / installing...
   1:glibc-locale-source-2.28-164.el8 ################################# [100%]
[root@centos temp]# rpm -ivh langpacks-zh_CN-1.0-12.el8.noarch.rpm --force --nodeps

warning: langpacks-zh_CN-1.0-12.el8.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID 8483c65d: NOKEY
Verifying...                          ################################# [100%]
Preparing...                          ################################# [100%]
Updating / installing...
   1:langpacks-zh_CN-1.0-12.el8       ################################# [100%]

5.reboot重启后系统后,输入locale再次查看

[root@centos temp]# reboot
[root@centos ~]# locale
LANG=zh_CN.UTF-8
LC_CTYPE="zh_CN.UTF-8"
LC_NUMERIC="zh_CN.UTF-8"
LC_TIME="zh_CN.UTF-8"
LC_COLLATE="zh_CN.UTF-8"
LC_MONETARY="zh_CN.UTF-8"
LC_MESSAGES="zh_CN.UTF-8"
LC_PAPER="zh_CN.UTF-8"
LC_NAME="zh_CN.UTF-8"
LC_ADDRESS="zh_CN.UTF-8"
LC_TELEPHONE="zh_CN.UTF-8"
LC_MEASUREMENT="zh_CN.UTF-8"
LC_IDENTIFICATION="zh_CN.UTF-8"
LC_ALL=


6.输入date查看是否为中文格式日期

[root@centos ~]# date
20230324日 星期五 18:21:01 CST

7.重新启动pgsql成功!


[root@centos temp]# systemctl restart postgresql-12.service
[root@centos temp]#
[root@centos temp]#
[root@centos temp]#
[root@centos temp]# systemctl status postgresql-12.servicepostgresql-12.service - PostgreSQL 12 database server
   Loaded: loaded (/usr/lib/systemd/system/postgresql-12.service; enabled; vendor preset: disabled)
   Active: active (running) since Fri 2023-03-24 17:07:28 CST; 1min 26s ago
     Docs: https://www.postgresql.org/docs/12/static/
  Process: 5070 ExecStartPre=/usr/pgsql-12/bin/postgresql-12-check-db-dir ${
    
    PGDATA} (code=exited, status=0/SUCCESS)
 Main PID: 5077 (postmaster)
    Tasks: 8 (limit: 78642)
   Memory: 467.2M
   CGroup: /system.slice/postgresql-12.service
           ├─5077 /usr/pgsql-12/bin/postmaster -D /extdisk/database/postgresql/data
           ├─5090 postgres: logger
           ├─5092 postgres: checkpointer
           ├─5093 postgres: background writer
           ├─5094 postgres: walwriter
           ├─5095 postgres: autovacuum launcher
           ├─5096 postgres: stats collector
           └─5097 postgres: logical replication launcher

324 17:07:26  systemd[1]: Starting PostgreSQL 12 database server...
324 17:07:27  postmaster[5077]: 2023-03-24 17:07:27.473 CST [5077] 日志:  正在启动 PostgreSQL 12.5 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 8.3.1 20191121 (Red Hat 8.>
2023-03-24 17:07:27.474 CST [5077] 日志:  正在监听IPv4地址"0.0.0.0",端口 5432
2023-03-24 17:07:27.474 CST [5077] 日志:  正在监听IPv6地址"::",端口 5432
2023-03-24 17:07:27.474 CST [5077] 日志:Unix套接字 "/var/run/postgresql/.s.PGSQL.5432"上侦听
2023-03-24 17:07:27.474 CST [5077] 日志:Unix套接字 "/tmp/.s.PGSQL.5432"上侦听
2023-03-24 17:07:28.422 CST [5077] 日志:  日志输出重定向到日志收集进程
2023-03-24 17:07:28.422 CST [5077] 提示:  后续的日志输出将出现在目录 "log".

猜你喜欢

转载自blog.csdn.net/qq_37959253/article/details/129756470