Junior — Middle
How did you create backups of the PostgreSQL database?
sobes.tech AI
Answer from AI
To create backups of PostgreSQL, the utility pg_dump is typically used for logical backups and pg_basebackup for physical ones.
- pg_dump — creates a database dump as an SQL script or archive, which can be restored on any PostgreSQL version. Example:
pg_dump -U username -F c -b -v -f backup_file.backup dbname
- pg_basebackup — creates a physical copy of the entire database, useful for replication and file-level recovery:
pg_basebackup -U replication_user -D /path/to/backup -Fp -Xs -P
You can also use tools for incremental backups, such as WAL archiving (Write-Ahead Logging), to save changes between full backups.
It is important to automate the process using scripts and schedulers (cron), as well as to verify the integrity and recoverability from backups.