title: How to correctly provide password to PostgreSQL when connecting remotely in Windows?
body: <p>DB: PostgreSQL 9.0
  Client: Windows 7
  Server Windows 2008, 64bit</p>
  
  <p>I'm trying to connect remotely to a PostgreSQL instance for purposes of performing a pg_dump to my local machine.</p>
  
  <p>Everything works from my client machine, except that I need to provide a password at the password prompt, and I'd ultimately like to batch this with a script.</p>
  
  <p>I've followed the instructions here:</p>
  
  <p><a href="http://www.postgresql.org/docs/current/static/libpq-pgpass.html" rel="nofollow noreferrer">http://www.postgresql.org/docs/current/static/libpq-pgpass.html</a></p>
  
  <p>But it's not working.</p>
  
  <p>To recap, I've created a file on the server: <code>C:/Users/postgres/AppData/postgresql/pgpass.conf</code>, where PostgreSQL is the db user.</p>
  
  <p>The file has one line with the following data:</p>
  
  <pre><code>\*:5432:\*postgres:[mypassword]
  </code></pre>
  
  <p>I've also tried replacing each <code>*</code> with <code>[localhost|myip]</code> and <code>[mydatabasename]</code> respectively.</p>
  
  <p>From my client machine, I connect using:</p>
  
  <pre><code>pg_dump -h &lt;myip&gt; -U postgres -w [mydbname] &gt; [mylocaldumpfile]
  </code></pre>
  
  <p>I'm presuming that I need to provide the <code>-w</code> switch in order to ignore password prompt, at which point it should look in the AppData directory on the server.</p>
  
  <p>It just comes back with:</p>
  
  <blockquote>
    <p>connection to database failed: fe_sendauth: no password supplied.</p>
  </blockquote>
  
  <p>As a hack workaround, if there was a way I could tell the Windows batch file on my client machine to inject the password at the PostgreSQL prompt, that would work as well.</p>