In this article, we will see how to perform custom format backup and restore of PostgreSQL database.
While plain text format produced by pg_dump is natural and simple, at the same time, it is not very flexible because it can create huge output files.
PostgreSQL has a nice little feature that allows users to export the so-called “custom format”, a format that is archived by default.
Syntax for custom format:
To produce a backup file in custom dump format, we need to add the -Fc option:
pg_dump -Fc database_name > database.dump
pg_dump -Fc database_name > database.dump
Example to take database backup using custom format -Fc:
In below example, r2schools is the database name and -Fc is custom format.
pg_dump -d r2schools -Fc >r2schools_fc.dump
Restore the backup taken from with -Fc format on target PostgreSQL server:
Do the scp as shown in the article from source to target serverSCP example
Now connect to target server and load the database with backup taken on source server using -Fc option.
postgres@mongodb2:/home/r2schools/pgbackups$ dropdb r2schools postgres@mongodb2:/home/r2schools/pgbackups$ createdb r2schools postgres@mongodb2:/home/r2schools/pgbackups$ pg_restore -d r2schools r2schools_fc.dump