31.16. Файл соединений служб

Файл соединений служб позволяет связать параметры соединений libpq с одним именем службы. Затем это имя службы можно задать при подключении через libpq и будут применены все связанные с ним параметры. Это позволяет модифицировать параметры соединений, обходясь без перекомпиляции приложения libpq. Имя службы можно также задать в переменной окружения PGSERVICE.

Файл соединений служб может быть личным файлом пользователя с путём ~/.pg_service.conf или задаваться переменной окружения PGSERVICEFILE, либо это может быть системный файл с путём `pg_config --sysconfdir`/pg_service.conf или в каталоге, задаваемом переменной окружения PGSYSCONFDIR. Если для одного имени службы существует определение и в системном файле, и в файле пользователя, определение пользователя имеет приоритет.

В этом файле используется формат "INI-файлов", в котором имя раздела задаёт имя службы, а параметры внутри — параметры соединения; их список приведён в Подразделе 31.1.2. Например:

# комментарий
[mydb]
host=somehost
port=5433
user=admin

Пример такого файла можно найти в share/pg_service.conf.sample.

31.16. The Connection Service File

The connection service file allows libpq connection parameters to be associated with a single service name. That service name can then be specified by a libpq connection, and the associated settings will be used. This allows connection parameters to be modified without requiring a recompile of the libpq application. The service name can also be specified using the PGSERVICE environment variable.

The connection service file can be a per-user service file at ~/.pg_service.conf or the location specified by the environment variable PGSERVICEFILE, or it can be a system-wide file at `pg_config --sysconfdir`/pg_service.conf or in the directory specified by the environment variable PGSYSCONFDIR. If service definitions with the same name exist in the user and the system file, the user file takes precedence.

The file uses an "INI file" format where the section name is the service name and the parameters are connection parameters; see Section 31.1.2 for a list. For example:

# comment
[mydb]
host=somehost
port=5433
user=admin

An example file is provided at share/pg_service.conf.sample.

FAQ