PG generated database backup file can have two, one is SQL files, binary files, binary files can only be restored using pg_restore.
BRIEF DESCRIPTION PostgreSQL database operations
PostgreSQL database version
psql --version
psql (PostgreSQL) 9.1.3
The following is the operation under linux, the windows will be replaced su -postgres
Run type cmd → d: →
cd D: \ Program Files \ PostgreSQL \ 9.2 \ bin, create the following table, when you delete the table, need to operate in postgres, and therefore need to create a database front delete input psql -u postgres
First, the database backup
1, the backup database structure
su - postgres
pg_dump -Fc -s -f testdbschema.sql testdb
2, back up the database data
su - postgres
pg_dump -Fc -a -f testdbdata.sql testdb
3, backup database structure and data
su - postgres
pg_dump -Fc -f testdbschemadata.sql testdb
4, the backup table structure specified in the database
pg_dump -Fc -s -t citycode -f citycode_schema.sql testdb
5, the backup data is specified in the database table
pg_dump -Fc -a -t citycode -f citycode_data.sql testdb
.6, designated backup database tables (and data structure)
pg_dump -Fc -t citycode -f citycode_schemadata.sql testdb
Second, delete the database
su - postgres
dropdb testdb
Third, restore the database
1, create a new database testdb
su - postgres
createdb testdb;
2, the recovery data structure (only schema)
su - postgres
pg_restore -s -d testdb testdbschema.sql
3, database data recovery (only data)
su - postgres
pg_restore -a -d testdb testdbdata.sql
4, the database structure and data recovery (schema and data)
su - postgres
pg_restore -d testdb testdbschemadata.sql
5, specify the table data recovery
1) Delete table
psql testdb
DROP TABLE citycode;
2) Recovery table structure
pg_restore -s -t citycode -d testdb citycode_schema.sql
3) restore table data
pg_restore -a -t citycode -d testdb citycode_data.sql
4) Recovery table (data structure)
pg_restore -t citycode -d testdb citycode_schemadata.sql
More than backup and recovery-related operations for static (no data growth) database.
IMPORTANT: pg_restore can be used to restore the pg_dump command (Fc \ Ft) format backup of data files. If there is no backup command execution pg_dump this format parameter declaration, an error message may occur when pg_restore restore "pg_restore: [archiver] input file does not appear to be a valid archive".
pg_dump official documents
https://www.postgresql.org/docs/10/app-pgdump.html
pg_dumpall
https://www.postgresql.org/docs/10/app-pg-dumpall.html
pg_restore