Everyone has a backup strategy until the day they actually need it. I learned this the hard way years ago when a junior colleague ran a migration against the wrong database and we discovered our "nightly backups" had been failing silently for three weeks. The cron job was fine. The disk it wrote to was full. Nobody had ever tried a restore.
That is the thing about PostgreSQL backups: making them is easy, trusting them is where people get hurt. This guide covers the two tools that matter β pg_dump for logical backups and pg_basebackup for full physical copies β plus the restore drill that turns a backup into something you can actually bet on.
The two kinds of backup (and when each one saves you)
Logical backup ( pg_dump ) exports your data as SQL. It is portable across PostgreSQL versions, you can restore a single table, and the files compress beautifully. This is what you want for most small-to-medium setups.
Physical backup ( pg_basebackup ) copies the whole data directory, including WAL files.β¦