postgresql_16:5.1.15 Environment Variables
PostgreSQL 16 > Client Interfaces > libpq — C Library > Environment Variables
The following environment variables can be used to select default connection parameter values, which will be used by (see libpq-PQconnectdb), (see libpq-PQsetdbLogin) and (see libpq-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. PGHOST behaves the same as the (see libpq-connect-host) connection parameter. PGHOSTADDR behaves the same as the (see libpq-connect-hostaddr) connection parameter. This can be set instead of or in addition to PGHOST to avoid DNS lookup overhead. PGPORT behaves the same as the (see libpq-connect-port) connection parameter. PGDATABASE behaves the same as the (see libpq-connect-dbname) connection parameter. PGUSER behaves the same as the (see libpq-connect-user) connection parameter. PGPASSWORD behaves the same as the (see libpq-connect-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 (see postgresql_16:5.1.16)). PGPASSFILE behaves the same as the (see libpq-connect-passfile) connection parameter. PGREQUIREAUTH behaves the same as the (see libpq-connect-require-auth) connection parameter. PGCHANNELBINDING behaves the same as the (see libpq-connect-channel-binding) connection parameter. PGSERVICE behaves the same as the (see libpq-connect-service) connection parameter. PGSERVICEFILE specifies the name of the per-user connection service file (see (see postgresql_16:5.1.17)). Defaults to ~/.pg_service.conf, or %APPDATA%\postgresql\.pg_service.conf on Microsoft Windows. PGOPTIONS behaves the same as the (see libpq-connect-options) connection parameter. PGAPPNAME behaves the same as the (see libpq-connect-application-name) connection parameter. PGSSLMODE behaves the same as the (see libpq-connect-sslmode) connection parameter. PGREQUIRESSL behaves the same as the (see libpq-connect-requiressl) connection parameter. This environment variable is deprecated in favor of the PGSSLMODE variable; setting both variables suppresses the effect of this one. PGSSLCOMPRESSION behaves the same as the (see libpq-connect-sslcompression) connection parameter. PGSSLCERT behaves the same as the (see libpq-connect-sslcert) connection parameter. PGSSLKEY behaves the same as the (see libpq-connect-sslkey) connection parameter. PGSSLCERTMODE behaves the same as the (see libpq-connect-sslcertmode) connection parameter. PGSSLROOTCERT behaves the same as the (see libpq-connect-sslrootcert) connection parameter. PGSSLCRL behaves the same as the (see libpq-connect-sslcrl) connection parameter. PGSSLCRLDIR behaves the same as the (see libpq-connect-sslcrldir) connection parameter. PGSSLSNI behaves the same as the (see libpq-connect-sslsni) connection parameter. PGREQUIREPEER behaves the same as the (see libpq-connect-requirepeer) connection parameter. PGSSLMINPROTOCOLVERSION behaves the same as the (see libpq-connect-ssl-min-protocol-version) connection parameter. PGSSLMAXPROTOCOLVERSION behaves the same as the (see libpq-connect-ssl-max-protocol-version) connection parameter. PGGSSENCMODE behaves the same as the (see libpq-connect-gssencmode) connection parameter. PGKRBSRVNAME behaves the same as the (see libpq-connect-krbsrvname) connection parameter. PGGSSLIB behaves the same as the (see libpq-connect-gsslib) connection parameter. PGGSSDELEGATION behaves the same as the (see libpq-connect-gssdelegation) connection parameter. PGCONNECT_TIMEOUT behaves the same as the (see libpq-connect-connect-timeout) connection parameter. PGCLIENTENCODING behaves the same as the (see libpq-connect-client-encoding) connection parameter. PGTARGETSESSIONATTRS behaves the same as the (see libpq-connect-target-session-attrs) connection parameter. PGLOADBALANCEHOSTS behaves the same as the (see libpq-connect-load-balance-hosts) connection parameter.
The following environment variables can be used to specify default behavior for each PostgreSQL session. (See also the (see postgresql_16:7.1.24) and (see postgresql_16:7.1.5) commands for ways to set default behavior on a per-user or per-database basis.) PGDATESTYLE sets the default style of date/time representation. (Equivalent to SET datestyle TO ....) PGTZ sets the default time zone. (Equivalent to SET timezone TO ....) PGGEQO sets the default mode for the genetic query optimizer. (Equivalent to SET geqo TO ....) Refer to the SQL command (see postgresql_16:7.1.172) for information on correct values for these environment variables.
The following environment variables determine internal behavior of libpq; they override compiled-in defaults. PGSYSCONFDIR sets the directory containing the pg_service.conf file and in a future version possibly other system-wide configuration files. PGLOCALEDIR sets the directory containing the locale files for message localization.