-1

My PostgreSQL installation by default uses /var/lib/pgsql directory to store data, backups and configuration files. As my disk space is running out, I have installed new hardware and mounted it in the /data directory. Having this done, I would like now to move the data and backups there.

What is the best way to do this transition correctly? Note that I do not require atomic transition – the PostgreSQL service can be offline while the data transfer is in progress.

Thanks in advance,

Pete.

2 Answers2

2

Depend on how your server was configured, you can simply change your PG_DATA variable.

But you can easily do:

service postgresql stop
mv /var/lib/pgsql/ /data/pgsql
ln -s /data/pgsql /var/lib/pgsql
service postgresql start

It will do the job.

otaviofcs
  • 178
0

There are a couple of options really. The most straightforward may be to shut the server down and then copy the whole tree under /var/lib/pgsql to the new disk then bind mount or mount it back to /var/lib/pgsql. I would probably choose the latter ymmv.

mkdir /data/pgsql
cd /var/lib/pgsql
cp -aRp * /data/pgsql
cd ..
mv pgsql pgsql.safe
mkdir pgsql
mount -obind /data/pgsql /var/lib/pgsql

Carry out your testing and then if that works add a suitable entry to /etc/fstab.

Similarly you could copy the entire contents of /var/lib/pgsql to /data then unmount /data and mount it on /var/lib/pgsql (having moved the old one out of the way and recreated the directory). Again run your tests and make suitable changes to fstab.

user9517
  • 117,122