33.14. Environment Variables
The following environment variables can be used to select default connection parameter values, which will be used by
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 to
PGHOSTto 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.15).
PGPASSFILEbehaves the same as the passfile connection parameter.
PGSERVICEbehaves the same as the service connection parameter.
PGSERVICEFILEspecifies the name of the per-user connection service file (see Section 33.16). Defaults to
%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 the
PGSSLMODEvariable; 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.
PGREQUIREPEERbehaves the same as the requirepeer 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 PostgreSQL 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.