This page in other versions: 8.4 / 9.0 / 9.1 / 9.2 / 9.3  |  Development versions: devel  |  Unsupported versions: 7.1 / 7.2 / 7.3 / 7.4 / 8.0 / 8.1 / 8.2 / 8.3

30.13. Environment Variables

The following environment variables can be used to select default connection parameter values, which will be used by PQconnectdb, PQsetdbLogin and 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 host connection parameter.

  • PGHOSTADDR behaves the same as hostaddr connection parameter. This can be set instead of or in addition to PGHOST to avoid DNS lookup overhead.

  • PGPORT behaves the same as port connection parameter.

  • PGDATABASE behaves the same as dbname connection parameter.

  • PGUSER behaves the same as user connection parameter. database.

  • PGPASSWORD behaves the same as password connection parameter. Use of this environment variable is not recommended for security reasons (some operating systems allow non-root users to see process environment variables via ps); instead consider using the ~/.pgpass file (see Section 30.14).

  • PGPASSFILE specifies the name of the password file to use for lookups. If not set, it defaults to ~/.pgpass (see Section 30.14).

  • PGSERVICE behaves the same as service connection parameter.

  • PGREALM sets the Kerberos realm to use with PostgreSQL, if it is different from the local realm. If PGREALM is set, libpq 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 server.

  • PGOPTIONS behaves the same as options connection parameter.

  • PGSSLMODE behaves the same as sslmode connection parameter.

  • PGREQUIRESSL behaves the same as requiressl connection parameter.

  • PGSSLCERT behaves the same as sslcert connection parameter.

  • PGSSLKEY behaves the same as sslkey connection parameter.

  • PGSSLROOTCERT behaves the same as sslrootcert connection parameter.

  • PGSSLCRL behaves the same as sslcrl connection parameter.

  • PGKRBSRVNAME behaves the same as krbsrvname connection parameter.

  • PGGSSLIB behaves the same as gsslib connection parameter.

  • PGCONNECT_TIMEOUT behaves the same as connect_timeout connection parameter.

The following environment variables can be used to specify default behavior for each PostgreSQL session. (See also the ALTER USER and ALTER DATABASE 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 ....)

  • PGCLIENTENCODING sets the default client character set encoding. (Equivalent to SET client_encoding TO ....)

  • PGGEQO sets the default mode for the genetic query optimizer. (Equivalent to SET geqo TO ....)

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.

  • PGSYSCONFDIR sets the directory containing the pg_service.conf file.

  • PGLOCALEDIR sets the directory containing the locale files for message internationalization.

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group