- Stop the PostgreSQL Service:
- First, stop the PostgreSQL service. You can do this by going to Start > Services, scrolling down to
postgresql-x64-{version}
, and right-clicking to stop it1. - it is usually advised to disable it as well to prevent accidental starts
- First, stop the PostgreSQL service. You can do this by going to Start > Services, scrolling down to
- Copy Data:
- Next, copy the data from the existing location (usually
C:\Program Files\PostgreSQL\{version}\data
) to the new location (e.g.,E:\pg_dbdata
)2. using Robocopy to ensure all permissions are copied
- Next, copy the data from the existing location (usually
- Modify the Registry keys ()
- Open the Windows Registry Editor (
regedit.exe
). - Navigate to
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\pgsql-some version
. - Double-click on “ImagePath” and change the directory after the
-D
option to your new location. Enclose the path in quotes if it contains spaces1. - Navigate to
HKEY_LOCAL_MACHINE\SOFTWARE\PostgreSQL\Installations\postgresql-x64-{Version}
. - Double-click on “Data Directory” and change the directory. Enclose the path in quotes if it contains spaces1.
- Navigate to
HKEY_LOCAL_MACHINE\SOFTWARE\PostgreSQL\Services\postgresql-x64-{Version}
. - Double-click on “Data Directory” and change the directory. Enclose the path in quotes if it contains spaces1.
- Open the Windows Registry Editor (
- Modify
postgresql.conf
(optional):- You might need to modify the
postgresql.conf
file if you’ve moved everything to the new location. However, in many cases, this step isn’t necessary2.
- You might need to modify the
- Restart the PostgreSQL Service:
- Finally, restart the PostgreSQL service to apply the changes.
Leave a Reply