Postgresql 中文操作指南

B.4. Date/Time Configuration Files #

由于时区缩写未很好地标准化,因此 PostgreSQL 提供了一种方法来自定义服务器接受的缩写集。 timezone_abbreviations运行时参数确定了有效缩写集。虽然任何数据库用户都可以更改此参数,但其可能的值受数据库管理员控制——它们实际上是存储在安装目录 _…​/share/timezonesets/_中的配置文件的名称。通过添加或更改该目录中的文件,管理员可以为时区缩写设置本地策略。

Since timezone abbreviations are not well standardized, PostgreSQL provides a means to customize the set of abbreviations accepted by the server. The timezone_abbreviations run-time parameter determines the active set of abbreviations. While this parameter can be altered by any database user, the possible values for it are under the control of the database administrator — they are in fact names of configuration files stored in …​/share/timezonesets/ of the installation directory. By adding or altering files in that directory, the administrator can set local policy for timezone abbreviations.

timezone_abbreviations 可以设置为 …​/share/timezonesets/ 中找到的任何文件名,如果该文件名称完全是字母。(禁止在 timezone_abbreviations 中使用非字母字符,可以防止读取目标目录之外的文件,以及读取编辑器备份文件和其他无关文件。)

timezone_abbreviations can be set to any file name found in …​/share/timezonesets/, if the file’s name is entirely alphabetic. (The prohibition against non-alphabetic characters in timezone_abbreviations prevents reading files outside the intended directory, as well as reading editor backup files and other extraneous files.)

时区缩写文件可以包含空行和以 # 开头的注释。非注释行必须采用以下格式之一:

A timezone abbreviation file can contain blank lines and comments beginning with #. Non-comment lines must have one of these formats:

zone_abbreviation offset
zone_abbreviation offset D
zone_abbreviation time_zone_name
@INCLUDE file_name
@OVERRIDE

zone_abbreviation 只是正在定义的缩写。offset 是一个整数,给出了与 UTC 相差的秒数,正数表示在格林威治以东,负数表示在格林威治以西。例如,-18000 表示在格林威治以西 5 小时,或者北美东海岸标准时间。D 表明该时区名称表示当地夏令时,而不是标准时间。

A zone_abbreviation is just the abbreviation being defined. An offset is an integer giving the equivalent offset in seconds from UTC, positive being east from Greenwich and negative being west. For example, -18000 would be five hours west of Greenwich, or North American east coast standard time. D indicates that the zone name represents local daylight-savings time rather than standard time.

或者,也可以指定一个 time_zone_name,引用 IANA 时区数据库中定义的时区名称。会参考时区的定义,以查看该缩写是否在该时区使用中,如果是,则使用合适含义,即在确定其值的 Timestamp 当前使用中含义,或者在其并非当时使用时立即之前使用含义,或者仅在其之后使用时使用最老旧的含义。这种行为对于处理含义在历史上发生过变化的缩写来说至关重要。还可以根据一个缩写未出现的时区名称来定义一个缩写;然后使用缩写就相当于写出时区名称。

Alternatively, a time_zone_name can be given, referencing a zone name defined in the IANA timezone database. The zone’s definition is consulted to see whether the abbreviation is or has been in use in that zone, and if so, the appropriate meaning is used — that is, the meaning that was currently in use at the timestamp whose value is being determined, or the meaning in use immediately before that if it wasn’t current at that time, or the oldest meaning if it was used only after that time. This behavior is essential for dealing with abbreviations whose meaning has historically varied. It is also allowed to define an abbreviation in terms of a zone name in which that abbreviation does not appear; then using the abbreviation is just equivalent to writing out the zone name.

Tip

在定义一个其与 UTC 的时差从未发生改变的缩写时,首选使用一个简单的整数 offset,因为处理这种缩写要比需要参考时区定义的缩写便宜得多。

Using a simple integer offset is preferred when defining an abbreviation whose offset from UTC has never changed, as such abbreviations are much cheaper to process than those that require consulting a time zone definition.

@INCLUDE 语法允许包含 …​/share/timezonesets/ 目录中的另一个文件。包含可以嵌套,至一定的深度。

The @INCLUDE syntax allows inclusion of another file in the …​/share/timezonesets/ directory. Inclusion can be nested, to a limited depth.

@OVERRIDE 语法表明该文件中的后续条目可以覆盖之前的条目(通常是获得自包含文件的条目)。如果没有此语法,则将相同时区缩写的相互冲突定义看作一个错误。

The @OVERRIDE syntax indicates that subsequent entries in the file can override previous entries (typically, entries obtained from included files). Without this, conflicting definitions of the same timezone abbreviation are considered an error.

在未修改的安装中,Default 文件包含了世界上大部分地区的非相互冲突时区缩写。为那些地区提供了 AustraliaIndia 文件:这些文件首先包括 Default 文件,然后根据需要增加或更改缩写。

In an unmodified installation, the file Default contains all the non-conflicting time zone abbreviations for most of the world. Additional files Australia and India are provided for those regions: these files first include the Default file and then add or modify abbreviations as needed.

出于参考目的,标准安装还包含文件 Africa.txtAmerica.txt 等,它们包含根据 IANA 时区数据库已知使用信息每个时区缩写的信息。视需要可以将这些文件中找到的时区名称定义复制并粘贴到自定义配置文件中。请注意由于这些名称中嵌入了点,因此不能直接将它们引用为 timezone_abbreviations 设置。

For reference purposes, a standard installation also contains files Africa.txt, America.txt, etc., containing information about every time zone abbreviation known to be in use according to the IANA timezone database. The zone name definitions found in these files can be copied and pasted into a custom configuration file as needed. Note that these files cannot be directly referenced as timezone_abbreviations settings, because of the dot embedded in their names.

Note

如果在读取时区缩写集时发生错误,则不会应用新值,并将保留旧集。如果错误发生在启动数据库时,启动将失败。

If an error occurs while reading the time zone abbreviation set, no new value is applied and the old set is kept. If the error occurs while starting the database, startup fails.

Caution

在配置文件中定义的时区缩写覆盖了 PostgreSQL 中内置的非时区含义。例如,Australia 配置文件定义了 SAT(对于南澳大利亚标准时间)。当此文件处于活动状态时,SAT 将不会被识别为星期六的缩写。

Time zone abbreviations defined in the configuration file override non-timezone meanings built into PostgreSQL. For example, the Australia configuration file defines SAT (for South Australian Standard Time). When this file is active, SAT will not be recognized as an abbreviation for Saturday.

Caution

如果您修改了 …​/share/timezonesets/ 中的文件,则您需要进行备份——正常的数据库转储不会包含此目录。

If you modify files in …​/share/timezonesets/, it is up to you to make backups — a normal database dump will not include this directory.