Postgresql 中文操作指南

20.2. File Locations #

除了前面提到的 _postgresql.conf_文件之外,PostgreSQL 还使用另外两个手动编辑的配置文件,用于控制客户端身份验证(它们的使用在 Chapter 21中已说明)。默认情况下,所有三个配置文件都存储在数据库集群的数据目录中。本节中描述的参数允许将配置文件放在其他位置。(这样做可以简化管理。特别是,分开保留配置文件时,通常更容易确保配置文件得到适当的备份。)

In addition to the postgresql.conf file already mentioned, PostgreSQL uses two other manually-edited configuration files, which control client authentication (their use is discussed in Chapter 21). By default, all three configuration files are stored in the database cluster’s data directory. The parameters described in this section allow the configuration files to be placed elsewhere. (Doing so can ease administration. In particular it is often easier to ensure that the configuration files are properly backed-up when they are kept separate.)

  • data_directory (string) #

    • Specifies the directory to use for data storage. This parameter can only be set at server start.

  • config_file (string) #

    • Specifies the main server configuration file (customarily called postgresql.conf). This parameter can only be set on the postgres command line.

  • hba_file (string) #

    • Specifies the configuration file for host-based authentication (customarily called pg_hba.conf). This parameter can only be set at server start.

  • ident_file (string) #

    • Specifies the configuration file for user name mapping (customarily called pg_ident.conf). This parameter can only be set at server start. See also Section 21.2.

  • external_pid_file (string) #

    • Specifies the name of an additional process-ID (PID) file that the server should create for use by server administration programs. This parameter can only be set at server start.

在默认安装中,上述参数均未显式设置。相反,数据目录由 -D 命令行选项或 PGDATA 环境变量指定,而所有配置文件都在数据目录中找到。

In a default installation, none of the above parameters are set explicitly. Instead, the data directory is specified by the -D command-line option or the PGDATA environment variable, and the configuration files are all found within the data directory.

如果你希望将配置文件存储在数据目录以外,则 postgres -D 命令行选项或 PGDATA 环境变量必须指向包含配置文件的目录,并且必须在 postgresql.conf(或在命令行中)中设置 data_directory 参数,以显示数据目录的实际所在位置。请注意,data_directory 覆盖了 -DPGDATA,以指定数据目录的位置,但不覆盖配置文件的位置。

If you wish to keep the configuration files elsewhere than the data directory, the postgres -D command-line option or PGDATA environment variable must point to the directory containing the configuration files, and the data_directory parameter must be set in postgresql.conf (or on the command line) to show where the data directory is actually located. Notice that data_directory overrides -D and PGDATA for the location of the data directory, but not for the location of the configuration files.

如果你愿意,可以使用参数 config_filehba_file 和/或 ident_file 分别指定配置文件名称和位置。config_file 只能在 postgres 命令行中指定,但其他参数可以在主配置文件中设置。如果显式设置了所有三个参数加上 data_directory,则无需指定 -DPGDATA

If you wish, you can specify the configuration file names and locations individually using the parameters config_file, hba_file and/or ident_file. config_file can only be specified on the postgres command line, but the others can be set within the main configuration file. If all three parameters plus data_directory are explicitly set, then it is not necessary to specify -D or PGDATA.

在设置这些参数中的任何一个时,相对于 postgres 启动的目录来解释相对路径。

When setting any of these parameters, a relative path will be interpreted with respect to the directory in which postgres is started.