HiveBrain v1.2.0
Get Started
← Back to all entries
snippetbashTip

pg_restore — Restore a PostgreSQL database from an archive file created by pg_dump. More information: <https://ww

Submitted by: @import:tldr-pages··
0
Viewed 0 times
commandfrompg_restoredatabasecliarchiverestorepostgresql

Problem

How to use the pg_restore command: Restore a PostgreSQL database from an archive file created by pg_dump. More information: <https://www.postgresql.org/docs/current/app-pgrestore.html>.

Solution

pg_restore — Restore a PostgreSQL database from an archive file created by pg_dump. More information: <https://www.postgresql.org/docs/current/app-pgrestore.html>.

Restore an archive into an existing database:
pg_restore {{[-d|--dbname]}} {{db_name}} {{archive_file.dump}}


Same as above, customize username:
pg_restore {{[-U|--username]}} {{username}} {{[-d|--dbname]}} {{db_name}} {{archive_file.dump}}


Same as above, customize host and port:
pg_restore {{[-h|--host]}} {{host}} {{[-p|--port]}} {{port}} {{[-d|--dbname]}} {{db_name}} {{archive_file.dump}}


List database objects included in the archive:
pg_restore {{[-l|--list]}} {{archive_file.dump}}


Clean database objects before creating them:
pg_restore {{[-c|--clean]}} {{[-d|--dbname]}} {{db_name}} {{archive_file.dump}}


Use multiple jobs to do the restoring:
pg_restore {{[-j|--jobs]}} {{2}} {{[-d|--dbname]}} {{db_name}} {{archive_file.dump}}

Code Snippets

Restore an archive into an existing database

pg_restore {{[-d|--dbname]}} {{db_name}} {{archive_file.dump}}

Same as above, customize username

pg_restore {{[-U|--username]}} {{username}} {{[-d|--dbname]}} {{db_name}} {{archive_file.dump}}

Same as above, customize host and port

pg_restore {{[-h|--host]}} {{host}} {{[-p|--port]}} {{port}} {{[-d|--dbname]}} {{db_name}} {{archive_file.dump}}

List database objects included in the archive

pg_restore {{[-l|--list]}} {{archive_file.dump}}

Clean database objects before creating them

pg_restore {{[-c|--clean]}} {{[-d|--dbname]}} {{db_name}} {{archive_file.dump}}

Context

tldr-pages: common/pg_restore

Revisions (0)

No revisions yet.