Sobes.tech
Middle

Have you ever made backups of PostgreSQL? How was it done?

sobes.tech AI

Answer from AI

PostgreSQL backups typically use several approaches:

  1. 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 dbname
    

    Here, -F c is the custom format, convenient for restoration via pg_restore.

  2. 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.

  3. 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.