Moving postgresql data to different drive

The following should do it:

  1. Shut down PostgreSQL
  2. Make sure PostgreSQL does not run any longer
  3. Check that PostgreSQL is really stopped
  4. Copy the old data directory to the new drive
    This is usually defined through a commandline parameter (-D) for your service or through the PGDATA environment variable.
  5. Update your PostgreSQL configuration (service, environment var) to point to the new data directory.
  6. 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.
  7. Start the service
  8. If everything is running fine, you can delete the old directory.

  1. Stop postgresql service
  2. cp -a source_data_directory destination_data_directory
  3. chown -R postgres_user /destination_data_directory
  4. export PGDATA=destination_data_directory
  5. Changing data directory to destination_data_directory within postgresql.conf
  6. pg_ctl start