How To Move a PostgreSQL Data Directory to a New Location

Time goes by – and the database content grows larger in number. Sometimes it demands changing database files localization. Unfortunately, older PostgreSQL versions do not offer the possibility of relocating DATA folder. Thus, files ought to be moved manually and the service should be configured, so it would use a new localisation of data files. .

Solution:

Warning

Incorrect Register editor usage may cause serious problems which would result in a need to reinstall your system. We cannot guarantee that solving problems caused by inappropriate usage of Register editor will be possible. Use Register Editor on your own responsibility.

 

  1. Right-click the position to display context menu and choose Stop option.
  2. Enter Windows service [services.msc] find PostgreSQL service (the name may differ dependently on installed version).

3. Move DATA folder to new localization (the installation path is C:\Program Files\PostgreSQL\x.x\data), x.x value describes the version of storage engine

4. Open Windows Register Editor [regedit.exe] and find the key.

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\pgsql-version-number

5. Double-click ImagePath value to open it and find D parameter. D parameter describes the localization of DATA folder for a given PostgreSQL instance. Change path to the new localization of the folder and save the changes.
6. After implementing the changes within the register open PostgreSQL service. It may be done similarily to stopping it by choosing Launch option from the context menu.



Was this article helpful?

Related Articles