2

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

pedrovgp
  • 767
  • 9
  • 23

2 Answers2

4

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.

  • It did not work. Doesn't this approach has the same effect as editing regedit, as advised in the first link? – pedrovgp Feb 21 '17 at 10:55
  • @pedrovgp what it seems to do is delete and then create the Windows service for PostgreSQL. It worked for me. P.S. Make sure to run Command Prompt as administrator before running these commands. – Gary Sheppard Jul 22 '17 at 14:30
0

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

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

Falinn
  • 151
  • 1
  • 6