title: How can I pass a password to pg_dump 10 when . pgpass in home directory is not an option?
body: <p>I am running a cron job that creates a database dump using the <code>pg_dump</code> command, like so:</p>
  
  <pre><code>export PGPASSWORD="XXXXXXXX"; pg_dump -h localhost -U my_user my_db &gt; /tmp/db_dump.sql
  </code></pre>
  
  <p>But when I run this command, I get a password authentication error:</p>
  
  <pre><code>pg_dump: [archiver (db)] connection to database "my_db" failed: FATAL:  password authentication failed for user "my_user"
  FATAL:  password authentication failed for user "my_user"
  </code></pre>
  
  <p>I am not able to place a <code>.pgpass</code> file under the user that's running the cron, but I could place it elsewhere and specify the <code>PGPASSFILE</code> like so:</p>
  
  <pre><code>export PGPASSFILE=/path/to/.pgpass; pg_dump -h localhost -U my_user my_db &gt; /tmp/db_dump.sql
  </code></pre>
  
  <p>But again this returns the same authentication error. I have confirmed that this is not a problem of having the wrong password, because it works when I use the interactive prompt:</p>
  
  <pre><code>pg_dump --password -h localhost -U my_user my_db &gt; /tmp/db_dump.sql
  Password: XXXXXXXX
  </code></pre>
  
  <p>When I look at the documentation, it looks like <code>PGPASSWORD</code> and <code>PGPASSFILE</code> are missing from the environmental variables (Perhaps they were removed?) <a href="https://www.postgresql.org/docs/10/app-pgdump.html" rel="nofollow noreferrer">https://www.postgresql.org/docs/10/app-pgdump.html</a> </p>
  
  <p>If I can't create a <code>.pgpass</code> file located in the home directory of the user running the script, how else can I run the <code>pg_dump</code> command?</p>
  
  <p>For context, I am running <code>pg_dump</code> version 10.6:</p>
  
  <pre><code>pg_dump --version
  pg_dump (PostgreSQL) 10.6 (Ubuntu 10.6-0ubuntu0.18.04.1)
  </code></pre>