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.
PGHOSTbehaves the same as thehost connection parameter.PGHOSTADDRbehaves the same as thehostaddr connection parameter. This can be set instead of or in addition toPGHOSTto avoid DNS lookup overhead.PGPORTbehaves the same as theport connection parameter.PGDATABASEbehaves the same as thedbname connection parameter.PGUSERbehaves the same as theuser connection parameter.PGPASSWORDbehaves 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).PGPASSFILEbehaves the same as thepassfile connection parameter.PGSERVICEbehaves the same as theservice connection parameter.PGSERVICEFILEspecifies the name of the per-user connection service file (seeSection 32.16). Defaults to~/.pg_service.conf, or%APPDATA%\postgresql\.pg_service.confon Microsoft Windows.PGOPTIONSbehaves the same as theoptions connection parameter.PGAPPNAMEbehaves the same as theapplication_name connection parameter.PGSSLMODEbehaves the same as thesslmode connection parameter.PGREQUIRESSLbehaves the same as therequiressl connection parameter. This environment variable is deprecated in favor of thePGSSLMODEvariable; setting both variables suppresses the effect of this one.PGSSLCOMPRESSIONbehaves the same as thesslcompression connection parameter.PGSSLCERTbehaves the same as thesslcert connection parameter.PGSSLKEYbehaves the same as thesslkey connection parameter.PGSSLROOTCERTbehaves the same as thesslrootcert connection parameter.PGSSLCRLbehaves the same as thesslcrl connection parameter.PGREQUIREPEERbehaves the same as therequirepeer connection parameter.PGKRBSRVNAMEbehaves the same as thekrbsrvname connection parameter.PGGSSLIBbehaves the same as thegsslib connection parameter.PGCONNECT_TIMEOUTbehaves the same as theconnect_timeout connection parameter.PGCLIENTENCODINGbehaves the same as theclient_encoding connection parameter.PGTARGETSESSIONATTRSbehaves 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.