32.14. 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.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.15).PGPASSFILE
behaves the same as thepassfile connection parameter.PGSERVICE
behaves the same as theservice connection parameter.PGSERVICEFILE
specifies the name of the per-user connection service file (seeSection 32.16). 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.PGSSLROOTCERT
behaves the same as thesslrootcert connection parameter.PGSSLCRL
behaves the same as thesslcrl connection parameter.PGREQUIREPEER
behaves the same as therequirepeer connection parameter.PGKRBSRVNAME
behaves the same as thekrbsrvname connection parameter.PGGSSLIB
behaves the same as thegsslib 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.
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.