Have you ever made backups of PostgreSQL? How was it done?
sobes.tech AI
Answer from AI
PostgreSQL backups typically use several approaches:
-
pg_dump — a utility for creating a logical dump of the database. It exports the structure and data into an SQL script or archive, which can then be restored.
Example command:
pg_dump -U username -F c -b -v -f backup_file.backup dbnameHere,
-F cis the custom format, convenient for restoration via pg_restore. -
pg_basebackup — used to create a physical copy of the entire database, including all data files. It is used for creating replicas or full recovery.
-
WAL archiving — to enable recovery to a specific point in time (PITR). WAL (Write-Ahead Logging) files are archived separately.
In practice, I set up automated backups using scripts that run pg_dump or pg_basebackup on a schedule (cron), and the files are stored on a remote server or in cloud storage. I also monitored rotation and checked the integrity of backups.