- Extract a
Postgres database into a script file
+ Extract a
Postgres database into a script file
or other archive file
- 1999-07-20
+ 2000-11-22
pg_dump [ dbname ]
pg_dump [ -h host ]
[ -p port ]
- [ -t table ]
- [ -a ] [ -c ] [ -d ] [ -D ] [ -i ] [ -n ] [ -N ]
- [ -o ] [ -s ] [ -u ] [ -v ] [ -x ]
+ [ -t table ]\r
+ [ -a ] [ -b ] [ -c ] [-C] [ -d ] [ -D ] \r
+ [-f file] \r
+ [-F format] \r
+ [ -i ] [ -n ] [ -N ] [ -o ] [ -O ] [-R] \r
+ [ -s ] [ -S ] [ -u ] [ -v ] [ -x ] [ -Z 0..9 ] \r
[ dbname ]
- 1998-11-05
+ 2000-11-22
Inputs
-
- -c
-
- Clean (drop) schema prior to create.
-
-
-
-
+ \r
+ -b\r
+ \r
+ Dump BLOB data.\r
+ \r
+ \r
+ \r
+\r
+ \r
+ -c\r
+ \r
+ Clean (drop) schema prior to create.\r
+ \r
+ \r
+ \r
+\r
+ \r
+ -C\r
+ \r
+ For plain text (script) output, include SQL to create the database itself.\r
+ \r
+ \r
+ \r
+\r
-d
- Dump data as proper insert strings.
+ Dump data as proper insert strings. This is not recommended for large databases\r
+ for performance reasons.
-D
- Dump data as inserts with attribute names
+ Dump data as inserts with attribute names. This is not recommended for large databases\r
+ for performance reasons.
+\r
+ \r
+ -f file\r
+ \r
+ Send output to the specified file.\r
+ \r
+ \r
+ \r
+\r
+ \r
+ -F format\r
+ \r
+ Format can be one of the following:\r
+ \r
+\r
+\r
+ \r
+ \r
+ p\r
+ \r
+ output a plain text SQL script file (default)\r
+ \r
+ \r
+ \r
+\r
+ \r
+ t\r
+ \r
+ output a TAR archive suitable for input into \r
+
pg_restore. Using this archive format
\r
+ allows reordering and/or exclusion of schema elements \r
+ at the time the database is restored. It is also possible to limit \r
+ which data is reloaded at restore time.\r
+ \r
+ \r
+ \r
+\r
+ \r
+ c\r
+ \r
+ output a custom archive suitable for input into \r
+
pg_restore. This is the most flexible
\r
+ format in that it allows reordering of data load as well \r
+ as schema elements. This format is also compressed by default.\r
+ \r
+ \r
+ \r
+\r
+ \r
+\r
+ \r
+ \r
-i
-
- -o
-
- Dump object identifiers (
OIDs) for every table.
-
-
-
-
+ \r
+ -o\r
+ \r
+ Dump object identifiers (
OIDs) for every table.
\r
+ \r
+ \r
+ \r
+\r
+ \r
+ -O\r
+ \r
+ In plain text output mode, don't set object ownership to match the \r
+ original database. Typically,
pg_dump \r
+ issues
\connect statments to set
\r
+ ownership of schema elements.\r
+ \r
+ \r
+ \r
+\r
+ \r
+ -R\r
+ \r
+ In plain text output mode, prohibit
pg_dump \r
+ from issuing any
\connect statements.
\r
+ \r
+ \r
+ \r
+\r
-s
-
- -t table
-
- Dump data for table only.
-
-
-
-
+ \r
+ -S username\r
+ \r
+ Specify the superuser username to use when disabling triggers and/or \r
+ setting ownership of schema elements.\r
+ \r
+ \r
+ \r
+\r
+ \r
+ -t table\r
+ \r
+ Dump data for table only.\r
+ \r
+ \r
+ \r
+\r
-u
+\r
+ \r
+ -Z 0..9\r
+ \r
+ Specify the compression level to use in archive formats that support \r
+ compression (currently only the custom archive format supports compression).\r
+ \r
+ \r
+ \r
+\r
- 1998-11-05
+ 2000-
Description
pg_dump is a utility for dumping out a
-
Postgres database into a script file
- containing query commands. The script
- files are in text format and can be used to reconstruct the database,
- even on other machines and other architectures.
+
Postgres database into a script or archive
\r
+ file containing query commands. The script files are in text format \r
+ and can be used to reconstruct the database, even on other machines \r
+ and other architectures.\r
+ \r
+ The archive files, new with this v7.1, contain enough information for \r
+
pg_restore to rebuild the database, but also
\r
+ allow pg_restore to be selective about what is restored, or even to \r
+ reorder the items prior to being restored. The archive files should \r
+ also be portable across architectures.\r
+ \r
will produce the queries necessary to re-generate all
user-defined types, functions, tables, indices, aggregates, and
is useful for dumping out the contents of a database to move from one
Postgres installation to another. After running
- one should examine the output script file for any warnings, especially
+ one should examine the output for any warnings, especially
in light of the limitations listed below.
+\r
+ When used with one of the alternate file formats and combined with \r
+
pg_restore, it provides a flexible archival
\r
+ and trasfer mechanism.
pg_dump can be used
\r
+ to backup an entire database, then
pg_restore \r
+ can be used to examine the archive and/or select which parts of the \r
+ database are to be restored.\r
+ \r
+\r
+ See the
pg_restore documentation for details.
\r
+ \r
+\r
- 1998-11-05
+ 2000-11-21
Notes
-
pg_dump does not handle large objects.
- Large objects are ignored and must be dealt with manually.
+ When dumping a single table or as plain text,
pg_dump \r
+ does not handle large objects. Large objects must be dumped in their\r
+ entirity using one of the binary archive formats.\r
- 1998-11-05
+ 2000-11-21
Usage
$ psql -e database < db.out
+\r
+ To dump a database called mydb that contains BLOBs to a TAR file:\r
+\r
+$ pg_dump -Ft --blobs mydb > db.tar\r
+ \r
+ \r
+\r
+ To reload this database (with BLOBs) to an existing db called newdb:\r
+\r
+$ pg_restore db.tar --db=newdb\r
+ \r
+ \r
+\r