3 .\" Author: The PostgreSQL Global Development Group
4 .\" Generator: DocBook XSL Stylesheets vsnapshot <http://docbook.sf.net/>
6 .\" Manual: PostgreSQL 18.0 Documentation
7 .\" Source: PostgreSQL 18.0
10 .TH "PG_DUMP" "1" "2025" "PostgreSQL 18.0" "PostgreSQL 18.0 Documentation"
11 .\" -----------------------------------------------------------------
12 .\" * Define some portability stuff
13 .\" -----------------------------------------------------------------
14 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
15 .\" http://bugs.debian.org/507673
16 .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
17 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
20 .\" -----------------------------------------------------------------
21 .\" * set default formatting
22 .\" -----------------------------------------------------------------
23 .\" disable hyphenation
25 .\" disable justification (adjust text to left margin only)
27 .\" -----------------------------------------------------------------
28 .\" * MAIN CONTENT STARTS HERE *
29 .\" -----------------------------------------------------------------
31 pg_dump \- export a PostgreSQL database as an SQL script or to other formats
33 .HP \w'\fBpg_dump\fR\ 'u
34 \fBpg_dump\fR [\fIconnection\-option\fR...] [\fIoption\fR...] [\fIdbname\fR]
38 is a utility for exporting a
40 database\&. It makes consistent exports even if the database is being used concurrently\&.
42 does not block other users accessing the database (readers or writers)\&. Note, however, that except in simple cases,
44 is generally not the right choice for taking regular backups of production databases\&. See
46 for further discussion\&.
49 only dumps a single database\&. To export an entire cluster, or to export global objects that are common to all databases in a cluster (such as roles and tablespaces), use
50 \fBpg_dumpall\fR(1)\&.
52 Dumps can be output in script or archive file formats\&. Script dumps are plain\-text files containing the SQL commands required to reconstruct the database to the state it was in at the time it was saved\&. To restore from such a script, feed it to
53 \fBpsql\fR(1)\&. Script files can be used to reconstruct the database even on other machines and other architectures; with some modifications, even on other SQL database products\&.
55 The alternative archive file formats must be used with
57 to rebuild the database\&. They allow
59 to be selective about what is restored, or even to reorder the items prior to being restored\&. The archive file formats are designed to be portable across architectures\&.
61 When used with one of the archive file formats and combined with
64 provides a flexible archival and transfer mechanism\&.
66 can be used to export an entire database, then
68 can be used to examine the archive and/or select which parts of the database are to be restored\&. The most flexible output file formats are the
70 format (\fB\-Fc\fR) and the
72 format (\fB\-Fd\fR)\&. They allow for selection and reordering of all archived items, support parallel restoration, and are compressed by default\&. The
74 format is the only format that supports parallel dumps\&.
77 pg_dump, one should examine the output for any warnings (printed on standard error), especially in light of the limitations listed below\&.
83 .nr an-no-space-flag 1
91 Restoring a dump causes the destination to execute arbitrary code of the source superusers\*(Aq choice\&. Partial dumps and partial restores do not limit that\&. If the source superusers are not trusted, the dumped SQL statements must be inspected before restoring\&. Non\-plain\-text dumps can be inspected by using
94 option\&. Note that the client running the dump and restore need not trust the source or destination superusers\&.
99 The following command\-line options control the content and format of the output\&.
103 Specifies the name of the database to be dumped\&. If this is not specified, the environment variable
105 is used\&. If that is not set, the user name specified for the connection is used\&.
112 Dump only the data, not the schema (data definitions) or statistics\&. Table data, large objects, and sequence values are dumped\&.
114 This option is similar to, but for historical reasons not identical to, specifying
115 \fB\-\-section=data\fR\&.
120 \fB\-\-large\-objects\fR
122 \fB\-\-blobs\fR (deprecated)
124 Include large objects in the dump\&. This is the default behavior except when
127 \fB\-\-schema\-only\fR,
128 \fB\-\-statistics\-only\fR, or
132 switch is therefore only useful to add large objects to dumps where a specific schema or table has been requested\&. Note that large objects are considered data and therefore will be included when
134 is used, but not when
135 \fB\-\-schema\-only\fR
137 \fB\-\-statistics\-only\fR
143 \fB\-\-no\-large\-objects\fR
145 \fB\-\-no\-blobs\fR (deprecated)
147 Exclude large objects in the dump\&.
153 are given, the behavior is to output large objects, when data is being dumped, see the
164 all the dumped database objects prior to outputting the commands for creating them\&. This option is useful when the restore is to overwrite an existing database\&. If any of the objects do not exist in the destination database, ignorable error messages will be reported during restore, unless
168 This option is ignored when emitting an archive (non\-text) output file\&. For the archive formats, you can specify the option when you call
176 Begin the output with a command to create the database itself and reconnect to the created database\&. (With a script of this form, it doesn\*(Aqt matter which database in the destination installation you connect to before running the script\&.) If
178 is also specified, the script drops and recreates the target database before reconnecting to it\&.
181 \fB\-\-create\fR, the output also includes the database\*(Aqs comment if any, and any configuration variable settings that are specific to this database, that is, any
182 \fBALTER DATABASE \&.\&.\&. SET \&.\&.\&.\fR
184 \fBALTER ROLE \&.\&.\&. IN DATABASE \&.\&.\&. SET \&.\&.\&.\fR
185 commands that mention this database\&. Access privileges for the database itself are also dumped, unless
189 This option is ignored when emitting an archive (non\-text) output file\&. For the archive formats, you can specify the option when you call
193 \fB\-e \fR\fB\fIpattern\fR\fR
195 \fB\-\-extension=\fR\fB\fIpattern\fR\fR
197 Dump only extensions matching
198 \fIpattern\fR\&. When this option is not specified, all non\-system extensions in the target database will be dumped\&. Multiple extensions can be selected by writing multiple
202 parameter is interpreted as a pattern according to the same rules used by
206 Patterns), so multiple extensions can also be selected by writing wildcard characters in the pattern\&. When using wildcards, be careful to quote the pattern if needed to prevent the shell from expanding the wildcards\&.
208 Any configuration relation registered by
209 \fBpg_extension_config_dump\fR
210 is included in the dump if its extension is specified by
211 \fB\-\-extension\fR\&.
217 .nr an-no-space-flag 1
228 makes no attempt to dump any other database objects that the selected extension(s) might depend upon\&. Therefore, there is no guarantee that the results of a specific\-extension dump can be successfully restored by themselves into a clean database\&.
233 \fB\-E \fR\fB\fIencoding\fR\fR
235 \fB\-\-encoding=\fR\fB\fIencoding\fR\fR
237 Create the dump in the specified character set encoding\&. By default, the dump is created in the database encoding\&. (Another way to get the same result is to set the
238 \fBPGCLIENTENCODING\fR
239 environment variable to the desired dump encoding\&.) The supported encodings are described in
243 \fB\-f \fR\fB\fIfile\fR\fR
245 \fB\-\-file=\fR\fB\fIfile\fR\fR
247 Send output to the specified file\&. This parameter can be omitted for file based output formats, in which case the standard output is used\&. It must be given for the directory output format however, where it specifies the target directory instead of a file\&. In this case the directory is created by
249 and must not exist before\&.
252 \fB\-F \fR\fB\fIformat\fR\fR
254 \fB\-\-format=\fR\fB\fIformat\fR\fR
256 Selects the format of the output\&.
258 can be one of the following:
266 script file (the default)\&.
273 Output a custom\-format archive suitable for input into
274 pg_restore\&. Together with the directory output format, this is the most flexible output format in that it allows manual selection and reordering of archived items during restore\&. This format is also compressed by default\&.
281 Output a directory\-format archive suitable for input into
282 pg_restore\&. This will create a directory with one file for each table and large object being dumped, plus a so\-called Table of Contents file describing the dumped objects in a machine\-readable format that
284 can read\&. A directory format archive can be manipulated with standard Unix tools; for example, files in an uncompressed archive can be compressed with the
288 tools\&. This format is compressed by default using
290 and also supports parallel dumps\&.
298 \fBtar\fR\-format archive suitable for input into
299 pg_restore\&. The tar format is compatible with the directory format: extracting a tar\-format archive produces a valid directory\-format archive\&. However, the tar format does not support compression\&. Also, when using tar format the relative order of table data items cannot be changed during restore\&.
303 \fB\-j \fR\fB\fInjobs\fR\fR
305 \fB\-\-jobs=\fR\fB\fInjobs\fR\fR
307 Run the dump in parallel by dumping
309 tables simultaneously\&. This option may reduce the time needed to perform the dump but it also increases the load on the database server\&. You can only use this option with the directory output format because this is the only output format where multiple processes can write their data at the same time\&.
314 + 1 connections to the database, so make sure your
316 setting is high enough to accommodate all connections\&.
318 Requesting exclusive locks on database objects while running a parallel dump could cause the dump to fail\&. The reason is that the
320 leader process requests shared locks (ACCESS SHARE) on the objects that the worker processes are going to dump later in order to make sure that nobody deletes them and makes them go away while the dump is running\&. If another client then requests an exclusive lock on a table, that lock will not be granted but will be queued waiting for the shared lock of the leader process to be released\&. Consequently any other access to the table will not be granted either and will queue after the exclusive lock request\&. This includes the worker process trying to dump the table\&. Without any precautions this would be a classic deadlock situation\&. To detect this conflict, the
322 worker process requests another shared lock using the
324 option\&. If the worker process is not granted this shared lock, somebody else must have requested an exclusive lock in the meantime and there is no way to continue with the dump, so
326 has no choice but to abort the dump\&.
328 To perform a parallel dump, the database server needs to support synchronized snapshots, a feature that was introduced in
330 9\&.2 for primary servers and 10 for standbys\&. With this feature, database clients can ensure they see the same data set even though they use different connections\&.
332 uses multiple database connections; it connects to the database once with the leader process and once again for each worker job\&. Without the synchronized snapshot feature, the different worker jobs wouldn\*(Aqt be guaranteed to see the same data in each connection, which could lead to an inconsistent backup\&.
335 \fB\-n \fR\fB\fIpattern\fR\fR
337 \fB\-\-schema=\fR\fB\fIpattern\fR\fR
339 Dump only schemas matching
340 \fIpattern\fR; this selects both the schema itself, and all its contained objects\&. When this option is not specified, all non\-system schemas in the target database will be dumped\&. Multiple schemas can be selected by writing multiple
344 parameter is interpreted as a pattern according to the same rules used by
348 Patterns), so multiple schemas can also be selected by writing wildcard characters in the pattern\&. When using wildcards, be careful to quote the pattern if needed to prevent the shell from expanding the wildcards; see
356 .nr an-no-space-flag 1
367 makes no attempt to dump any other database objects that the selected schema(s) might depend upon\&. Therefore, there is no guarantee that the results of a specific\-schema dump can be successfully restored by themselves into a clean database\&.
375 .nr an-no-space-flag 1
382 Non\-schema objects such as large objects are not dumped when
384 is specified\&. You can add large objects back to the dump with the
385 \fB\-\-large\-objects\fR
391 \fB\-N \fR\fB\fIpattern\fR\fR
393 \fB\-\-exclude\-schema=\fR\fB\fIpattern\fR\fR
395 Do not dump any schemas matching
396 \fIpattern\fR\&. The pattern is interpreted according to the same rules as for
399 can be given more than once to exclude schemas matching any of several patterns\&.
405 are given, the behavior is to dump just the schemas that match at least one
412 \fB\-n\fR, then schemas matching
414 are excluded from what is otherwise a normal dump\&.
421 Do not output commands to set ownership of objects to match the original database\&. By default,
426 \fBSET SESSION AUTHORIZATION\fR
427 statements to set ownership of created database objects\&. These statements will fail when the script is run unless it is started by a superuser (or the same user that owns all of the objects in the script)\&. To make a script that can be restored by any user, but will give that user ownership of all the objects, specify
430 This option is ignored when emitting an archive (non\-text) output file\&. For the archive formats, you can specify the option when you call
436 \fB\-\-no\-reconnect\fR
438 This option is obsolete but still accepted for backwards compatibility\&.
443 \fB\-\-schema\-only\fR
445 Dump only the object definitions (schema), not data or statistics\&.
447 This option cannot be used with
450 \fB\-\-statistics\-only\fR\&. It is similar to, but for historical reasons not identical to, specifying
451 \fB\-\-section=pre\-data \-\-section=post\-data\fR\&.
453 (Do not confuse this with the
455 option, which uses the word
457 in a different meaning\&.)
459 To exclude table data for only a subset of tables in the database, see
460 \fB\-\-exclude\-table\-data\fR\&.
463 \fB\-S \fR\fB\fIusername\fR\fR
465 \fB\-\-superuser=\fR\fB\fIusername\fR\fR
467 Specify the superuser user name to use when disabling triggers\&. This is relevant only if
468 \fB\-\-disable\-triggers\fR
469 is used\&. (Usually, it\*(Aqs better to leave this out, and instead start the resulting script as superuser\&.)
472 \fB\-t \fR\fB\fIpattern\fR\fR
474 \fB\-\-table=\fR\fB\fIpattern\fR\fR
476 Dump only tables with names matching
477 \fIpattern\fR\&. Multiple tables can be selected by writing multiple
481 parameter is interpreted as a pattern according to the same rules used by
485 Patterns), so multiple tables can also be selected by writing wildcard characters in the pattern\&. When using wildcards, be careful to quote the pattern if needed to prevent the shell from expanding the wildcards; see
489 As well as tables, this option can be used to dump the definition of matching views, materialized views, foreign tables, and sequences\&. It will not dump the contents of views or materialized views, and the contents of foreign tables will only be dumped if the corresponding foreign server is specified with
490 \fB\-\-include\-foreign\-data\fR\&.
496 switches have no effect when
498 is used, because tables selected by
500 will be dumped regardless of those switches, and non\-table objects will not be dumped\&.
506 .nr an-no-space-flag 1
517 makes no attempt to dump any other database objects that the selected table(s) might depend upon\&. Therefore, there is no guarantee that the results of a specific\-table dump can be successfully restored by themselves into a clean database\&.
522 \fB\-T \fR\fB\fIpattern\fR\fR
524 \fB\-\-exclude\-table=\fR\fB\fIpattern\fR\fR
526 Do not dump any tables matching
527 \fIpattern\fR\&. The pattern is interpreted according to the same rules as for
530 can be given more than once to exclude tables matching any of several patterns\&.
536 are given, the behavior is to dump just the tables that match at least one
543 \fB\-t\fR, then tables matching
545 are excluded from what is otherwise a normal dump\&.
552 Specifies verbose mode\&. This will cause
554 to output detailed object comments and start/stop times to the dump file, and progress messages to standard error\&. Repeating the option causes additional debug\-level messages to appear on standard error\&.
568 \fB\-\-no\-privileges\fR
572 Prevent dumping of access privileges (grant/revoke commands)\&.
575 \fB\-Z \fR\fB\fIlevel\fR\fR
577 \fB\-Z \fR\fB\fImethod\fR\fR[:\fIdetail\fR]
579 \fB\-\-compress=\fR\fB\fIlevel\fR\fR
581 \fB\-\-compress=\fR\fB\fImethod\fR\fR[:\fIdetail\fR]
583 Specify the compression method and/or the compression level to use\&. The compression method can be set to
588 for no compression\&. A compression detail string can optionally be specified\&. If the detail string is an integer, it specifies the compression level\&. Otherwise, it should be a comma\-separated list of items, each of the form
591 keyword=value\&. Currently, the supported keywords are
596 If no compression level is specified, the default compression level will be used\&. If only a level is specified without mentioning an algorithm,
598 compression will be used if the level is greater than
599 0, and no compression will be used if the level is
602 For the custom and directory archive formats, this specifies compression of individual table\-data segments, and the default is to compress using
604 at a moderate level\&. For plain text output, setting a nonzero compression level causes the entire output file to be compressed, as though it had been fed through
607 zstd; but the default is not to compress\&. With zstd compression,
609 mode may improve the compression ratio, at the cost of increased memory use\&.
611 The tar archive format currently does not support compression at all\&.
614 \fB\-\-binary\-upgrade\fR
616 This option is for use by in\-place upgrade utilities\&. Its use for other purposes is not recommended or supported\&. The behavior of the option may change in future releases without notice\&.
619 \fB\-\-column\-inserts\fR
621 \fB\-\-attribute\-inserts\fR
625 commands with explicit column names (INSERT INTO \fItable\fR (\fIcolumn\fR, \&.\&.\&.) VALUES \&.\&.\&.)\&. This will make restoration very slow; it is mainly useful for making dumps that can be loaded into non\-PostgreSQL
626 databases\&. Any error during restoring will cause only rows that are part of the problematic
628 to be lost, rather than the entire table contents\&.
631 \fB\-\-disable\-dollar\-quoting\fR
633 This option disables the use of dollar quoting for function bodies, and forces them to be quoted using SQL standard string syntax\&.
636 \fB\-\-disable\-triggers\fR
638 This option is relevant only when creating a dump that includes data but does not include schema\&. It instructs
640 to include 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\&.
642 Presently, the commands emitted for
643 \fB\-\-disable\-triggers\fR
644 must be done as superuser\&. So, you should also specify a superuser name with
645 \fB\-S\fR, or preferably be careful to start the resulting script as a superuser\&.
647 This option is ignored when emitting an archive (non\-text) output file\&. For the archive formats, you can specify the option when you call
651 \fB\-\-enable\-row\-security\fR
653 This option is relevant only when dumping the contents of a table which has row security\&. By default,
657 to off, to ensure that all data is dumped from the table\&. If the user does not have sufficient privileges to bypass row security, then an error is thrown\&. This parameter instructs
661 to on instead, allowing the user to dump the parts of the contents of the table that they have access to\&.
663 Note that if you use this option currently, you probably also want the dump be in
667 during restore does not support row security\&.
670 \fB\-\-exclude\-extension=\fR\fB\fIpattern\fR\fR
672 Do not dump any extensions matching
673 \fIpattern\fR\&. The pattern is interpreted according to the same rules as for
675 \fB\-\-exclude\-extension\fR
676 can be given more than once to exclude extensions matching any of several patterns\&.
681 \fB\-\-exclude\-extension\fR
682 are given, the behavior is to dump just the extensions that match at least one
685 \fB\-\-exclude\-extension\fR
687 \fB\-\-exclude\-extension\fR
689 \fB\-e\fR, then extensions matching
690 \fB\-\-exclude\-extension\fR
691 are excluded from what is otherwise a normal dump\&.
694 \fB\-\-exclude\-table\-and\-children=\fR\fB\fIpattern\fR\fR
696 This is the same as the
697 \fB\-T\fR/\fB\-\-exclude\-table\fR
698 option, except that it also excludes any partitions or inheritance child tables of the table(s) matching the
702 \fB\-\-exclude\-table\-data=\fR\fB\fIpattern\fR\fR
704 Do not dump data for any tables matching
705 \fIpattern\fR\&. The pattern is interpreted according to the same rules as for
707 \fB\-\-exclude\-table\-data\fR
708 can be given more than once to exclude tables matching any of several patterns\&. This option is useful when you need the definition of a particular table even though you do not need the data in it\&.
710 To exclude data for all tables in the database, see
711 \fB\-\-schema\-only\fR
713 \fB\-\-statistics\-only\fR\&.
716 \fB\-\-exclude\-table\-data\-and\-children=\fR\fB\fIpattern\fR\fR
718 This is the same as the
719 \fB\-\-exclude\-table\-data\fR
720 option, except that it also excludes data of any partitions or inheritance child tables of the table(s) matching the
724 \fB\-\-extra\-float\-digits=\fR\fB\fIndigits\fR\fR
726 Use the specified value of
727 \fBextra_float_digits\fR
728 when dumping floating\-point data, instead of the maximum available precision\&. Routine dumps made for backup purposes should not use this option\&.
731 \fB\-\-filter=\fR\fB\fIfilename\fR\fR
733 Specify a filename from which to read patterns for objects to include or exclude from the dump\&. The patterns are interpreted according to the same rules as the corresponding options:
734 \fB\-t\fR/\fB\-\-table\fR,
735 \fB\-\-table\-and\-children\fR,
736 \fB\-T\fR/\fB\-\-exclude\-table\fR, and
737 \fB\-\-exclude\-table\-and\-children\fR
739 \fB\-n\fR/\fB\-\-schema\fR
741 \fB\-N\fR/\fB\-\-exclude\-schema\fR
743 \fB\-\-include\-foreign\-data\fR
744 for data on foreign servers,
745 \fB\-\-exclude\-table\-data\fR
747 \fB\-\-exclude\-table\-data\-and\-children\fR
749 \fB\-e\fR/\fB\-\-extension\fR
751 \fB\-\-exclude\-extension\fR
752 for extensions\&. To read from
755 as the filename\&. The
757 option can be specified in conjunction with the above listed options for including or excluding objects, and can also be specified more than once for multiple filter files\&.
759 The file lists one object pattern per row, with the following format:
765 { include | exclude } { extension | foreign_data | table | table_and_children | table_data | table_data_and_children | schema } \fIPATTERN\fR
771 The first keyword specifies whether the objects matched by the pattern are to be included or excluded\&. The second keyword specifies the type of object to be filtered using the pattern:
781 extension: extensions\&. This works like the
782 \fB\-e\fR/\fB\-\-extension\fR
784 \fB\-\-exclude\-extension\fR
796 foreign_data: data on foreign servers\&. This works like the
797 \fB\-\-include\-foreign\-data\fR
798 option\&. This keyword can only be used with the
811 table: tables\&. This works like the
812 \fB\-t\fR/\fB\-\-table\fR
814 \fB\-T\fR/\fB\-\-exclude\-table\fR
826 table_and_children: tables including any partitions or inheritance child tables\&. This works like the
827 \fB\-\-table\-and\-children\fR
829 \fB\-\-exclude\-table\-and\-children\fR
841 table_data: table data of any tables matching
842 \fIpattern\fR\&. This works like the
843 \fB\-\-exclude\-table\-data\fR
844 option\&. This keyword can only be used with the
857 table_data_and_children: table data of any tables matching
859 as well as any partitions or inheritance children of the table(s)\&. This works like the
860 \fB\-\-exclude\-table\-data\-and\-children\fR
861 option\&. This keyword can only be used with the
874 schema: schemas\&. This works like the
875 \fB\-n\fR/\fB\-\-schema\fR
877 \fB\-N\fR/\fB\-\-exclude\-schema\fR
883 are considered comments and ignored\&. Comments can be placed after an object pattern row as well\&. Blank lines are also ignored\&. See
885 for how to perform quoting in patterns\&.
887 Example files are listed below in the
895 DROP \&.\&.\&. IF EXISTS
896 commands to drop objects in
898 mode\&. This suppresses
899 \(lqdoes not exist\(rq
900 errors that might otherwise be reported\&. This option is not valid unless
905 \fB\-\-include\-foreign\-data=\fR\fB\fIforeignserver\fR\fR
907 Dump the data for any foreign table with a foreign server matching
909 pattern\&. Multiple foreign servers can be selected by writing multiple
910 \fB\-\-include\-foreign\-data\fR
911 switches\&. Also, the
913 parameter is interpreted as a pattern according to the same rules used by
917 Patterns), so multiple foreign servers can also be selected by writing wildcard characters in the pattern\&. When using wildcards, be careful to quote the pattern if needed to prevent the shell from expanding the wildcards; see
919 below\&. The only exception is that an empty pattern is disallowed\&.
925 .nr an-no-space-flag 1
933 \fB\-\-include\-foreign\-data\fR
934 may result in access to unexpected foreign servers\&. Also, to use this option securely, make sure that the named server must have a trusted owner\&.
942 .nr an-no-space-flag 1
950 \fB\-\-include\-foreign\-data\fR
953 does not check that the foreign table is writable\&. Therefore, there is no guarantee that the results of a foreign table dump can be successfully restored\&.
962 commands (rather than
963 \fBCOPY\fR)\&. This will make restoration very slow; it is mainly useful for making dumps that can be loaded into non\-PostgreSQL
964 databases\&. Any error during restoring will cause only rows that are part of the problematic
966 to be lost, rather than the entire table contents\&. Note that the restore might fail altogether if you have rearranged column order\&. The
967 \fB\-\-column\-inserts\fR
968 option is safe against column order changes, though even slower\&.
971 \fB\-\-load\-via\-partition\-root\fR
973 When dumping data for a table partition, make the
977 statements target the root of the partitioning hierarchy that contains it, rather than the partition itself\&. This causes the appropriate partition to be re\-determined for each row when the data is loaded\&. This may be useful when restoring data on a server where rows do not always fall into the same partitions as they did on the original server\&. That could happen, for example, if the partitioning column is of type text and the two systems have different definitions of the collation used to sort the partitioning column\&.
980 \fB\-\-lock\-wait\-timeout=\fR\fB\fItimeout\fR\fR
982 Do not wait forever to acquire shared table locks at the beginning of the dump\&. Instead fail if unable to lock a table within the specified
983 \fItimeout\fR\&. The timeout may be specified in any of the formats accepted by
984 \fBSET statement_timeout\fR\&. (Allowed formats vary depending on the server version you are dumping from, but an integer number of milliseconds is accepted by all versions\&.)
987 \fB\-\-no\-comments\fR
999 \fB\-\-no\-policies\fR
1001 Do not dump row security policies\&.
1004 \fB\-\-no\-publications\fR
1006 Do not dump publications\&.
1009 \fB\-\-no\-schema\fR
1011 Do not dump schema (data definitions)\&.
1014 \fB\-\-no\-security\-labels\fR
1016 Do not dump security labels\&.
1019 \fB\-\-no\-statistics\fR
1021 Do not dump statistics\&. This is the default\&.
1024 \fB\-\-no\-subscriptions\fR
1026 Do not dump subscriptions\&.
1033 will wait for all files to be written safely to disk\&. This option causes
1035 to return without waiting, which is faster, but means that a subsequent operating system crash can leave the dump corrupt\&. Generally, this option is useful for testing but should not be used when dumping data from production installation\&.
1038 \fB\-\-no\-table\-access\-method\fR
1040 Do not output commands to select table access methods\&. With this option, all objects will be created with whichever table access method is the default during restore\&.
1042 This option is ignored when emitting an archive (non\-text) output file\&. For the archive formats, you can specify the option when you call
1046 \fB\-\-no\-tablespaces\fR
1048 Do not output commands to select tablespaces\&. With this option, all objects will be created in whichever tablespace is the default during restore\&.
1050 This option is ignored when emitting an archive (non\-text) output file\&. For the archive formats, you can specify the option when you call
1054 \fB\-\-no\-toast\-compression\fR
1056 Do not output commands to set
1058 compression methods\&. With this option, all columns will be restored with the default compression setting\&.
1061 \fB\-\-no\-unlogged\-table\-data\fR
1063 Do not dump the contents of unlogged tables and sequences\&. This option has no effect on whether or not the table and sequence definitions (schema) are dumped; it only suppresses dumping the table and sequence data\&. Data in unlogged tables and sequences is always excluded when dumping from a standby server\&.
1066 \fB\-\-on\-conflict\-do\-nothing\fR
1069 ON CONFLICT DO NOTHING
1072 commands\&. This option is not valid unless
1074 \fB\-\-column\-inserts\fR
1076 \fB\-\-rows\-per\-insert\fR
1077 is also specified\&.
1080 \fB\-\-quote\-all\-identifiers\fR
1082 Force quoting of all identifiers\&. This option is recommended when dumping a database from a server whose
1084 major version is different from
1085 pg_dump\*(Aqs, or when the output is intended to be loaded into a server of a different major version\&. By default,
1087 quotes only identifiers that are reserved words in its own major version\&. This sometimes results in compatibility issues when dealing with servers of other versions that may have slightly different sets of reserved words\&. Using
1088 \fB\-\-quote\-all\-identifiers\fR
1089 prevents such issues, at the price of a harder\-to\-read dump script\&.
1092 \fB\-\-restrict\-key=\fR\fB\fIrestrict_key\fR\fR
1094 Use the provided string as the
1097 key in the dump output\&. This can only be specified for plain\-text dumps, i\&.e\&., when
1103 option is omitted\&. If no restrict key is specified,
1105 will generate a random one as needed\&. Keys may contain only alphanumeric characters\&.
1107 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
1109 with the dump output\&.
1112 \fB\-\-rows\-per\-insert=\fR\fB\fInrows\fR\fR
1116 commands (rather than
1117 \fBCOPY\fR)\&. Controls the maximum number of rows per
1119 command\&. The value specified must be a number greater than zero\&. Any error during restoring will cause only rows that are part of the problematic
1121 to be lost, rather than the entire table contents\&.
1124 \fB\-\-section=\fR\fB\fIsectionname\fR\fR
1126 Only dump the named section\&. The section name can be
1129 \fBpost\-data\fR\&. This option can be specified more than once to select multiple sections\&. The default is to dump all sections\&.
1131 The data section contains actual table data, large\-object contents, sequence values, and statistics for tables, materialized views, and foreign tables\&. Post\-data items include definitions of indexes, triggers, rules, statistics for indexes, and constraints other than validated check and not\-null constraints\&. Pre\-data items include all other data definition items\&.
1134 \fB\-\-sequence\-data\fR
1136 Include sequence data in the dump\&. This is the default behavior except when
1138 \fB\-\-schema\-only\fR, or
1139 \fB\-\-statistics\-only\fR
1143 \fB\-\-serializable\-deferrable\fR
1147 transaction for the dump, to ensure that the snapshot used is consistent with later database states; but do this by waiting for a point in the transaction stream at which no anomalies can be present, so that there isn\*(Aqt a risk of the dump failing or causing other transactions to roll back with a
1148 serialization_failure\&. See
1150 for more information about transaction isolation and concurrency control\&.
1152 This option is not beneficial for a dump which is intended only for disaster recovery\&. It could be useful for a dump used to load a copy of the database for reporting or other read\-only load sharing while the original database continues to be updated\&. Without it the dump may reflect a state which is not consistent with any serial execution of the transactions eventually committed\&. For example, if batch processing techniques are used, a batch may show as closed in the dump without all of the items which are in the batch appearing\&.
1154 This option will make no difference if there are no read\-write transactions active when pg_dump is started\&. If read\-write transactions are active, the start of the dump may be delayed for an indeterminate length of time\&. Once running, performance with or without the switch is the same\&.
1157 \fB\-\-snapshot=\fR\fB\fIsnapshotname\fR\fR
1159 Use the specified synchronized snapshot when making a dump of the database (see
1161 for more details)\&.
1163 This option is useful when needing to synchronize the dump with a logical replication slot (see
1164 Chapter\ \&47) or with a concurrent session\&.
1166 In the case of a parallel dump, the snapshot name defined by this option is used rather than taking a new snapshot\&.
1169 \fB\-\-statistics\fR
1174 \fB\-\-statistics\-only\fR
1176 Dump only the statistics, not the schema (data definitions) or data\&. Statistics for tables, materialized views, foreign tables, and indexes are dumped\&.
1179 \fB\-\-strict\-names\fR
1181 Require that each extension (\fB\-e\fR/\fB\-\-extension\fR), schema (\fB\-n\fR/\fB\-\-schema\fR) and table (\fB\-t\fR/\fB\-\-table\fR) pattern match at least one extension/schema/table in the database to be dumped\&. This also applies to filters used with
1182 \fB\-\-filter\fR\&. Note that if none of the extension/schema/table patterns find matches,
1184 will generate an error even without
1185 \fB\-\-strict\-names\fR\&.
1187 This option has no effect on
1188 \fB\-\-exclude\-extension\fR,
1189 \fB\-N\fR/\fB\-\-exclude\-schema\fR,
1190 \fB\-T\fR/\fB\-\-exclude\-table\fR, or
1191 \fB\-\-exclude\-table\-data\fR\&. An exclude pattern failing to match any objects is not considered an error\&.
1194 \fB\-\-sync\-method=\fR\fB\fImethod\fR\fR
1197 fsync, which is the default,
1198 \fBpg_dump \-\-format=directory\fR
1199 will recursively open and synchronize all files in the archive directory\&.
1203 may be used instead to ask the operating system to synchronize the whole file system that contains the archive directory\&. See
1204 recovery_init_sync_method
1205 for information about the caveats to be aware of when using
1208 This option has no effect when
1216 \fB\-\-table\-and\-children=\fR\fB\fIpattern\fR\fR
1218 This is the same as the
1219 \fB\-t\fR/\fB\-\-table\fR
1220 option, except that it also includes any partitions or inheritance child tables of the table(s) matching the
1224 \fB\-\-use\-set\-session\-authorization\fR
1226 Output SQL\-standard
1227 \fBSET SESSION AUTHORIZATION\fR
1230 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\&. Also, a dump using
1231 \fBSET SESSION AUTHORIZATION\fR
1232 will certainly require superuser privileges to restore correctly, whereas
1234 requires lesser privileges\&.
1243 command line arguments, and exit\&.
1246 The following command\-line options control the database connection parameters\&.
1248 \fB\-d \fR\fB\fIdbname\fR\fR
1250 \fB\-\-dbname=\fR\fB\fIdbname\fR\fR
1252 Specifies the name of the database to connect to\&. This is equivalent to specifying
1254 as the first non\-option argument on the command line\&. The
1257 connection string\&. If so, connection string parameters will override any conflicting command line options\&.
1260 \fB\-h \fR\fB\fIhost\fR\fR
1262 \fB\-\-host=\fR\fB\fIhost\fR\fR
1264 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
1266 environment variable, if set, else a Unix domain socket connection is attempted\&.
1269 \fB\-p \fR\fB\fIport\fR\fR
1271 \fB\-\-port=\fR\fB\fIport\fR\fR
1273 Specifies the TCP port or local Unix domain socket file extension on which the server is listening for connections\&. Defaults to the
1275 environment variable, if set, or a compiled\-in default\&.
1278 \fB\-U \fR\fB\fIusername\fR\fR
1280 \fB\-\-username=\fR\fB\fIusername\fR\fR
1282 User name to connect as\&.
1287 \fB\-\-no\-password\fR
1289 Never issue a password prompt\&. If the server requires password authentication and a password is not available by other means such as a
1291 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\&.
1300 to prompt for a password before connecting to a database\&.
1302 This option is never essential, since
1304 will automatically prompt for a password if the server demands password authentication\&. However,
1306 will waste a connection attempt finding out that the server wants a password\&. In some cases it is worth typing
1308 to avoid the extra connection attempt\&.
1311 \fB\-\-role=\fR\fB\fIrolename\fR\fR
1313 Specifies a role name to be used to create the dump\&. This option causes
1318 command after connecting to the database\&. It is useful when the authenticated user (specified by
1319 \fB\-U\fR) lacks privileges needed by
1320 pg_dump, 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 dumps to be made without violating the policy\&.
1334 Default connection parameters\&.
1339 Specifies whether to use color in diagnostic messages\&. Possible values are
1346 This utility, like most other
1348 utilities, also uses the environment variables supported by
1351 Section\ \&32.15)\&.
1357 statements\&. If you have problems running
1358 pg_dump, make sure you are able to select information from the database using, for example,
1359 \fBpsql\fR(1)\&. Also, any default connection settings and environment variables used by the
1361 front\-end library will apply\&.
1363 The database activity of
1365 is normally collected by the cumulative statistics system\&. If this is undesirable, you can set parameter
1374 If your database cluster has any local additions to the
1376 database, be careful to restore the output of
1378 into a truly empty database; otherwise you are likely to get errors due to duplicate definitions of the added objects\&. To make an empty database without any local additions, copy from
1381 template1, for example:
1387 CREATE DATABASE foo WITH TEMPLATE template0;
1393 When a dump without schema is chosen and the option
1394 \fB\-\-disable\-triggers\fR
1397 emits commands to disable triggers on user tables before inserting the data, and then commands to re\-enable them after the data has been inserted\&. If the restore is stopped in the middle, the system catalogs might be left in the wrong state\&.
1400 \fB\-\-statistics\fR
1403 will include most optimizer statistics in the resulting dump file\&. However, some statistics may not be included, such as those created explicitly with
1404 CREATE STATISTICS (\fBCREATE_STATISTICS\fR(7))
1405 or custom statistics added by an extension\&. Therefore, it may be useful to run
1407 after restoring from a dump file to ensure optimal performance; see
1411 for more information\&.
1415 is used to transfer data to newer versions of
1416 PostgreSQL, the output of
1418 can be expected to load into
1420 server versions newer than
1421 pg_dump\*(Aqs version\&.
1425 servers older than its own version\&. (Currently, servers back to version 9\&.2 are supported\&.) However,
1429 servers newer than its own major version; it will refuse to even try, rather than risk making an invalid dump\&. Also, it is not guaranteed that
1430 pg_dump\*(Aqs output can be loaded into a server of an older major version \(em not even if the dump was taken from a server of that version\&. Loading a dump file into an older server may require manual editing of the dump file to remove syntax not understood by the older server\&. Use of the
1431 \fB\-\-quote\-all\-identifiers\fR
1432 option is recommended in cross\-version cases, as it can prevent problems arising from varying reserved\-word lists in different
1436 When dumping logical replication subscriptions,
1439 \fBCREATE SUBSCRIPTION\fR
1440 commands that use the
1442 option, so that restoring the subscription does not make remote connections for creating a replication slot or for initial table copy\&. That way, the dump can be restored without requiring network access to the remote servers\&. It is then up to the user to reactivate the subscriptions in a suitable way\&. If the involved hosts have changed, the connection information might have to be changed\&. It might also be appropriate to truncate the target tables before initiating a new full table copy\&. If users intend to copy initial data during refresh they must create the slot with
1443 two_phase = false\&. After the initial sync, the
1445 option will be automatically enabled by the subscriber if the subscription had been originally created with
1449 It is generally recommended to use the
1451 (\fB\-\-no\-psqlrc\fR) option when restoring a database from a plain\-text
1453 script to ensure a clean restore process and prevent potential conflicts with non\-default
1458 To dump a database called
1460 into an SQL\-script file:
1466 $ \fBpg_dump mydb > db\&.sql\fR
1472 To reload such a script into a (freshly created) database named
1479 $ \fBpsql \-X \-d newdb \-f db\&.sql\fR
1485 To dump a database into a custom\-format archive file:
1491 $ \fBpg_dump \-Fc mydb > db\&.dump\fR
1497 To dump a database into a directory\-format archive:
1503 $ \fBpg_dump \-Fd mydb \-f dumpdir\fR
1509 To dump a database into a directory\-format archive in parallel with 5 worker jobs:
1515 $ \fBpg_dump \-Fd mydb \-j 5 \-f dumpdir\fR
1521 To reload an archive file into a (freshly created) database named
1528 $ \fBpg_restore \-d newdb db\&.dump\fR
1534 To reload an archive file into the same database it was dumped from, discarding the current contents of that database:
1540 $ \fBpg_restore \-d postgres \-\-clean \-\-create db\&.dump\fR
1546 To dump a single table named
1553 $ \fBpg_dump \-t mytab mydb > db\&.sql\fR
1559 To dump all tables whose names start with
1563 schema, except for the table named
1570 $ \fBpg_dump \-t \*(Aqdetroit\&.emp*\*(Aq \-T detroit\&.employee_log mydb > db\&.sql\fR
1576 To dump all schemas whose names start with
1581 gsm, excluding any schemas whose names contain the word
1588 $ \fBpg_dump \-n \*(Aqeast*gsm\*(Aq \-n \*(Aqwest*gsm\*(Aq \-N \*(Aq*test*\*(Aq mydb > db\&.sql\fR
1594 The same, using regular expression notation to consolidate the switches:
1600 $ \fBpg_dump \-n \*(Aq(east|west)*gsm\*(Aq \-N \*(Aq*test*\*(Aq mydb > db\&.sql\fR
1606 To dump all database objects except for tables whose names begin with
1613 $ \fBpg_dump \-T \*(Aqts_*\*(Aq mydb > db\&.sql\fR
1619 To specify an upper\-case or mixed\-case name in
1621 and related switches, you need to double\-quote the name; else it will be folded to lower case (see
1622 Patterns)\&. But double quotes are special to the shell, so in turn they must be quoted\&. Thus, to dump a single table with a mixed\-case name, you need something like
1628 $ \fBpg_dump \-t "\e"MixedCaseName\e"" mydb > mytab\&.sql\fR
1634 To dump all tables whose names start with
1635 mytable, except for table
1636 mytable2, specify a filter file
1644 include table mytable*
1645 exclude table mytable2
1657 $ \fBpg_dump \-\-filter=filter\&.txt mydb > db\&.sql\fR
1663 \fBpg_dumpall\fR(1), \fBpg_restore\fR(1), \fBpsql\fR(1)