Using environment variables

One way to pass all kinds of parameters is to use environment variables. If information is not explicitly passed to pg_dump, it will look for the missing information in predefined environment variables. A list of all potential settings can be found here: https://www.postgresql.org/docs/10/static/libpq-envars.html.

The following overview shows some environment variables commonly needed for backups:

  • PGHOST: It tells the system which host to connect to
  • PGPORT: It defines the TCP port to be used
  • PGUSER: It tells a client program about the desired user
  • PGPASSWORD: It contains the password to be used
  • PGDATABASE: It is the name of the database to connect to

The advantage of these environments is that the password won't ...

Get Mastering PostgreSQL 10 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.