Backing Up the Database
To prevent data loss, you are advised to back up the database data before uninstalling the database. Perform backups as required.
Backing Up the Database
- Log in to the database as the gpadmin user.
1su - gpadmin
- Back up databases.
- Back up a single database. In the following command, databasename indicates the name of the database to be backed up, which must exist in the database. databasename.dump is the name of the backup file. By default, the backup file is stored in the current directory.
1pg_dump -Fc databasename > databasename.dump
- Back up all databases. In the following command, all.dump indicates the name of the backup file. By default, the file is stored in the current directory.
1pg_dumpall >all.dump
- Back up a single database. In the following command, databasename indicates the name of the database to be backed up, which must exist in the database. databasename.dump is the name of the backup file. By default, the backup file is stored in the current directory.
Restoring the Database
- Log in to the database as the gpadmin user.
1su - gpadmin
- Restore databases.
- Restore a single database. In the following command, databasename indicates the name of the database to be restored, which must exist in the database. databasename.dump is the file used for restoration. The file path may vary.
1pg_restore -d databasename databasename.dump
- Restore all databases. In the following command, all.dump is the file used for restoration. The file path may vary.
psql -f all.dump postgres
- Restore a single database. In the following command, databasename indicates the name of the database to be restored, which must exist in the database. databasename.dump is the file used for restoration. The file path may vary.
Parent topic: Using the Database