Search code examples
databasepostgresqlubuntubackupupgrade

Backing up old clusters AFTER upgrading Postgresql


So, I was careless and upgraded Ubuntu from 18 to 20 -- thus postgresql from 10 to 12 -- WITHOUT making backups of my postgresql-10 cluster. Now that I'm looking into upgrading the cluster to work with 12, I'm realizing that was a mistake. Is there a way to back them up before attempting to upgrade them, now that postgres itself is already upgraded?

I could just copy the whole data folder and zip it up somewhere, but (a) that'd be a lot of disk space, and (b) I definitely don't yet understand postgres well enough to restore from those files.

(The last annoying thing here, which maybe deserves its own question, is that my pg10 data directory is on an external drive, which I'd like to keep using. Even if I can solve my backup problem, I'm not sure what the "easiest" way to do this is...)

EDIT: Actually I think my problem is a little different than I thought, and the postgres backup tools might still work for me. I will report back!


Solution

  • It turns out I had two versions of Postgres installed simultaneously, so I was able to backup with a simple 'pg_dumpall' before upgrading the clusters. This manpage and this blogpost were both helpful in sorting things out.

    Because I had a lot of onboard storage free I let pg_upgradecluster populate the default data folder, and then I copied it all over to my external, and edited the conf file to point back to that. (And then, yes, I made a backup of the upgraded cluster.)