Postgres service won't start in Windows after pgdata directory was moved

10.1k Views Asked by At

I followed these instructions to move Postgres data directory from C:\Users\username\Documents\dir\postgres96_data to C:\Users\username\Documents\postgres96_data.

Now the Postgres service won't start. Trying to start it manually yields the following message (freely translated from pt-br):

"The postgres-x64-9.6 service on Local Computer started then stopped. Some services stop automatically if they are not beeing used by other services or programs."

I tried (successfully) to start the database in cmd.exe, with the command

"C:\Program Files\PostgreSQL\9.6\bin\pg_ctl.exe" start -D "C:\Users\username\Documents\postgres96_data" -w

The log was:

2017-02-20 07:33:26 BRT LOG:  database system was interrupted; last known up at 2017-02-18 09:52:00 BRT
2017-02-20 07:33:27 BRT FATAL:  the database system is starting up
... 
2017-02-20 07:35:10 BRT FATAL:  the database system is starting up
2017-02-20 07:36:19 BRT LOG:  database system was not properly shut down; automatic recovery in progress 
2017-02-20 07:36:19 BRT LOG: invalid record length at 6/438EBB88: wanted 24, got 0 
2017-02-20 07:36:19 BRT LOG:  redo is not required 
2017-02-20 07:36:19 BRT LOG: MultiXact member wraparound protections are now enabled 
2017-02-20 07:36:19 BRT LOG:  sistema de banco de dados está pronto para aceitar conexões [database system is ready to accept conections, free translation] 
2017-02-20 07:36:21 BRT LOG:  autovacuum launcher started

PREVIOUS RESEARCH

Link

Link

Link

Link

2

There are 2 best solutions below

0
On

Granting Full permission on the data directory, to the logged-in user worked for me.

Data_Directory - Properties - Security - Add User - Grant Full Permission

2
On

You need to change the service definition. The service is still using the old data directory.

To change the service, remove it and re-create it:

pg_ctl unregister -N postgres-x64-9.6

Then re-create it using the new data directory:

pg_ctl register -N postgres-x64-9.6 -D "C:\Users\username\Documents\postgres96_data"

This assumes you were using a default installation where the service runs using the built-in "Network Account". If that isn't the case you need to supply the necessary username and password with the -U and -P parameters to when registering the service.