Moving postgresql data to different drive
The following should do it:
- Shut down PostgreSQL
- Make sure PostgreSQL does not run any longer
- Check that PostgreSQL is really stopped
- Copy the old data directory to the new drive
This is usually defined through a commandline parameter (-D
) for your service or through thePGDATA
environment variable. - Update your PostgreSQL configuration (service, environment var) to point to the new data directory.
- If you copied the data, rename the old data directory to make sure PostgreSQL cannot find it any longer. That way you'll get an error message if you didn't get the configuration right.
- Start the service
- If everything is running fine, you can delete the old directory.
- Stop postgresql service
- cp -a source_data_directory destination_data_directory
- chown -R postgres_user /destination_data_directory
- export PGDATA=destination_data_directory
- Changing data directory to destination_data_directory within postgresql.conf
- pg_ctl start