Postgresql – Why does changing data directory for PostgreSQL 9.5 in Server 2008 lead to “directory does not exist”

file-permissionspermissionspostgresqlwindows-server-2008

I'm trying to migrate a PostgreSQL 9.5 database to a larger disk E on a Windows 2008 Server. After stopping the service I initially tried copying the the data folder to the new disk and then changed the PostgreSQL Service's executable path using

sc config postgresql-x64-9.5 binPath= "\"C:\Program Files\PostgreSQL\9.5\bin\pg_ctl.exe\" runservice -N \"postgresql-x64-9.5\" -D \"E:\pg_db\data\" -w"

I changed the permissions on the data folder to include "Network Services" by right-clicking on the folder and going Properties. Under the Security Tab click "Edit..." and then "Add...". Type "Network Service" and then click "Check Names" and then OK.

But when I hit Start in Services, the following error message appears under the Windows Event Viewer:

FATAL: data directory "E:/pg_db/data" does not exist.

I even tried creating a new data directory from the administrator cmd prompt using instructions here but eventually got the same error.

I see one of the answers to the "Similar Questions" as I'm writing this is "It is easier if you reinstall Postgre and select data folder during install." That can't be the best we can do.

Best Answer

Found the problem while scanning through the Running & Installing PostgreSQL On Native Windows Wiki

The PostgreSQL service account needs read permissions on all directories leading up to the service directory. It needs write permissions only on the data directory.

I had set the write permission on the data directory for Network Service but not the read permission on the directories above it.