32.15. Environment Variables#
The following environment variables can be used to select default connection parameter values, which will be used byPQconnectdb
,PQsetdbLogin
andPQsetdb
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.
PGHOST
behaves the same as thehost connection parameter.PGSSLNEGOTIATION
behaves the same as thesslnegotiation connection parameter.PGHOSTADDR
behaves the same as thehostaddr connection parameter. This can be set instead of or in addition toPGHOST
to avoid DNS lookup overhead.PGPORT
behaves the same as theport connection parameter.PGDATABASE
behaves the same as thedbname connection parameter.PGUSER
behaves the same as theuser connection parameter.PGPASSWORD
behaves the same as thepassword 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 viaps; instead consider using a password file (seeSection 32.16).PGPASSFILE
behaves the same as thepassfile connection parameter.PGREQUIREAUTH
behaves the same as therequire_auth connection parameter.PGCHANNELBINDING
behaves the same as thechannel_binding connection parameter.PGSERVICE
behaves the same as theservice connection parameter.PGSERVICEFILE
specifies the name of the per-user connection service file (seeSection 32.17). Defaults to~/.pg_service.conf
, or%APPDATA%\postgresql\.pg_service.conf
on Microsoft Windows.PGOPTIONS
behaves the same as theoptions connection parameter.PGAPPNAME
behaves the same as theapplication_name connection parameter.PGSSLMODE
behaves the same as thesslmode connection parameter.PGREQUIRESSL
behaves the same as therequiressl connection parameter. This environment variable is deprecated in favor of thePGSSLMODE
variable; setting both variables suppresses the effect of this one.PGSSLCOMPRESSION
behaves the same as thesslcompression connection parameter.PGSSLCERT
behaves the same as thesslcert connection parameter.PGSSLKEY
behaves the same as thesslkey connection parameter.PGSSLCERTMODE
behaves the same as thesslcertmode connection parameter.PGSSLROOTCERT
behaves the same as thesslrootcert connection parameter.PGSSLCRL
behaves the same as thesslcrl connection parameter.PGSSLCRLDIR
behaves the same as thesslcrldir connection parameter.PGSSLSNI
behaves the same as thesslsni connection parameter.PGREQUIREPEER
behaves the same as therequirepeer connection parameter.PGSSLMINPROTOCOLVERSION
behaves the same as thessl_min_protocol_version connection parameter.PGSSLMAXPROTOCOLVERSION
behaves the same as thessl_max_protocol_version connection parameter.PGGSSENCMODE
behaves the same as thegssencmode connection parameter.PGKRBSRVNAME
behaves the same as thekrbsrvname connection parameter.PGGSSLIB
behaves the same as thegsslib connection parameter.PGGSSDELEGATION
behaves the same as thegssdelegation connection parameter.PGCONNECT_TIMEOUT
behaves the same as theconnect_timeout connection parameter.PGCLIENTENCODING
behaves the same as theclient_encoding connection parameter.PGTARGETSESSIONATTRS
behaves the same as thetarget_session_attrs connection parameter.PGLOADBALANCEHOSTS
behaves the same as theload_balance_hosts connection parameter.
The following environment variables can be used to specify default behavior for eachPostgres Pro session. (See also theALTER ROLE andALTER DATABASE commands for ways to set default behavior on a per-user or per-database basis.)
Refer to theSQL commandSET for information on correct values for these environment variables.
The following environment variables determine internal behavior oflibpq; they override compiled-in defaults.