Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Maulik Paneliya
Maulik Paneliya

Posted on • Edited on

     

Store PostgreSQL Data on Another Drive (D: or E:)

  1. Initialize a New Data DirectoryYou 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
Enter fullscreen modeExit fullscreen mode

Replace D:\PostgreSQLData with the desired folder path on your other drive.

  1. Update PostgreSQL Configuration to Use the New Data DirectoryYou 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"
Enter fullscreen modeExit fullscreen mode

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.

  1. Restart the PostgreSQL ServiceGo back to the Services Manager and restart the PostgreSQL service.Alternative During InstallationIf 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-17cd C:\Program Files\PostgreSQL\17\binpg_ctl unregister -N "postgresql-x64-17pg_ctl register -N "postgresql-x64-17" -D C:\Program Files\PostgreSQL\17\datanet start postgresql-x64-17
Enter fullscreen modeExit fullscreen mode

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

Software Developer
  • Location
    India
  • Education
    Msc.IT
  • Pronouns
    He
  • Work
    Software Developer
  • Joined

More fromMaulik Paneliya

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp