Talk:Change the default PGDATA directory on Windows
From PostgreSQL wiki
the described method for change of the default PGDATA directory on Windows (XP) (editing the registry) does not work for me (postmaster is crashing in this way. Maybe version problem? I tried only with 8.3.3.-1, and I had anyway a lot of compatibility problems with this version when I tried upgrading from 8.1.5). However, at least I found a way how to start a new database in a custom directory. I couldn't find a working how2 (for beginners) so far, so for those interested, here's the way I did it:
(note: you have to have an up-and-running standard psql installation for this, be administrator and know the postmaster service account password)
- Stop the Postmaster Service (open services panel -> klick on postgresql server -> stop)
- in command-line window, enter
runas /noprofile /env /user:<domain>\<username> cmd
(with username being the name of the account used for running the postmaster service)
- enter the corresponding password
- now a command-line window opens, run under the postmaster service account
- in this window, type
initdb -D <path> -E SQL_ASCII -U <username> -W
or something similar, depending on your configuration needs (try initdb --help). (with username being the name of the database superuser. This will create a new database in the chosen directory, with all necessary rights for postmaster to access it.
- close the command-line window run under postmaster service account
- as Admin: unregister the old service (instead of directly altering something in the registry via regedit):
pg_ctl unregister -N "pgsql-8.3"
"pgsql-8.3" is the service name. If you are running a different version, the name will be different. You can find the service name under "Services" -> right-klick on the corresponding service -> properties
- register a new service, giving the new path for the database:
pg_ctl register -N "pgsql-8.3" -U <username> -P <password> -D <path>
- start the service
I hope this comment will be helpful for someone.