postgres pg_restore - ghdrako/doc_snipets GitHub Wiki
- https://www.postgresql.org/docs/current/app-pgrestore.html
- https://severalnines.com/blog/pgrestore-alternatives-postgresql-backup-and-automatic-recovery-clustercontrol/
pg_dump creates a portable file format that can be used to transfer data between different PostgreSQL installations or even between different database management systems.
pg_restore is a PostgreSQL utility that restores a backup file created by pg_dump or a similar tool. It reads the SQL statements from the backup file and applies them to a new or existing database, creating a copy of the original database. pg_restore can be used to restore the entire database, specific tables or schemas, or even individual records.
Restore to existing database
In example with change collation
pg_restore -d target_database /path/to/the/backup.dbbackup
-d
--dbname
: specifies the target database to restore to. By default, pg_restore creates a new database with the same name as the original database.-F
: specifies the backup format. The default format is plain text (-Fp
), but you can also use binary (-Fc
) or directory (-Fd
) formats.
Restore to recreated identical database
If you are certain that there is no data of any value in the target database (which will be deleted by the following command) try:
sudo -u postgres pg_restore --create --clean -d postgres /path/to/dbbackup.sql
–c
--clean
: remove database objects before recreating them-C
--create
: construct a database before restoring it
psql "sslmode=verify-ca sslrootcert=server-ca.pem sslcert=client-cert.pem sslkey=client-key.pem hostaddr=<ip> port=5432 user=postgres dbname=postgres"
pg_dump "sslmode=verify-ca sslrootcert=server-ca.pem sslcert=client-cert.pem sslkey=client-key.pem hostaddr=10.223.208.206 port=5432 user=ebkadm dbname=ebkdb" --format=custom \
--no-owner \
--no-acl \
> ebkdb.dmp
pg_restore -d "sslmode=verify-ca sslrootcert=server-ca.pem sslcert=client-cert.pem sslkey=client-key.pem hostaddr=<ip> port=5432 user=ebkadm dbname=ebkdb" ebkdb.dmp