8

I'm trying to run pg_upgrade on Windows 2008R2, but I'm getting the error:

cannot write to log file pg_upgrade_internal.log Failure, exiting

I saw a similar question for Linux at 23216734 which explains that the issue is with permissions, but it doesn't help with Windows as I do not have a user named postgres

Same goes for the pg_upgrade docs, which mention a postgres user:

RUNAS /USER:postgres "CMD.EXE"

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

RUNAS /USER:Administrator "CMD.EXE"

And run pg_upgrade in the new command prompt, but am getting the same error.

Also, I am not sure which directory needs permissions? Where is the process trying to write pg_upgrade_internal.log to?


More details:

The command I'm running is:

C:\Apps\postgresql\pgsql-9.5.0\bin>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

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:

C:\Apps\postgresql\pgsql-9.5.0\bin>type nul > E:\PGSQL_data\_test_write_permission.txt
C:\Apps\postgresql\pgsql-9.5.0\bin>type nul > E:\PGSQLData\pgsql-9.5\_test_write_permission.txt
C:\Apps\postgresql\pgsql-9.5.0\bin>type nul > C:\Apps\postgresql\pgsql-9.4.5.3\bin\_test_write_permission.txt
C:\Apps\postgresql\pgsql-9.5.0\bin>type nul > C:\Apps\postgresql\pgsql-9.5.0\bin\_test_write_permission.txt

So now I'm even more puzzled than before...


Even more details:

I see that the command to create the internal log file is at /src/bin/pg_upgrade/option.c#L101

Which calls fopen_priv(INTERNAL_LOG_FILE, "a") defined at /src/bin/pg_upgrade/file.c#L243

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.

Any ideas?

Community
  • 1
  • 1
isapir
  • 21,295
  • 13
  • 115
  • 116
  • Please show us the complete command line that you use to run `pg_upgrade`. You should not run that as Administrator, a regular user is enough, but you have to make sure that the access rights on **both** data directories are setup correctly! –  Jan 07 '16 at 21:40
  • @a_horse_with_no_name - I updated the question to show the full command line. I am logged on to Windows as the Administrator so the directories should be accessible to the user account. Do you know where does pg_upgrade try to save pg_upgrade_internal.log to? – isapir Jan 07 '16 at 23:25
  • No idea. I just did an upgrade from 9.4 to 9.5 with a regular user account and everything worked fine, so I guess the file is stored in some temp directory of the current user. I had to quote the path to the `.exe` and I used the wrong way of quoting the path which then resulted in very strange errors. That's why I asked for the full command. –  Jan 07 '16 at 23:34
  • @a_horse_with_no_name When I quoted paths on other PG tools, e.g. `initdb` it failed, so I try to avoid that. For good measure, I tried now to quote all the paths, as well as changing the `\` separator to '/', but I still get the same error. – isapir Jan 07 '16 at 23:42

1 Answers1

30

So the source code comment at /src/bin/pg_upgrade/file.c#L243 /* fopen() file with no group/other permissions */ gave me an idea.

I created a temp folder at C:\temp and gave Write permissions to Everyone, and then ran pg_upgrade from that directory, i.e.

C:\temp>C:\Apps\postgresql\pgsql-9.5.0\bin\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

Whereas before I was trying to run pg_upgrade from the working directory %PGSQL%\bin which did not have a Write permissions to Everyone.

Now I don't get the cannot write to log file pg_upgrade_internal.log error anymore.

The docs actually say pg_upgrade requires write permission in the current directory.

isapir
  • 21,295
  • 13
  • 115
  • 116
  • 2
    yep, have to be in a temp folder, and then call the full path to the p_upgrade utility, thanks – Andrew Jan 25 '17 at 15:05