33.15. Переменные окружения
Воспользовавшись следующими переменными окружения, можно задать значения параметров соединения по умолчанию, которые будут использоваться функциями PQconnectdb, PQsetdbLogin и PQsetdb, если никакое значение не будет задано вызывающим кодом. В частности, используя их, можно обойтись без жёсткого задания параметров соединения в простых клиентских приложениях.
PGHOSTдействует так же, как параметр соединения host.PGHOSTADDRдействует так же, как параметр соединения hostaddr. Эту переменную можно задать вместо или вместе сPGHOSTдля предотвращения поиска адреса в DNS.PGPORTдействует так же, как параметр соединения port.PGDATABASEдействует так же, как параметр соединения dbname.PGUSERдействует так же, как параметр соединения user.PGPASSWORDдействует так же, как параметр соединения password. Использовать эту переменную окружения не рекомендуется по соображениям безопасности, так как в некоторых операционных системах непривилегированные пользователи могут видеть переменные окружения процессов в выводе ps; вместо этого лучше использовать файл паролей (см. Раздел 33.16).PGPASSFILEдействует так же, как параметр соединения passfile.PGCHANNELBINDINGдействует так же, как параметр соединения channel_binding.PGSERVICEдействует так же, как параметр соединения service.PGSERVICEFILEзадаёт имя личного файла пользователя с параметрами подключения к службам (см. Раздел 33.17). По умолчанию применяется имя файла~/.pg_service.conf(или%APPDATA%\postgresql\.pg_service.confв Microsoft Windows).PGOPTIONSдействует так же, как параметр соединения options.PGAPPNAMEдействует так же, как параметр соединения application_name.PGSSLMODEдействует так же, как параметр соединения sslmode.PGREQUIRESSLдействует так же, как параметр соединения requiressl. Эта переменная окружения утратила актуальность с появлением переменнойPGSSLMODE; если установить обе переменные, значение данной не возымеет эффекта.PGSSLCOMPRESSIONдействует так же, как параметр соединения sslcompression.PGSSLCERTдействует так же, как параметр соединения sslcert.PGSSLKEYдействует так же, как параметр соединения sslkey.PGSSLROOTCERTдействует так же, как параметр соединения sslrootcert.PGSSLCRLдействует так же, как параметр соединения sslcrl.PGSSLCRLDIRдействует так же, как параметр соединения sslcrldir.PGSSLSNIдействует так же, как параметр соединения sslsni.PGREQUIREPEERдействует так же, как параметр соединения requirepeer.PGSSLMINPROTOCOLVERSIONдействует так же, как параметр соединения ssl_min_protocol_version.PGSSLMAXPROTOCOLVERSIONдействует так же, как параметр соединения ssl_max_protocol_version.PGGSSENCMODEдействует так же, как параметр соединения gssencmode.PGKRBSRVNAMEдействует так же, как параметр соединения krbsrvname.PGGSSLIBдействует так же, как параметр соединения gsslib.PGCONNECT_TIMEOUTдействует так же, как параметр соединения connect_timeout.PGCLIENTENCODINGдействует так же, как параметр соединения client_encoding.PGTARGETSESSIONATTRSдействует так же, как параметр соединения target_session_attrs.
Следующие переменные окружения позволяют задать поведение по умолчанию для каждого отдельного сеанса Postgres Pro. (См. также описание команд ALTER ROLE и ALTER DATABASE, позволяющих установить поведение по умолчанию для отдельного пользователя или отдельной базы.)
PGDATESTYLEустанавливает стиль представления даты/времени по умолчанию. (РавносильноSET datestyle TO ....)PGTZустанавливает часовой пояс по умолчанию. (РавносильноSET timezone TO ....)PGGEQOустанавливает режим по умолчанию для генетического оптимизатора запросов. (РавносильноSET geqo TO ....)
Информацию о корректных значениях этих переменных окружения можно найти в описании SQL-команды SET.
Следующие переменные среды определяют внутреннее поведение libpq; они переопределяют встроенные значения.
33.15. Environment Variables
The following environment variables can be used to select default connection parameter values, which will be used by PQconnectdb, PQsetdbLogin and PQsetdb if no value is directly specified by the calling code. These are useful to avoid hard-coding database connection information into simple client applications, for example.
PGHOSTbehaves the same as the host connection parameter.PGHOSTADDRbehaves the same as the hostaddr connection parameter. This can be set instead of or in addition toPGHOSTto avoid DNS lookup overhead.PGPORTbehaves the same as the port connection parameter.PGDATABASEbehaves the same as the dbname connection parameter.PGUSERbehaves the same as the user connection parameter.PGPASSWORDbehaves the same as the password connection parameter. Use of this environment variable is not recommended for security reasons, as some operating systems allow non-root users to see process environment variables via ps; instead consider using a password file (see Section 33.16).PGPASSFILEbehaves the same as the passfile connection parameter.PGCHANNELBINDINGbehaves the same as the channel_binding connection parameter.PGSERVICEbehaves the same as the service connection parameter.PGSERVICEFILEspecifies the name of the per-user connection service file (see Section 33.17). Defaults to~/.pg_service.conf, or%APPDATA%\postgresql\.pg_service.confon Microsoft Windows.PGOPTIONSbehaves the same as the options connection parameter.PGAPPNAMEbehaves the same as the application_name connection parameter.PGSSLMODEbehaves the same as the sslmode connection parameter.PGREQUIRESSLbehaves the same as the requiressl connection parameter. This environment variable is deprecated in favor of thePGSSLMODEvariable; setting both variables suppresses the effect of this one.PGSSLCOMPRESSIONbehaves the same as the sslcompression connection parameter.PGSSLCERTbehaves the same as the sslcert connection parameter.PGSSLKEYbehaves the same as the sslkey connection parameter.PGSSLROOTCERTbehaves the same as the sslrootcert connection parameter.PGSSLCRLbehaves the same as the sslcrl connection parameter.PGSSLCRLDIRbehaves the same as the sslcrldir connection parameter.PGSSLSNIbehaves the same as the sslsni connection parameter.PGREQUIREPEERbehaves the same as the requirepeer connection parameter.PGSSLMINPROTOCOLVERSIONbehaves the same as the ssl_min_protocol_version connection parameter.PGSSLMAXPROTOCOLVERSIONbehaves the same as the ssl_max_protocol_version connection parameter.PGGSSENCMODEbehaves the same as the gssencmode connection parameter.PGKRBSRVNAMEbehaves the same as the krbsrvname connection parameter.PGGSSLIBbehaves the same as the gsslib connection parameter.PGCONNECT_TIMEOUTbehaves the same as the connect_timeout connection parameter.PGCLIENTENCODINGbehaves the same as the client_encoding connection parameter.PGTARGETSESSIONATTRSbehaves the same as the target_session_attrs connection parameter.
The following environment variables can be used to specify default behavior for each Postgres Pro session. (See also the ALTER ROLE and ALTER DATABASE commands for ways to set default behavior on a per-user or per-database basis.)
Refer to the SQL command SET for information on correct values for these environment variables.
The following environment variables determine internal behavior of libpq; they override compiled-in defaults.