{
    "mode": "man",
    "parameter": "pg_restore",
    "section": "1",
    "url": "https://www.chedong.com/phpMan.php/man/pg_restore/1/json",
    "generated": "2026-06-15T14:38:52Z",
    "synopsis": "pgrestore [connection-option...] [option...] [filename]",
    "sections": {
        "NAME": {
            "content": "pgrestore - restore a PostgreSQL database from an archive file created by pgdump\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "pgrestore [connection-option...] [option...] [filename]\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "pgrestore is a utility for restoring a PostgreSQL database from an archive created by\npgdump(1) in one of the non-plain-text formats. It will issue the commands necessary to\nreconstruct the database to the state it was in at the time it was saved. The archive files\nalso allow pgrestore to be selective about what is restored, or even to reorder the items\nprior to being restored. The archive files are designed to be portable across architectures.\n\npgrestore can operate in two modes. If a database name is specified, pgrestore connects to\nthat database and restores archive contents directly into the database. Otherwise, a script\ncontaining the SQL commands necessary to rebuild the database is created and written to a\nfile or standard output. This script output is equivalent to the plain text output format of\npgdump. Some of the options controlling the output are therefore analogous to pgdump\noptions.\n\nObviously, pgrestore cannot restore information that is not present in the archive file. For\ninstance, if the archive was made using the “dump data as INSERT commands” option, pgrestore\nwill not be able to load the data using COPY statements.\n\nWarning\nRestoring a dump causes the destination to execute arbitrary code of the source\nsuperusers' choice. Partial dumps and partial restores do not limit that. If the source\nsuperusers are not trusted, the dumped SQL statements must be inspected before restoring.\nNon-plain-text dumps can be inspected by using pgrestore's --file option. Note that the\nclient running the dump and restore need not trust the source or destination superusers.\n",
            "subsections": []
        },
        "OPTIONS": {
            "content": "pgrestore accepts the following command line arguments.\n\nfilename\nSpecifies the location of the archive file (or directory, for a directory-format archive)\nto be restored. If not specified, the standard input is used.\n",
            "subsections": [
                {
                    "name": "-a",
                    "content": "",
                    "flag": "-a"
                },
                {
                    "name": "--data-only",
                    "content": "Restore only the data, not the schema (data definitions). Table data, large objects, and\nsequence values are restored, if present in the archive.\n\nThis option is similar to, but for historical reasons not identical to, specifying\n--section=data.\n",
                    "long": "--data-only"
                },
                {
                    "name": "-c",
                    "content": "",
                    "flag": "-c"
                },
                {
                    "name": "--clean",
                    "content": "Before restoring database objects, issue commands to DROP all the objects that will be\nrestored. This option is useful for overwriting an existing database. If any of the\nobjects do not exist in the destination database, ignorable error messages will be\nreported, unless --if-exists is also specified.\n",
                    "long": "--clean"
                },
                {
                    "name": "-C",
                    "content": "",
                    "flag": "-C"
                },
                {
                    "name": "--create",
                    "content": "Create the database before restoring into it. If --clean is also specified, drop and\nrecreate the target database before connecting to it.\n\nWith --create, pgrestore also restores the database's comment if any, and any\nconfiguration variable settings that are specific to this database, that is, any ALTER\nDATABASE ... SET ...  and ALTER ROLE ... IN DATABASE ... SET ...  commands that mention\nthis database. Access privileges for the database itself are also restored, unless\n--no-acl is specified.\n\nWhen this option is used, the database named with -d is used only to issue the initial\nDROP DATABASE and CREATE DATABASE commands. All data is restored into the database name\nthat appears in the archive.\n",
                    "long": "--create"
                },
                {
                    "name": "-d",
                    "content": "--dbname=dbname\nConnect to database dbname and restore directly into the database. The dbname can be a\nconnection string. If so, connection string parameters will override any conflicting\ncommand line options.\n",
                    "flag": "-d"
                },
                {
                    "name": "-e",
                    "content": "",
                    "flag": "-e"
                },
                {
                    "name": "--exit-on-error",
                    "content": "Exit if an error is encountered while sending SQL commands to the database. The default\nis to continue and to display a count of errors at the end of the restoration.\n",
                    "long": "--exit-on-error"
                },
                {
                    "name": "-f",
                    "content": "--file=filename\nSpecify output file for generated script, or for the listing when used with -l. Use - for\nstdout.\n",
                    "flag": "-f"
                },
                {
                    "name": "-F",
                    "content": "--format=format\nSpecify format of the archive. It is not necessary to specify the format, since\npgrestore will determine the format automatically. If specified, it can be one of the\nfollowing:\n\nc\ncustom\nThe archive is in the custom format of pgdump.\n\nd\ndirectory\nThe archive is a directory archive.\n\nt\ntar\nThe archive is a tar archive.\n",
                    "flag": "-F"
                },
                {
                    "name": "-I",
                    "content": "--index=index\nRestore definition of named index only. Multiple indexes may be specified with multiple\n-I switches.\n",
                    "flag": "-I"
                },
                {
                    "name": "-j",
                    "content": "--jobs=number-of-jobs\nRun the most time-consuming steps of pgrestore — those that load data, create indexes,\nor create constraints — concurrently, using up to number-of-jobs concurrent sessions.\nThis option can dramatically reduce the time to restore a large database to a server\nrunning on a multiprocessor machine. This option is ignored when emitting a script rather\nthan connecting directly to a database server.\n\nEach job is one process or one thread, depending on the operating system, and uses a\nseparate connection to the server.\n\nThe optimal value for this option depends on the hardware setup of the server, of the\nclient, and of the network. Factors include the number of CPU cores and the disk setup. A\ngood place to start is the number of CPU cores on the server, but values larger than that\ncan also lead to faster restore times in many cases. Of course, values that are too high\nwill lead to decreased performance because of thrashing.\n\nOnly the custom and directory archive formats are supported with this option. The input\nmust be a regular file or directory (not, for example, a pipe or standard input). Also,\nmultiple jobs cannot be used together with the option --single-transaction.\n",
                    "flag": "-j"
                },
                {
                    "name": "-l",
                    "content": "",
                    "flag": "-l"
                },
                {
                    "name": "--list",
                    "content": "List the table of contents of the archive. The output of this operation can be used as\ninput to the -L option. Note that if filtering switches such as -n or -t are used with\n-l, they will restrict the items listed.\n",
                    "long": "--list"
                },
                {
                    "name": "-L",
                    "content": "--use-list=list-file\nRestore only those archive elements that are listed in list-file, and restore them in the\norder they appear in the file. Note that if filtering switches such as -n or -t are used\nwith -L, they will further restrict the items restored.\n\nlist-file is normally created by editing the output of a previous -l operation. Lines can\nbe moved or removed, and can also be commented out by placing a semicolon (;) at the\nstart of the line. See below for examples.\n",
                    "flag": "-L"
                },
                {
                    "name": "-n",
                    "content": "--schema=schema\nRestore only objects that are in the named schema. Multiple schemas may be specified with\nmultiple -n switches. This can be combined with the -t option to restore just a specific\ntable.\n",
                    "flag": "-n"
                },
                {
                    "name": "-N",
                    "content": "--exclude-schema=schema\nDo not restore objects that are in the named schema. Multiple schemas to be excluded may\nbe specified with multiple -N switches.\n\nWhen both -n and -N are given for the same schema name, the -N switch wins and the schema\nis excluded.\n",
                    "flag": "-N"
                },
                {
                    "name": "-O",
                    "content": "",
                    "flag": "-O"
                },
                {
                    "name": "--no-owner",
                    "content": "Do not output commands to set ownership of objects to match the original database. By\ndefault, pgrestore issues ALTER OWNER or SET SESSION AUTHORIZATION statements to set\nownership of created schema elements. These statements will fail unless the initial\nconnection to the database is made by a superuser (or the same user that owns all of the\nobjects in the script). With -O, any user name can be used for the initial connection,\nand this user will own all the created objects.\n",
                    "long": "--no-owner"
                },
                {
                    "name": "-P",
                    "content": "--function=function-name(argtype [, ...])\nRestore the named function only. Be careful to spell the function name and arguments\nexactly as they appear in the dump file's table of contents. Multiple functions may be\nspecified with multiple -P switches.\n",
                    "flag": "-P"
                },
                {
                    "name": "-R",
                    "content": "",
                    "flag": "-R"
                },
                {
                    "name": "--no-reconnect",
                    "content": "This option is obsolete but still accepted for backwards compatibility.\n",
                    "long": "--no-reconnect"
                },
                {
                    "name": "-s",
                    "content": "",
                    "flag": "-s"
                },
                {
                    "name": "--schema-only",
                    "content": "Restore only the schema (data definitions), not data, to the extent that schema entries\nare present in the archive.\n\nThis option is the inverse of --data-only. It is similar to, but for historical reasons\nnot identical to, specifying --section=pre-data --section=post-data.\n\n(Do not confuse this with the --schema option, which uses the word “schema” in a\ndifferent meaning.)\n",
                    "long": "--schema-only"
                },
                {
                    "name": "-S",
                    "content": "--superuser=username\nSpecify the superuser user name to use when disabling triggers. This is relevant only if\n--disable-triggers is used.\n",
                    "flag": "-S"
                },
                {
                    "name": "-t",
                    "content": "--table=table\nRestore definition and/or data of only the named table. For this purpose, “table”\nincludes views, materialized views, sequences, and foreign tables. Multiple tables can be\nselected by writing multiple -t switches. This option can be combined with the -n option\nto specify table(s) in a particular schema.\n\nNote\nWhen -t is specified, pgrestore makes no attempt to restore any other database\nobjects that the selected table(s) might depend upon. Therefore, there is no\nguarantee that a specific-table restore into a clean database will succeed.\n\nNote\nThis flag does not behave identically to the -t flag of pgdump. There is not\ncurrently any provision for wild-card matching in pgrestore, nor can you include a\nschema name within its -t. And, while pgdump's -t flag will also dump subsidiary\nobjects (such as indexes) of the selected table(s), pgrestore's -t flag does not\ninclude such subsidiary objects.\n\nNote\nIn versions prior to PostgreSQL 9.6, this flag matched only tables, not any other\ntype of relation.\n",
                    "flag": "-t"
                },
                {
                    "name": "-T",
                    "content": "--trigger=trigger\nRestore named trigger only. Multiple triggers may be specified with multiple -T switches.\n",
                    "flag": "-T"
                },
                {
                    "name": "-v",
                    "content": "",
                    "flag": "-v"
                },
                {
                    "name": "--verbose",
                    "content": "Specifies verbose mode. This will cause pgrestore to output detailed object comments and\nstart/stop times to the output file, and progress messages to standard error. Repeating\nthe option causes additional debug-level messages to appear on standard error.\n",
                    "long": "--verbose"
                },
                {
                    "name": "-V",
                    "content": "",
                    "flag": "-V"
                },
                {
                    "name": "--version",
                    "content": "Print the pgrestore version and exit.\n",
                    "long": "--version"
                },
                {
                    "name": "-x",
                    "content": "",
                    "flag": "-x"
                },
                {
                    "name": "--no-privileges",
                    "content": "",
                    "long": "--no-privileges"
                },
                {
                    "name": "--no-acl",
                    "content": "Prevent restoration of access privileges (grant/revoke commands).\n",
                    "long": "--no-acl"
                },
                {
                    "name": "-1",
                    "content": "",
                    "flag": "-1"
                },
                {
                    "name": "--single-transaction",
                    "content": "Execute the restore as a single transaction (that is, wrap the emitted commands in\nBEGIN/COMMIT). This ensures that either all the commands complete successfully, or no\nchanges are applied. This option implies --exit-on-error.\n",
                    "long": "--single-transaction"
                },
                {
                    "name": "--disable-triggers",
                    "content": "This option is relevant only when performing a data-only restore. It instructs pgrestore\nto execute commands to temporarily disable triggers on the target tables while the data\nis restored. Use this if you have referential integrity checks or other triggers on the\ntables that you do not want to invoke during data restore.\n\nPresently, the commands emitted for --disable-triggers must be done as superuser. So you\nshould also specify a superuser name with -S or, preferably, run pgrestore as a\nPostgreSQL superuser.\n",
                    "long": "--disable-triggers"
                },
                {
                    "name": "--enable-row-security",
                    "content": "This option is relevant only when restoring the contents of a table which has row\nsecurity. By default, pgrestore will set rowsecurity to off, to ensure that all data is\nrestored in to the table. If the user does not have sufficient privileges to bypass row\nsecurity, then an error is thrown. This parameter instructs pgrestore to set\nrowsecurity to on instead, allowing the user to attempt to restore the contents of the\ntable with row security enabled. This might still fail if the user does not have the\nright to insert the rows from the dump into the table.\n\nNote that this option currently also requires the dump be in INSERT format, as COPY FROM\ndoes not support row security.\n",
                    "long": "--enable-row-security"
                },
                {
                    "name": "--if-exists",
                    "content": "Use DROP ... IF EXISTS commands to drop objects in --clean mode. This suppresses “does\nnot exist” errors that might otherwise be reported. This option is not valid unless\n--clean is also specified.\n",
                    "long": "--if-exists"
                },
                {
                    "name": "--no-comments",
                    "content": "Do not output commands to restore comments, even if the archive contains them.\n",
                    "long": "--no-comments"
                },
                {
                    "name": "--no-data-for-failed-tables",
                    "content": "By default, table data is restored even if the creation command for the table failed\n(e.g., because it already exists). With this option, data for such a table is skipped.\nThis behavior is useful if the target database already contains the desired table\ncontents. For example, auxiliary tables for PostgreSQL extensions such as PostGIS might\nalready be loaded in the target database; specifying this option prevents duplicate or\nobsolete data from being loaded into them.\n\nThis option is effective only when restoring directly into a database, not when producing\nSQL script output.\n",
                    "long": "--no-data-for-failed-tables"
                },
                {
                    "name": "--no-publications",
                    "content": "Do not output commands to restore publications, even if the archive contains them.\n",
                    "long": "--no-publications"
                },
                {
                    "name": "--no-security-labels",
                    "content": "Do not output commands to restore security labels, even if the archive contains them.\n",
                    "long": "--no-security-labels"
                },
                {
                    "name": "--no-subscriptions",
                    "content": "Do not output commands to restore subscriptions, even if the archive contains them.\n",
                    "long": "--no-subscriptions"
                },
                {
                    "name": "--no-tablespaces",
                    "content": "Do not output commands to select tablespaces. With this option, all objects will be\ncreated in whichever tablespace is the default during restore.\n\n--restrict-key=restrictkey\nUse the provided string as the psql \\restrict key in the dump output. This can only be\nspecified for SQL script output, i.e., when the --file option is used. If no restrict key\nis specified, pgrestore will generate a random one as needed. Keys may contain only\nalphanumeric characters.\n\nThis option is primarily intended for testing purposes and other scenarios that require\nrepeatable output (e.g., comparing dump files). It is not recommended for general use, as\na malicious server with advance knowledge of the key may be able to inject arbitrary code\nthat will be executed on the machine that runs psql with the dump output.\n\n--section=sectionname\nOnly restore the named section. The section name can be pre-data, data, or post-data.\nThis option can be specified more than once to select multiple sections. The default is\nto restore all sections.\n\nThe data section contains actual table data as well as large-object definitions.\nPost-data items consist of definitions of indexes, triggers, rules and constraints other\nthan validated check constraints. Pre-data items consist of all other data definition\nitems.\n",
                    "long": "--no-tablespaces"
                },
                {
                    "name": "--strict-names",
                    "content": "Require that each schema (-n/--schema) and table (-t/--table) qualifier match at least\none schema/table in the backup file.\n",
                    "long": "--strict-names"
                },
                {
                    "name": "--use-set-session-authorization",
                    "content": "Output SQL-standard SET SESSION AUTHORIZATION commands instead of ALTER OWNER commands to\ndetermine object ownership. This makes the dump more standards-compatible, but depending\non the history of the objects in the dump, might not restore properly.\n\n-?",
                    "long": "--use-set-session-authorization"
                },
                {
                    "name": "--help",
                    "content": "Show help about pgrestore command line arguments, and exit.\n\npgrestore also accepts the following command line arguments for connection parameters:\n",
                    "long": "--help"
                },
                {
                    "name": "-h",
                    "content": "--host=host\nSpecifies the host name of the machine on which the server is running. If the value\nbegins with a slash, it is used as the directory for the Unix domain socket. The default\nis taken from the PGHOST environment variable, if set, else a Unix domain socket\nconnection is attempted.\n",
                    "flag": "-h"
                },
                {
                    "name": "-p",
                    "content": "--port=port\nSpecifies the TCP port or local Unix domain socket file extension on which the server is\nlistening for connections. Defaults to the PGPORT environment variable, if set, or a\ncompiled-in default.\n",
                    "flag": "-p"
                },
                {
                    "name": "-U",
                    "content": "--username=username\nUser name to connect as.\n",
                    "flag": "-U"
                },
                {
                    "name": "-w",
                    "content": "",
                    "flag": "-w"
                },
                {
                    "name": "--no-password",
                    "content": "Never issue a password prompt. If the server requires password authentication and a\npassword is not available by other means such as a .pgpass file, the connection attempt\nwill fail. This option can be useful in batch jobs and scripts where no user is present\nto enter a password.\n",
                    "long": "--no-password"
                },
                {
                    "name": "-W",
                    "content": "",
                    "flag": "-W"
                },
                {
                    "name": "--password",
                    "content": "Force pgrestore to prompt for a password before connecting to a database.\n\nThis option is never essential, since pgrestore will automatically prompt for a password\nif the server demands password authentication. However, pgrestore will waste a\nconnection attempt finding out that the server wants a password. In some cases it is\nworth typing -W to avoid the extra connection attempt.\n\n--role=rolename\nSpecifies a role name to be used to perform the restore. This option causes pgrestore to\nissue a SET ROLE rolename command after connecting to the database. It is useful when the\nauthenticated user (specified by -U) lacks privileges needed by pgrestore, but can\nswitch to a role with the required rights. Some installations have a policy against\nlogging in directly as a superuser, and use of this option allows restores to be\nperformed without violating the policy.\n",
                    "long": "--password"
                }
            ]
        },
        "ENVIRONMENT": {
            "content": "PGHOST\nPGOPTIONS\nPGPORT\nPGUSER\nDefault connection parameters\n\nPGCOLOR\nSpecifies whether to use color in diagnostic messages. Possible values are always, auto\nand never.\n\nThis utility, like most other PostgreSQL utilities, also uses the environment variables\nsupported by libpq (see Section 34.15). However, it does not read PGDATABASE when a database\nname is not supplied.\n",
            "subsections": []
        },
        "DIAGNOSTICS": {
            "content": "When a direct database connection is specified using the -d option, pgrestore internally\nexecutes SQL statements. If you have problems running pgrestore, make sure you are able to\nselect information from the database using, for example, psql(1). Also, any default\nconnection settings and environment variables used by the libpq front-end library will apply.\n",
            "subsections": []
        },
        "NOTES": {
            "content": "If your installation has any local additions to the template1 database, be careful to load\nthe output of pgrestore into a truly empty database; otherwise you are likely to get errors\ndue to duplicate definitions of the added objects. To make an empty database without any\nlocal additions, copy from template0 not template1, for example:\n\nCREATE DATABASE foo WITH TEMPLATE template0;\n\nThe limitations of pgrestore are detailed below.\n\n•   When restoring data to a pre-existing table and the option --disable-triggers is used,\npgrestore emits commands to disable triggers on user tables before inserting the data,\nthen emits commands to re-enable them after the data has been inserted. If the restore is\nstopped in the middle, the system catalogs might be left in the wrong state.\n\n•   pgrestore cannot restore large objects selectively; for instance, only those for a\nspecific table. If an archive contains large objects, then all large objects will be\nrestored, or none of them if they are excluded via -L, -t, or other options.\n\nSee also the pgdump(1) documentation for details on limitations of pgdump.\n\nOnce restored, it is wise to run ANALYZE on each restored table so the optimizer has useful\nstatistics; see Section 25.1.3 and Section 25.1.6 for more information.\n",
            "subsections": []
        },
        "EXAMPLES": {
            "content": "Assume we have dumped a database called mydb into a custom-format dump file:\n\n$ pgdump -Fc mydb > db.dump\n\nTo drop the database and recreate it from the dump:\n\n$ dropdb mydb\n$ pgrestore -C -d postgres db.dump\n\nThe database named in the -d switch can be any database existing in the cluster; pgrestore\nonly uses it to issue the CREATE DATABASE command for mydb. With -C, data is always restored\ninto the database name that appears in the dump file.\n\nTo restore the dump into a new database called newdb:\n\n$ createdb -T template0 newdb\n$ pgrestore -d newdb db.dump\n\nNotice we don't use -C, and instead connect directly to the database to be restored into.\nAlso note that we clone the new database from template0 not template1, to ensure it is\ninitially empty.\n\nTo reorder database items, it is first necessary to dump the table of contents of the\narchive:\n\n$ pgrestore -l db.dump > db.list\n\nThe listing file consists of a header and one line for each item, e.g.:\n\n;\n; Archive created at Mon Sep 14 13:55:39 2009\n;     dbname: DBDEMOS\n;     TOC Entries: 81\n;     Compression: 9\n;     Dump Version: 1.10-0\n;     Format: CUSTOM\n;     Integer: 4 bytes\n;     Offset: 8 bytes\n;     Dumped from database version: 8.3.5\n;     Dumped by pgdump version: 8.3.8\n;\n;\n; Selected TOC Entries:\n;\n3; 2615 2200 SCHEMA - public pasha\n1861; 0 0 COMMENT - SCHEMA public pasha\n1862; 0 0 ACL - public pasha\n317; 1247 17715 TYPE public composite pasha\n319; 1247 25899 DOMAIN public domain0 pasha\n\nSemicolons start a comment, and the numbers at the start of lines refer to the internal\narchive ID assigned to each item.\n\nLines in the file can be commented out, deleted, and reordered. For example:\n\n10; 145433 TABLE mapresolutions postgres\n;2; 145344 TABLE species postgres\n;4; 145359 TABLE ntheader postgres\n6; 145402 TABLE speciesrecords postgres\n;8; 145416 TABLE ssold postgres\n\ncould be used as input to pgrestore and would only restore items 10 and 6, in that order:\n\n$ pgrestore -L db.list db.dump\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "pgdump(1), pgdumpall(1), psql(1)\n\n\n\nPostgreSQL 14.23                                2026                                   PGRESTORE(1)",
            "subsections": []
        }
    },
    "summary": "pgrestore - restore a PostgreSQL database from an archive file created by pgdump",
    "flags": [
        {
            "flag": "-a",
            "long": null,
            "arg": null,
            "description": ""
        },
        {
            "flag": "",
            "long": "--data-only",
            "arg": null,
            "description": "Restore only the data, not the schema (data definitions). Table data, large objects, and sequence values are restored, if present in the archive. This option is similar to, but for historical reasons not identical to, specifying --section=data."
        },
        {
            "flag": "-c",
            "long": null,
            "arg": null,
            "description": ""
        },
        {
            "flag": "",
            "long": "--clean",
            "arg": null,
            "description": "Before restoring database objects, issue commands to DROP all the objects that will be restored. This option is useful for overwriting an existing database. If any of the objects do not exist in the destination database, ignorable error messages will be reported, unless --if-exists is also specified."
        },
        {
            "flag": "-C",
            "long": null,
            "arg": null,
            "description": ""
        },
        {
            "flag": "",
            "long": "--create",
            "arg": null,
            "description": "Create the database before restoring into it. If --clean is also specified, drop and recreate the target database before connecting to it. With --create, pgrestore also restores the database's comment if any, and any configuration variable settings that are specific to this database, that is, any ALTER DATABASE ... SET ... and ALTER ROLE ... IN DATABASE ... SET ... commands that mention this database. Access privileges for the database itself are also restored, unless --no-acl is specified. When this option is used, the database named with -d is used only to issue the initial DROP DATABASE and CREATE DATABASE commands. All data is restored into the database name that appears in the archive."
        },
        {
            "flag": "-d",
            "long": null,
            "arg": null,
            "description": "--dbname=dbname Connect to database dbname and restore directly into the database. The dbname can be a connection string. If so, connection string parameters will override any conflicting command line options."
        },
        {
            "flag": "-e",
            "long": null,
            "arg": null,
            "description": ""
        },
        {
            "flag": "",
            "long": "--exit-on-error",
            "arg": null,
            "description": "Exit if an error is encountered while sending SQL commands to the database. The default is to continue and to display a count of errors at the end of the restoration."
        },
        {
            "flag": "-f",
            "long": null,
            "arg": null,
            "description": "--file=filename Specify output file for generated script, or for the listing when used with -l. Use - for stdout."
        },
        {
            "flag": "-F",
            "long": null,
            "arg": null,
            "description": "--format=format Specify format of the archive. It is not necessary to specify the format, since pgrestore will determine the format automatically. If specified, it can be one of the following: c custom The archive is in the custom format of pgdump. d directory The archive is a directory archive. t tar The archive is a tar archive."
        },
        {
            "flag": "-I",
            "long": null,
            "arg": null,
            "description": "--index=index Restore definition of named index only. Multiple indexes may be specified with multiple -I switches."
        },
        {
            "flag": "-j",
            "long": null,
            "arg": null,
            "description": "--jobs=number-of-jobs Run the most time-consuming steps of pgrestore — those that load data, create indexes, or create constraints — concurrently, using up to number-of-jobs concurrent sessions. This option can dramatically reduce the time to restore a large database to a server running on a multiprocessor machine. This option is ignored when emitting a script rather than connecting directly to a database server. Each job is one process or one thread, depending on the operating system, and uses a separate connection to the server. The optimal value for this option depends on the hardware setup of the server, of the client, and of the network. Factors include the number of CPU cores and the disk setup. A good place to start is the number of CPU cores on the server, but values larger than that can also lead to faster restore times in many cases. Of course, values that are too high will lead to decreased performance because of thrashing. Only the custom and directory archive formats are supported with this option. The input must be a regular file or directory (not, for example, a pipe or standard input). Also, multiple jobs cannot be used together with the option --single-transaction."
        },
        {
            "flag": "-l",
            "long": null,
            "arg": null,
            "description": ""
        },
        {
            "flag": "",
            "long": "--list",
            "arg": null,
            "description": "List the table of contents of the archive. The output of this operation can be used as input to the -L option. Note that if filtering switches such as -n or -t are used with -l, they will restrict the items listed."
        },
        {
            "flag": "-L",
            "long": null,
            "arg": null,
            "description": "--use-list=list-file Restore only those archive elements that are listed in list-file, and restore them in the order they appear in the file. Note that if filtering switches such as -n or -t are used with -L, they will further restrict the items restored. list-file is normally created by editing the output of a previous -l operation. Lines can be moved or removed, and can also be commented out by placing a semicolon (;) at the start of the line. See below for examples."
        },
        {
            "flag": "-n",
            "long": null,
            "arg": null,
            "description": "--schema=schema Restore only objects that are in the named schema. Multiple schemas may be specified with multiple -n switches. This can be combined with the -t option to restore just a specific table."
        },
        {
            "flag": "-N",
            "long": null,
            "arg": null,
            "description": "--exclude-schema=schema Do not restore objects that are in the named schema. Multiple schemas to be excluded may be specified with multiple -N switches. When both -n and -N are given for the same schema name, the -N switch wins and the schema is excluded."
        },
        {
            "flag": "-O",
            "long": null,
            "arg": null,
            "description": ""
        },
        {
            "flag": "",
            "long": "--no-owner",
            "arg": null,
            "description": "Do not output commands to set ownership of objects to match the original database. By default, pgrestore issues ALTER OWNER or SET SESSION AUTHORIZATION statements to set ownership of created schema elements. These statements will fail unless the initial connection to the database is made by a superuser (or the same user that owns all of the objects in the script). With -O, any user name can be used for the initial connection, and this user will own all the created objects."
        },
        {
            "flag": "-P",
            "long": null,
            "arg": null,
            "description": "--function=function-name(argtype [, ...]) Restore the named function only. Be careful to spell the function name and arguments exactly as they appear in the dump file's table of contents. Multiple functions may be specified with multiple -P switches."
        },
        {
            "flag": "-R",
            "long": null,
            "arg": null,
            "description": ""
        },
        {
            "flag": "",
            "long": "--no-reconnect",
            "arg": null,
            "description": "This option is obsolete but still accepted for backwards compatibility."
        },
        {
            "flag": "-s",
            "long": null,
            "arg": null,
            "description": ""
        },
        {
            "flag": "",
            "long": "--schema-only",
            "arg": null,
            "description": "Restore only the schema (data definitions), not data, to the extent that schema entries are present in the archive. This option is the inverse of --data-only. It is similar to, but for historical reasons not identical to, specifying --section=pre-data --section=post-data. (Do not confuse this with the --schema option, which uses the word “schema” in a different meaning.)"
        },
        {
            "flag": "-S",
            "long": null,
            "arg": null,
            "description": "--superuser=username Specify the superuser user name to use when disabling triggers. This is relevant only if --disable-triggers is used."
        },
        {
            "flag": "-t",
            "long": null,
            "arg": null,
            "description": "--table=table Restore definition and/or data of only the named table. For this purpose, “table” includes views, materialized views, sequences, and foreign tables. Multiple tables can be selected by writing multiple -t switches. This option can be combined with the -n option to specify table(s) in a particular schema. Note When -t is specified, pgrestore makes no attempt to restore any other database objects that the selected table(s) might depend upon. Therefore, there is no guarantee that a specific-table restore into a clean database will succeed. Note This flag does not behave identically to the -t flag of pgdump. There is not currently any provision for wild-card matching in pgrestore, nor can you include a schema name within its -t. And, while pgdump's -t flag will also dump subsidiary objects (such as indexes) of the selected table(s), pgrestore's -t flag does not include such subsidiary objects. Note In versions prior to PostgreSQL 9.6, this flag matched only tables, not any other type of relation."
        },
        {
            "flag": "-T",
            "long": null,
            "arg": null,
            "description": "--trigger=trigger Restore named trigger only. Multiple triggers may be specified with multiple -T switches."
        },
        {
            "flag": "-v",
            "long": null,
            "arg": null,
            "description": ""
        },
        {
            "flag": "",
            "long": "--verbose",
            "arg": null,
            "description": "Specifies verbose mode. This will cause pgrestore to output detailed object comments and start/stop times to the output file, and progress messages to standard error. Repeating the option causes additional debug-level messages to appear on standard error."
        },
        {
            "flag": "-V",
            "long": null,
            "arg": null,
            "description": ""
        },
        {
            "flag": "",
            "long": "--version",
            "arg": null,
            "description": "Print the pgrestore version and exit."
        },
        {
            "flag": "-x",
            "long": null,
            "arg": null,
            "description": ""
        },
        {
            "flag": "",
            "long": "--no-privileges",
            "arg": null,
            "description": ""
        },
        {
            "flag": "",
            "long": "--no-acl",
            "arg": null,
            "description": "Prevent restoration of access privileges (grant/revoke commands)."
        },
        {
            "flag": "-1",
            "long": null,
            "arg": null,
            "description": ""
        },
        {
            "flag": "",
            "long": "--single-transaction",
            "arg": null,
            "description": "Execute the restore as a single transaction (that is, wrap the emitted commands in BEGIN/COMMIT). This ensures that either all the commands complete successfully, or no changes are applied. This option implies --exit-on-error."
        },
        {
            "flag": "",
            "long": "--disable-triggers",
            "arg": null,
            "description": "This option is relevant only when performing a data-only restore. It instructs pgrestore to execute commands to temporarily disable triggers on the target tables while the data is restored. Use this if you have referential integrity checks or other triggers on the tables that you do not want to invoke during data restore. Presently, the commands emitted for --disable-triggers must be done as superuser. So you should also specify a superuser name with -S or, preferably, run pgrestore as a PostgreSQL superuser."
        },
        {
            "flag": "",
            "long": "--enable-row-security",
            "arg": null,
            "description": "This option is relevant only when restoring the contents of a table which has row security. By default, pgrestore will set rowsecurity to off, to ensure that all data is restored in to the table. If the user does not have sufficient privileges to bypass row security, then an error is thrown. This parameter instructs pgrestore to set rowsecurity to on instead, allowing the user to attempt to restore the contents of the table with row security enabled. This might still fail if the user does not have the right to insert the rows from the dump into the table. Note that this option currently also requires the dump be in INSERT format, as COPY FROM does not support row security."
        },
        {
            "flag": "",
            "long": "--if-exists",
            "arg": null,
            "description": "Use DROP ... IF EXISTS commands to drop objects in --clean mode. This suppresses “does not exist” errors that might otherwise be reported. This option is not valid unless --clean is also specified."
        },
        {
            "flag": "",
            "long": "--no-comments",
            "arg": null,
            "description": "Do not output commands to restore comments, even if the archive contains them."
        },
        {
            "flag": "",
            "long": "--no-data-for-failed-tables",
            "arg": null,
            "description": "By default, table data is restored even if the creation command for the table failed (e.g., because it already exists). With this option, data for such a table is skipped. This behavior is useful if the target database already contains the desired table contents. For example, auxiliary tables for PostgreSQL extensions such as PostGIS might already be loaded in the target database; specifying this option prevents duplicate or obsolete data from being loaded into them. This option is effective only when restoring directly into a database, not when producing SQL script output."
        },
        {
            "flag": "",
            "long": "--no-publications",
            "arg": null,
            "description": "Do not output commands to restore publications, even if the archive contains them."
        },
        {
            "flag": "",
            "long": "--no-security-labels",
            "arg": null,
            "description": "Do not output commands to restore security labels, even if the archive contains them."
        },
        {
            "flag": "",
            "long": "--no-subscriptions",
            "arg": null,
            "description": "Do not output commands to restore subscriptions, even if the archive contains them."
        },
        {
            "flag": "",
            "long": "--no-tablespaces",
            "arg": null,
            "description": "Do not output commands to select tablespaces. With this option, all objects will be created in whichever tablespace is the default during restore. --restrict-key=restrictkey Use the provided string as the psql \\restrict key in the dump output. This can only be specified for SQL script output, i.e., when the --file option is used. If no restrict key is specified, pgrestore will generate a random one as needed. Keys may contain only alphanumeric characters. This option is primarily intended for testing purposes and other scenarios that require repeatable output (e.g., comparing dump files). It is not recommended for general use, as a malicious server with advance knowledge of the key may be able to inject arbitrary code that will be executed on the machine that runs psql with the dump output. --section=sectionname Only restore the named section. The section name can be pre-data, data, or post-data. This option can be specified more than once to select multiple sections. The default is to restore all sections. The data section contains actual table data as well as large-object definitions. Post-data items consist of definitions of indexes, triggers, rules and constraints other than validated check constraints. Pre-data items consist of all other data definition items."
        },
        {
            "flag": "",
            "long": "--strict-names",
            "arg": null,
            "description": "Require that each schema (-n/--schema) and table (-t/--table) qualifier match at least one schema/table in the backup file."
        },
        {
            "flag": "",
            "long": "--use-set-session-authorization",
            "arg": null,
            "description": "Output SQL-standard SET SESSION AUTHORIZATION commands instead of ALTER OWNER commands to determine object ownership. This makes the dump more standards-compatible, but depending on the history of the objects in the dump, might not restore properly. -?"
        },
        {
            "flag": "",
            "long": "--help",
            "arg": null,
            "description": "Show help about pgrestore command line arguments, and exit. pgrestore also accepts the following command line arguments for connection parameters:"
        },
        {
            "flag": "-h",
            "long": null,
            "arg": null,
            "description": "--host=host Specifies the host name of the machine on which the server is running. If the value begins with a slash, it is used as the directory for the Unix domain socket. The default is taken from the PGHOST environment variable, if set, else a Unix domain socket connection is attempted."
        },
        {
            "flag": "-p",
            "long": null,
            "arg": null,
            "description": "--port=port Specifies the TCP port or local Unix domain socket file extension on which the server is listening for connections. Defaults to the PGPORT environment variable, if set, or a compiled-in default."
        },
        {
            "flag": "-U",
            "long": null,
            "arg": null,
            "description": "--username=username User name to connect as."
        },
        {
            "flag": "-w",
            "long": null,
            "arg": null,
            "description": ""
        },
        {
            "flag": "",
            "long": "--no-password",
            "arg": null,
            "description": "Never issue a password prompt. If the server requires password authentication and a password is not available by other means such as a .pgpass file, the connection attempt will fail. This option can be useful in batch jobs and scripts where no user is present to enter a password."
        },
        {
            "flag": "-W",
            "long": null,
            "arg": null,
            "description": ""
        },
        {
            "flag": "",
            "long": "--password",
            "arg": null,
            "description": "Force pgrestore to prompt for a password before connecting to a database. This option is never essential, since pgrestore will automatically prompt for a password if the server demands password authentication. However, pgrestore will waste a connection attempt finding out that the server wants a password. In some cases it is worth typing -W to avoid the extra connection attempt. --role=rolename Specifies a role name to be used to perform the restore. This option causes pgrestore to issue a SET ROLE rolename command after connecting to the database. It is useful when the authenticated user (specified by -U) lacks privileges needed by pgrestore, but can switch to a role with the required rights. Some installations have a policy against logging in directly as a superuser, and use of this option allows restores to be performed without violating the policy."
        }
    ],
    "examples": [
        "Assume we have dumped a database called mydb into a custom-format dump file:",
        "$ pgdump -Fc mydb > db.dump",
        "To drop the database and recreate it from the dump:",
        "$ dropdb mydb",
        "$ pgrestore -C -d postgres db.dump",
        "The database named in the -d switch can be any database existing in the cluster; pgrestore",
        "only uses it to issue the CREATE DATABASE command for mydb. With -C, data is always restored",
        "into the database name that appears in the dump file.",
        "To restore the dump into a new database called newdb:",
        "$ createdb -T template0 newdb",
        "$ pgrestore -d newdb db.dump",
        "Notice we don't use -C, and instead connect directly to the database to be restored into.",
        "Also note that we clone the new database from template0 not template1, to ensure it is",
        "initially empty.",
        "To reorder database items, it is first necessary to dump the table of contents of the",
        "archive:",
        "$ pgrestore -l db.dump > db.list",
        "The listing file consists of a header and one line for each item, e.g.:",
        "; Archive created at Mon Sep 14 13:55:39 2009",
        ";     dbname: DBDEMOS",
        ";     TOC Entries: 81",
        ";     Compression: 9",
        ";     Dump Version: 1.10-0",
        ";     Format: CUSTOM",
        ";     Integer: 4 bytes",
        ";     Offset: 8 bytes",
        ";     Dumped from database version: 8.3.5",
        ";     Dumped by pgdump version: 8.3.8",
        "; Selected TOC Entries:",
        "3; 2615 2200 SCHEMA - public pasha",
        "1861; 0 0 COMMENT - SCHEMA public pasha",
        "1862; 0 0 ACL - public pasha",
        "317; 1247 17715 TYPE public composite pasha",
        "319; 1247 25899 DOMAIN public domain0 pasha",
        "Semicolons start a comment, and the numbers at the start of lines refer to the internal",
        "archive ID assigned to each item.",
        "Lines in the file can be commented out, deleted, and reordered. For example:",
        "10; 145433 TABLE mapresolutions postgres",
        ";2; 145344 TABLE species postgres",
        ";4; 145359 TABLE ntheader postgres",
        "6; 145402 TABLE speciesrecords postgres",
        ";8; 145416 TABLE ssold postgres",
        "could be used as input to pgrestore and would only restore items 10 and 6, in that order:",
        "$ pgrestore -L db.list db.dump"
    ],
    "see_also": [
        {
            "name": "pgdump",
            "section": "1",
            "url": "https://www.chedong.com/phpMan.php/man/pgdump/1/json"
        },
        {
            "name": "pgdumpall",
            "section": "1",
            "url": "https://www.chedong.com/phpMan.php/man/pgdumpall/1/json"
        },
        {
            "name": "psql",
            "section": "1",
            "url": "https://www.chedong.com/phpMan.php/man/psql/1/json"
        }
    ],
    "tldr": {
        "source": "official",
        "description": "Restore a PostgreSQL database from an archive file created by pg_dump.",
        "examples": [
            {
                "description": "Restore an archive into an existing database",
                "command": "pg_restore {{-d|--dbname}} {{db_name}} {{archive_file.dump}}"
            },
            {
                "description": "Same as above, customize username",
                "command": "pg_restore {{-U|--username}} {{username}} {{-d|--dbname}} {{db_name}} {{archive_file.dump}}"
            },
            {
                "description": "Same as above, customize host and port",
                "command": "pg_restore {{-h|--host}} {{host}} {{-p|--port}} {{port}} {{-d|--dbname}} {{db_name}} {{archive_file.dump}}"
            },
            {
                "description": "List database objects included in the archive",
                "command": "pg_restore {{-l|--list}} {{archive_file.dump}}"
            },
            {
                "description": "Clean database objects before creating them",
                "command": "pg_restore {{-c|--clean}} {{-d|--dbname}} {{db_name}} {{archive_file.dump}}"
            },
            {
                "description": "Use multiple jobs to do the restoring",
                "command": "pg_restore {{-j|--jobs}} {{2}} {{-d|--dbname}} {{db_name}} {{archive_file.dump}}"
            }
        ]
    }
}