在 Postgresql 中,如何将本地时间作为时区以在 FreeBSD 上工作?

qui*_*lur 0 postgresql postgresql-9.4

PostgreSQL: 9.4
FreeBSD: 11.2

当我将TimeZone参数设置为postgresql.conf时,localtime在尝试启动 PostgreSQL 时收到以下错误。

service postgresql restart
<2022-06-02 11:18:27.612 EDT> LOG:  invalid value for parameter "TimeZone": "localtime"
<2022-06-02 11:18:27.613 EDT> FATAL:  configuration file "/usr/local/pgsql/data/postgresql.conf" contains errors
pg_ctl: could not start server
Examine the log output.
Run Code Online (Sandbox Code Playgroud)

在我的搜索过程中,我发现了这个对应关系,这似乎表明 /etc/localtime 应该是一个符号链接。我的不是,所以我尝试将其更改为符号链接,但它仍然不起作用,因为我得到了与上面相同的错误。

mv /etc/localtime /etc/localtime.bak
ln -s /usr/share/zoneinfo/America/Yellowknife
shutdown -r now
ls -la /etc/localtime
lrwxr-xr-x  1 root  wheel  35 Jun  2 11:04 /etc/localtime -> /usr/share/zoneinfo/America/Yellowknife
Run Code Online (Sandbox Code Playgroud)

可以开始TimeZone工作localtimeFreeBSD

请注意,我还发现了讨论,其中提到在 中创建symlinkto 。我也尝试过,但它不起作用,因为我仍然遇到与上面相同的错误。/etc/localtime/usr/share/zoneinfo

使用pg_config --configure我发现它没有配置--with-system-tzdata。这是使用的要求吗localtime

Lau*_*lbe 5

按照您配置 PostgreSQL 的方式,它不使用操作系统的时区数据库,而是使用其自己的副本,该副本位于pg_config --sharedir. 所以你的符号链接没有任何作用。

您必须在 PostgreSQL 的时区数据库副本中创建该符号链接,但正确的解决方案是不同的:设置timezoneAmerica/Yellowknife.

不要使用不受支持的 PostgreSQL 版本。