- Initialize a New Data Directory You can use the initdb command to create a new data directory on your desired drive.
Open Command Prompt as Administrator.
Run the following command to initialize a new data directory on your chosen drive:
initdb -D D:\PostgreSQLData
Replace D:\PostgreSQLData with the desired folder path on your other drive.
- Update PostgreSQL Configuration to Use the New Data Directory You need to inform PostgreSQL to use this new location.
Stop the PostgreSQL service:
Open the Services Manager (press Win + R, type services.msc, and hit Enter).
Find the PostgreSQL service (e.g., postgresql-x64-17) and stop it.
Edit the PostgreSQL service to point to the new data directory:
Open a Command Prompt as Administrator.
Run this command:
pg_ctl register -N "postgresql-x64-17" -D "D:\PostgreSQLData"
Replace "D:\PostgreSQLData" with your new data directory path.
Update postgresql.conf if needed:
Locate the postgresql.conf file in your new data directory.
Check for any absolute paths that reference the old directory and update them to the new directory.
- Restart the PostgreSQL Service Go back to the Services Manager and restart the PostgreSQL service. Alternative During Installation If you're installing PostgreSQL for the first time:
During installation, choose the "Advanced Options" step.
Change the data directory path to your preferred location (e.g., D:\PostgreSQLData).
Additional Notes
Ensure the drive you choose has sufficient space for your database needs.
Back up your data regularly to avoid accidental data loss, regardless of the drive used.
**
Fixing Services Issue
**
net stop postgresql-x64-17
cd "C:\Program Files\PostgreSQL\17\bin"
pg_ctl unregister -N "postgresql-x64-17"
pg_ctl register -N "postgresql-x64-17" -D "C:\Program Files\PostgreSQL\17\data"
net start postgresql-x64-17
Top comments (0)