PostgreSQL

Restore & Clone PostgreSQL from Snapshot Backup

If you are using snapshots as your backup strategy then there may be times where you want to clone the snapshot and restore it on another server. I’ll go through that scenario. My environment is Redhat 6.1, PostgreSQL 9.2 and Netapp Snapshots.

It’ll be a similar process with other snapshot technologies but the cloning and mounting of disks may differ. Firstly, we need to get the mounts cloned and presented to the appropriate server which can be done by a trusty storage admin.

We add the above details to /ets/fstab and mount our volumes. We need to create directories first, mount and change permissions. The server that I’m working on already has a database running on it under /pg01/data so I’ve appended “_r” to my mounts.

Now that we have our cloned filesystems ready to go, we can modify the appropriate values in /pg01_r/data/postgresql.conf. The following were relevant in my environment:

I needed to change the listen_address as I was on a new host. I already had a postgresql cluster running on the default port so that needed to change and my filesystem was slightly different from the original server so my archive command needed a tweak.

I also had to change my tablespace and xlog symlinks as they were still pointing to the “/pg01” directory and not the new cloned mounts.

And finally create the recovery.conf in the $PGDATA directory.

I wanted to recovery to our last transaction so I didn’t specify any point in time values but it could have easily be done with recovery_target_time. Now we can start our cluster.

After a few minutes our cluster should be recovered, cloned and ready to go. We can check our postgresql.log file and see output like this.

Leave a Reply

Your email address will not be published. Required fields are marked *

CAPTCHA * Time limit is exhausted. Please reload CAPTCHA.