NMS
Backup and Restore Guide
Serial.no.
Doc version Version 4.0
Prepared by BluePal solutions (Pvt) Ltd.
Approved by Kernex Microsystems (India) Ltd.
Date May 19, 2025
Table of Contents
PostgreSQL Backup and Restore Guide............................................................................................................3
1. Backup Instructions....................................................................................................................................3
Using pg_dump (Recommended for single database).............................................................3
2. Restore Instructions...................................................................................................................................4
Using pg_restore......................................................................................................................................4
3. Prerequisites & Tips................................................................................................................................... 5
PostgreSQL Backup and Restore Guide
Managing data reliability is a critical part of any production-grade system. This
guide provides clear, step-by-step instructions on how to back up and restore
PostgreSQL databases using both command-line tools and best practices.
Whether you're deploying to cloud-hosted environments like AWS RDS or
managing on-premise PostgreSQL instances, this guide ensures your data can be
safely backed up, moved, or restored without data loss. It covers:
Generating custom-format .dump files using pg_dump
Restoring backups with pg_restore
Common pitfalls, prerequisites, and security considerations
1. Backup Instructions
Using pg_dump (Recommended for single database)
Command:
pg_dump -U <db_username> -h <host> -p <port> -F c -b -v -
f "backup_file.dump" <database_name>
- -F c: Custom format (recommended for restore)
- -b: Include blobs
- -v: Verbose mode
- -f: Output file name
Example:
pg_dump -U postgres -h database-1.c7m0mks0224e.us-
west-1.rds.amazonaws.com -p 5432 -F c -b -v -f
"nms_backup.dump" nms
2. Restore Instructions
Using pg_restore
Command:
pg_restore -U <db_username> -h <host> -p <port> -d
<target_database> -v "backup_file.dump"
Note: You must create the database manually before restoring:
createdb -U postgres -h database-1.c7m0mks0224e.us-
west-1.rds.amazonaws.com -p 5432 nms
Example:
createdb -U postgres -h database-1.c7m0mks0224e.us-
west-1.rds.amazonaws.com -p 5432 nms
pg_restore -U postgres -h database-1.c7m0mks0224e.us-
west-1.rds.amazonaws.com -p 5432 -d nms -v
"nms_backup.dump"
3. Prerequisites & Tips
Ensure PostgreSQL client tools (pg_dump, pg_restore, createdb) are
installed and in your PATH.
Use pgAdmin if you prefer a GUI-based backup and restore.
You may be prompted for a password. For automation, set the
PGPASSWORD environment variable.
Restoring into an existing database may overwrite data—use with
caution.
If you encounter errors, check:
1.Database user permissions
2.Network/firewall settings
3.That the backup file path is correct
4.That the target database exists