pg_restore
databaseLinux/Unix
The pg_restore command is one of the most frequently used commands in Linux/Unix-like operating systems. pg_restore Restore a PostgreSQL database from an archive file created by pg_dump
Quick Reference
Command Name:
pg_restore
Category:
database
Platform:
Linux/Unix
Basic Usage:
pg_restore [options] [arguments]
Common Use Cases
Syntax
pg_restore [connection-option...] [option...] [filename]
Options
Option | Description |
---|---|
-a, --data-only |
Restore only the data, not the schema |
-c, --clean |
Clean (drop) database objects before recreating |
-C, --create |
Create the database before restoring into it |
-d, --dbname=NAME |
Connect to database NAME |
-e, --exit-on-error |
Exit if an error is encountered |
-f, --file=FILENAME |
Output file name (for scripts) or directory (for directory format) |
-F, --format=c|d|t |
Backup file format (should be automatic) |
-I, --index=NAME |
Restore named index |
-j, --jobs=NUM |
Use this many parallel jobs to restore |
-l, --list |
List the contents of the archive |
-L, --use-list=FILENAME |
Restore only objects in list file |
-n, --schema=SCHEMA |
Restore only objects in the named schema |
-N, --exclude-schema=SCHEMA |
Do not restore objects in the named schema |
-O, --no-owner |
Skip restoration of object ownership |
-P, --function=NAME(args) |
Restore named function |
-s, --schema-only |
Restore only the schema, no data |
-S, --superuser=NAME |
Superuser user name to use for disabling triggers |
-t, --table=TABLE |
Restore named relation (table, view, etc.) |
-T, --trigger=NAME |
Restore named trigger |
-v, --verbose |
Verbose mode |
-x, --no-privileges |
Skip restoration of access privileges (grant/revoke) |
--disable-triggers |
Disable triggers during data-only restore |
--no-data-for-failed-tables |
Do not restore data of tables that could not be created |
--no-security-labels |
Do not restore security labels |
--no-tablespaces |
Do not restore tablespace assignments |
--section=SECTION |
Restore named section (pre-data, data, or post-data) |
--use-set-session-authorization |
Use SET SESSION AUTHORIZATION commands instead of ALTER OWNER commands |
Connection Options:
Option | Description |
---|---|
-h, --host=HOSTNAME |
Database server host or socket directory |
-p, --port=PORT |
Database server port number |
-U, --username=NAME |
Connect as specified database user |
-w, --no-password |
Never prompt for password |
-W, --password |
Force password prompt |
--role=ROLENAME |
Do SET ROLE before restore |
Examples
How to Use These Examples
The examples below show common ways to use the pg_restore
command. Try them in your terminal to see the results. You can copy any example by clicking on the code block.
# Basic Examples Basic
pg_restore -d mydb mydb.dump