HiveBrain v1.2.0
Get Started
← Back to all entries
patternsqlMajor

Moving postgresql data to different drive

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
postgresqldifferentmovingdrivedata

Problem

I am using AWS as my cloud environment. I installed PostgreSQL on the same drive as my root instance volume. I have attached and mounted the second drive to my instance. Now I want to move all my PostgreSQL data to the different drive. I am still in development mode so I can delete the old data if it makes transfer easier at this point of time. What is the best way to do this?

Is PostgreSQL tablespace something which I should look at?

Solution

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


The data directory is usually defined through a commandline parameter (-D) for your service or through the PGDATA environment variable.

  • Update your PostgreSQL configuration (service, environment var) to point to the new data directory. In Windows you can use the sc utility or pg_ctl (from the Postgres binaries)



  • 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.

Context

StackExchange Database Administrators Q#28926, answer score: 33

Revisions (0)

No revisions yet.