by bugsbunny » Mon Apr 21, 2008 8:50 am
You can fix it easier than that.
The database cluster itself is located in a subdirectory called PGDATA (it might be DATA, I don't have a current Windows install to check on). Within that sub-directory you'll find the following:
PG_VERSION - this file contains the Postgres version number associated with this cluster
postmaster.opts - this file contains the most recent command line options used to start the Postgres server
postmaster.pid - a lock file which should only be found while the server is running
postgresql.conf - the postgres configuration file
pg_hba.conf - client authentication file
pg_ident.conf - ident map file (used in conjunction with pg_hba.conf for some types of authentication)
You then have a number of sub-directories which contain the actual data files for the cluster.
Uninstall Postgres. It will leave your PGDATA sub-directory intact, but you can just copy that folder to a safe location before uninstalling if you want to be sure (better safe than sorry).
Now install postgres to the new location. Make sure that it's correctly installed and working, then shutdown the server.
Replace all the sub-directories within the new PGDATA directory with the sub-directories from the old one. Do NOT replace any of the configuration files (although if you do it actually shouldn't hurt anything assuming that they're still at the default levels).
Restart postgres.
Done.
Alternately you can leave your current postgres install alone and simply move the actual cluster to the new drive.
Shutdown Postgres.
Copy (don't move for the moment) the entire PGDATA directory to the new drive (I'll assume that it's D: and you copied to D:\PGDATA)
Set correct permissions on the new directory ensuring that the user that the postgres service will be running as has read/write access to the directory and all subdirectories and files.
From D:\PGDATA delete the 3 configuration files (postgresql.conf , pg_hba.conf , pg_ident.conf) along with postmaster.opts and, if it exists, postmaster.pid. Do NOT delete the PG_VERSION file.
Now, in the original PGDATA directory open up postgresql.conf in a text editor. In there, right towards the top, you should find a section:
#------------------------------------------------------------------------------
# FILE LOCATIONS
#------------------------------------------------------------------------------
Find the line that starts:
#data_directory =
Uncomment it by removing the # and enter your new location:
data_directory = 'D:\PGDATA'
Save the modified file.
Delete all the subdirectories and all the files other than the 3 .conf files.
Restart postgres. It should now be accessing the data in the new location.
If for some strange reason it doesn't work you can always copy the data back and undo the change to the postgresql.conf file.