title: pg_upgrade on Windows cannot write to log file pg_upgrade_internal.log
body: <p>I'm trying to run pg_upgrade on Windows 2008R2, but I'm getting the error:</p>
  
  <blockquote>
    <p>cannot write to log file pg_upgrade_internal.log Failure, exiting</p>
  </blockquote>
  
  <p>I saw a similar question for Linux at <a href="https://stackoverflow.com/questions/23216734/cannot-write-to-log-file-pg-upgrade-internal-log-when-upgrading-from-postgresq">23216734</a> which explains that the issue is with permissions, but it doesn't help with Windows as I do not have a user named <code>postgres</code></p>
  
  <p>Same goes for the <a href="http://www.postgresql.org/docs/current/static/pgupgrade.html" rel="noreferrer">pg_upgrade docs</a>, which mention a <code>postgres</code> user:</p>
  
  <blockquote>
    <p>RUNAS /USER:postgres "CMD.EXE"</p>
  </blockquote>
  
  <p>But again, I do not have such a user, and am trying to run this command as Administrator so I don't understand why I would have no permission.  I even tried to do </p>
  
  <pre><code>RUNAS /USER:Administrator "CMD.EXE"
  </code></pre>
  
  <p>And run pg_upgrade in the new command prompt, but am getting the same error.</p>
  
  <p>Also, I am not sure which directory needs permissions?  Where is the process trying to write <code>pg_upgrade_internal.log</code> to?</p>
  
  <hr>
  
  <p>More details:</p>
  
  <p>The command I'm running is:</p>
  
  <pre class="lang-none prettyprint-override"><code>C:\Apps\postgresql\pgsql-9.5.0\bin&gt;pg_upgrade.exe --old-datadir=E:\PGSQL_data --new-datadir=E:\PGSQLData\pgsql-9.5 --old-bindir=C:\Apps\postgresql\pgsql-9.4.5.3\bin --new-bindir=C:\Apps\postgresql\pgsql-9.5.0\bin
  </code></pre>
  
  <p>From the same command prompt that gives the error I ran the following commands and they all worked, creating an empty file in the respective directories, so write permissions to the directories that are passed to pg_upgrade are allowed:</p>
  
  <pre><code>C:\Apps\postgresql\pgsql-9.5.0\bin&gt;type nul &gt; E:\PGSQL_data\_test_write_permission.txt
  C:\Apps\postgresql\pgsql-9.5.0\bin&gt;type nul &gt; E:\PGSQLData\pgsql-9.5\_test_write_permission.txt
  C:\Apps\postgresql\pgsql-9.5.0\bin&gt;type nul &gt; C:\Apps\postgresql\pgsql-9.4.5.3\bin\_test_write_permission.txt
  C:\Apps\postgresql\pgsql-9.5.0\bin&gt;type nul &gt; C:\Apps\postgresql\pgsql-9.5.0\bin\_test_write_permission.txt
  </code></pre>
  
  <p>So now I'm even more puzzled than before...</p>
  
  <hr>
  
  <p>Even more details:</p>
  
  <p>I see that the command to create the internal log file is at <a href="https://github.com/postgres/postgres/blob/master/src/bin/pg_upgrade/option.c#L101" rel="noreferrer">/src/bin/pg_upgrade/option.c#L101</a></p>
  
  <p>Which calls <code>fopen_priv(INTERNAL_LOG_FILE, "a")</code> defined at 
  <a href="https://github.com/postgres/postgres/blob/master/src/bin/pg_upgrade/file.c#L243" rel="noreferrer">/src/bin/pg_upgrade/file.c#L243</a></p>
  
  <p>But I'm not sure to which directory it is trying to write.  If I would know that then I can check the permissions on that directory.  </p>
  
  <p>Any ideas?</p>