Postgresql – Restoring a database using Postgres data files instead of .sql files

migrationpostgresql

I backed up my Ubuntu 14.04 system using rsync to a USB stick, but apparently it wasn't formatted for booting. The original disk has been erased and I put a fresh install of Ubuntu on it. In migrating my data I forgot to dump one of my postgres databases to SQL, and I need to migrate it to my new install of Ubuntu.

I'm considering formatting a bootable disk and then attempting to rsync my old system to that for disk so I can boot and dump my database to SQL. But that's a discussion for a different forum.

I'm wondering if it's possible to use the data files from my old system to restore my database (i.e. copy /var/lib/postgresql/9.3/main) from my old install to my new install? Has anyone ever done this? I did try just copying the data file but it caused Postgres to break beyond repair. I had to delete it entirely and reinstall.

I know it's possible with MySQL, but I'm less familiar with Postgres.

Thanks!

Best Answer

Rsync is a supported backup method for postgresql. However it has some caveats that you need to be aware of. Namely the database should be offline when the sync is done.

So if your database was offline when you synced, you could restore it jsut fine.