2016-01-07 14:45:17 +08:00
|
|
|
# pg_restore
|
|
|
|
|
|
|
|
> Restore a PostgreSQL database from an archive file created by pg_dump.
|
2019-05-29 14:53:44 +01:00
|
|
|
> More information: <https://www.postgresql.org/docs/current/app-pgrestore.html>.
|
2016-01-07 14:45:17 +08:00
|
|
|
|
|
|
|
- Restore an archive into an existing database:
|
|
|
|
|
2025-04-22 06:20:48 +03:00
|
|
|
`pg_restore {{[-d|--dbname]}} {{db_name}} {{archive_file.dump}}`
|
2016-01-07 14:45:17 +08:00
|
|
|
|
|
|
|
- Same as above, customize username:
|
|
|
|
|
2025-04-22 06:20:48 +03:00
|
|
|
`pg_restore {{[-U|--username]}} {{username}} {{[-d|--dbname]}} {{db_name}} {{archive_file.dump}}`
|
2016-01-07 14:45:17 +08:00
|
|
|
|
|
|
|
- Same as above, customize host and port:
|
|
|
|
|
2025-04-22 06:20:48 +03:00
|
|
|
`pg_restore {{[-h|--host]}} {{host}} {{[-p|--port]}} {{port}} {{[-d|--dbname]}} {{db_name}} {{archive_file.dump}}`
|
2016-01-07 14:45:17 +08:00
|
|
|
|
2020-07-17 20:37:32 +03:00
|
|
|
- List database objects included in the archive:
|
|
|
|
|
2025-04-22 06:20:48 +03:00
|
|
|
`pg_restore {{[-l|--list]}} {{archive_file.dump}}`
|
2020-07-17 20:37:32 +03:00
|
|
|
|
2016-01-07 14:45:17 +08:00
|
|
|
- Clean database objects before creating them:
|
|
|
|
|
2025-04-22 06:20:48 +03:00
|
|
|
`pg_restore {{[-c|--clean]}} {{[-d|--dbname]}} {{db_name}} {{archive_file.dump}}`
|
2016-01-07 14:45:17 +08:00
|
|
|
|
|
|
|
- Use multiple jobs to do the restoring:
|
|
|
|
|
2025-04-22 06:20:48 +03:00
|
|
|
`pg_restore {{[-j|--jobs]}} {{2}} {{[-d|--dbname]}} {{db_name}} {{archive_file.dump}}`
|