Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I move postgresql data to another directory on Ubuntu over Amazon EC2?

We've been running postgresql 8.4 for quite some time. As with any database, we are slowly reaching our threshold for space. I added another 8 GB EBS drive and mounted it to our instance and configured it to work properly on a directory called /files

Within /files, I manually created

Correct me if I'm wrong, but I believe all postgresql data is stored in /var/lib/postgresql/8.4/main

I backed up the database and I ran sudo /etc/init.d/postgresql stop. This stops the postgresql server. I tried to copy and paste the contents of /var/lib/postgresql/8.4/main into the /files directory but that turned out be a HUGE MESS! due to file permissions. I had to go in and chmod the contents of that folder just so that I could copy and paste them. Some files did not copy fully because of root permissions. I modified the data_directory parameter in postgresql.conf to point to the files directory

 data_directory = '/files/postgresql/main' 

and I ran sudo /etc/init.d/postgresql restart and the server failed to start. Again probably due to permission issues. Amazon EC2 only allows you to access the service as ubuntu by default. You can only access root from within the terminal which makes everything a lot more complicated.

Is there a much cleaner and more efficient step by step way of doing this?

like image 283
deadlock Avatar asked May 21 '13 20:05

deadlock


People also ask

Where is PostgreSQL data stored Ubuntu?

PostgreSQL configuration files are stored in the /etc/postgresql/<version>/main directory. For example, if you install PostgreSQL 12, the configuration files are stored in the /etc/postgresql/12/main directory.


1 Answers

Stop the server.

Copy the datadir while retaining permissions - use cp -aRv.

Then (easiest, as it avoids the need to modify initscripts) just move the old datadir aside and symlink the old path to the new location.

like image 72
Craig Ringer Avatar answered Sep 23 '22 15:09

Craig Ringer