Change the default PostgreSQL data directory on Windows

pgsql logoOur database which is storing every minute telemetry data is now getting bigger and need to be relocated to another newly mounted drive. So, I need to relocate the old data to a new disk. Actually, I don’t need to do this if my drive is a dynamic drive.

As we already know, PostgresSQL for Windows installs the PGDATA directory by default into “C:\Program Files\PostgreSQL\8.3\data”. This mini-HOWTO explains how to change the default PGDATA directory to another location. Note that 8.3 is the version number of my current PostgreSQL installation. It could be varied based on your installed version.

Step 1: Stop The PostgreSQL Service
Close all applications that are currently connected to your database, then go to Windows Services Management and stop the PostgreSQL service:

Start->Settings->Control Panel->Administrative Tools->Services

You should check the task manager to see if any postgresql.exe instances are still running. If so, DO NOT TERMINATE them, instead close all applications that are still connected to the database. Sometimes services like webservers keep persistent connections. In this case you also should stop these services.

Step 2: Change Registry Values

Start the Windows Registry Editor (regedit.exe) and navigate to: “HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\pgsql-8.3″
. Double click on “ImagePath” and change the diectory after the “-D” option to your new location. If the path to your new location contains spaces, you should then enclose it with quotes.

Registry Editor

Step 3: Move the data folder to the new location

Move your current PGDATA directory to the directory you just specified in Step 2.
Please note that you should do this as Administrator on server machines.

Step 4: Restart The PostgreSQL Service

Before you can start your database you must close and re-open the Windows
Services Management window. This refreshes the path you just changed in the registry without the need to restart your system.

After closing and re-opening the Services Management window, you should check the “path to executable” information of the PostgreSQL Database service. The path after “-D” option should be pointing to your new directory now.

Service properties

Now that the PGDATA directory has been re-located and the service startup parameter in the registry has been modified. The new directory should be granted permissions to PostgreSQL service to access it.

Directory Properties Dialog

Add username which PostgreSQL service use.

And then, set some required permissions PostgreSQL operations.

Now, you can go ahead and start the service.



Tags: , , , , , ,

38 Responses to “Change the default PostgreSQL data directory on Windows”

  1. Arlette Siciliano Says:

    great post,however i have some difficulty in understanding the final paragraph, can you please describe a bit more?

  2. Cialis Says:

    gzuGgp Excellent article, I will take note. Many thanks for the story!

  3. Large Plastic Storage Boxes Says:

    Very super information.

  4. tramadoltsguq Says:

    Awesome Post. I add this Blog to my bookmarks.

  5. Many Grodin Says:

    Hi There! I ran into your site absolutely by mistake, and it turned out to being a blessing. You bring a lot of interesting things to the table and I will be back for more :) Thanks!

  6. tramadolipojl Says:

    Thanks For This Blog, was added to my bookmarks.

  7. fix windows registry errors Says:

    Intimately, the post is actually the best topic on this related issue. I fit in with your conclusions and will eagerly look forward to your approaching updates. Just saying thanks will not just be sufficient, for the phenomenal clarity in your writing. I will immediately grab your rss feed to stay abreast of any updates.

  8. low cost links Says:

    Cool post.

  9. graphite golf clubs Says:

    You certainly deserve a round of applause for your post and more specifically, your blog in general. Very high quality material

  10. lapel pins Says:

    Great info, thank you for making this available on your blog.

  11. scuba diving Says:

    You certainly deserve a round of applause for your post and more specifically, your blog in general. Very high quality material

  12. cherche viagra Says:

    So why you do this?

  13. Ron Cannell Says:

    For some reason only half of the submit is being displayed, is it my browser or the website?

  14. Watch Eclipse Online Says:

    I just visited your site through Facebook… would you be interested in getting weblog partners?

  15. Watch Eclipse Online Says:

    I just visited your website via Facebook… would you be interested in getting weblog partners?

  16. Madlen Says:

    Hi Webmaster, If you’re interested in making money from your blog and driving thousands of free visitors to your website then i will show you a secret way to build a Blog Empire that earned over $1,107,693! Just check it out now: http://tinyurl.com/new-blogging-system

  17. vemmaap Says:

    I find myself coming to your blog more and more often to the point where my visits are almost daily now!

  18. vemmagg Says:

    I just sent this post to a bunch of my friends as I agree with most of what you’re saying here and the way you’ve presented it is awesome.

  19. tahitian noni juice Says:

    I’ve been visiting your blog for a while now and I always find a gem in your new posts. Thanks for sharing.

  20. scuba diving Says:

    You certainly have some agreeable opinions and views. Your blog provides a fresh look at the subject.

  21. gry Says:

    Awesome Post. I add this Post to my bookmarks.

  22. Francisco Odeh Says:

    Hi administrator I wallow in w/ ur article . may i copy this know-how for my academic check ? thanks

  23. Mohamed Bersaw Says:

    Hi administrator I rejoice in w/ ur content . can i copy this knowledge being my college test ? thanks

  24. Douglas Hallczuk Says:

    Hello admin , i want how to ask question about A New content. is this okay ?(1st)Whats the meaning for which content? but i enjoy using Your New url. (2nd) are you have facebook or twitter > end users may add A New facebook badge just so i can like Your web site. like my blog Thank end usersbest Regards admin as for (sorry,if my english is bad. iam an italian :p)

  25. Jeramy Garski Says:

    Hello dude,i like Your site ideal much. attain u have on suggestion being my site? thanks being Your attention

  26. Mckenzie Vangalder Says:

    Hello dude,i likes Your website very a lot. do u have on suggestion as my homepage? thanks as A New attention

  27. Mckenzie Vangalder Says:

    Hello dude,i like this Your blog very a lot. achieve u have suggestion for my site? thanks for Your New attention

  28. noni Says:

    Awesome Blog. I add this Blog to my bookmarks.

  29. kosmetyki Says:

    You certainly have some agreeable opinions and views. Your blog provides a fresh look at the subject.

  30. noni Says:

    You certainly have some agreeable opinions and views. Your blog provides a fresh look at the subject.

  31. noni Says:

    Very informative post. Thanks for taking the time to share your view with us.

  32. canon lenses Says:

    You certainly deserve a round of applause for your post and more specifically, your blog in general. Very high quality material

  33. tapety Says:

    You certainly have some agreeable opinions and views. Your blog provides a fresh look at the subject.

  34. noni Says:

    Thanks For This Post, was added to my bookmarks.

  35. sok noni Says:

    I find myself coming to your blog more and more often to the point where my visits are almost daily now!

  36. gadget show modern warfare 2 Says:

    Hello dude,i like Your blog ideal much. achieve u have on suggestion for my website? thanks for Ones New attention

  37. gadgets for vista Says:

    Hello dude,i like Your site ideal a lot. accomplish u have suggestion for my homepage? thanks being A New attention

  38. Min Korst Says:

    Hello dude,i liking Ones homepage in truth a lot. do u have suggestion as my site? thanks being A New attention

Leave a Reply