The following environment variables can be used to select default connection parameter values, which will be used by PQconnectdb or PQsetdbLogin if no value is directly specified by the calling code. These are useful to avoid hard-coding database names into simple application programs.
PGUSER sets the user name used to connect to the database and for authentication.
PGREALM sets the Kerberos realm to use with PostgreSQL, if it is different from the local realm. If PGREALM is set, PostgreSQL applications will attempt authentication with servers for this realm and use separate ticket files to avoid conflicts with local ticket files. This environment variable is only used if Kerberos authentication is selected by the backend.
PGOPTIONS sets additional runtime options for the PostgreSQL backend.
PGTTY sets the file or tty on which debugging messages from the backend server are displayed.
The following environment variables can be used to specify user-level default behavior for every PostgreSQL session:
PGDATESTYLE sets the default style of date/time representation.
PGTZ sets the default time zone.
PGCLIENTENCODING sets the default client encoding (if multibyte support was selected when configuring PostgreSQL).
The following environment variables can be used to specify default internal behavior for every PostgreSQL session:
PGGEQO sets the default mode for the genetic optimizer.
Refer to the SET SQL command for information on correct values for these environment variables.