<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <HTML ><HEAD ><TITLE >pg_dump</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK REV="MADE" HREF="mailto:pgsql-docs@postgresql.org"><LINK REL="HOME" TITLE="PostgreSQL 8.3.11 Documentation" HREF="index.html"><LINK REL="UP" TITLE="PostgreSQL Client Applications" HREF="reference-client.html"><LINK REL="PREVIOUS" TITLE="pg_config" HREF="app-pgconfig.html"><LINK REL="NEXT" TITLE="pg_dumpall" HREF="app-pg-dumpall.html"><LINK REL="STYLESHEET" TYPE="text/css" HREF="stylesheet.css"><META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-8859-1"><META NAME="creation" CONTENT="2010-05-14T03:43:41"></HEAD ><BODY CLASS="REFENTRY" ><DIV CLASS="NAVHEADER" ><TABLE SUMMARY="Header navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TH COLSPAN="5" ALIGN="center" VALIGN="bottom" >PostgreSQL 8.3.11 Documentation</TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="top" ><A HREF="app-pgconfig.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="10%" ALIGN="left" VALIGN="top" ><A HREF="app-pgconfig.html" >Fast Backward</A ></TD ><TD WIDTH="60%" ALIGN="center" VALIGN="bottom" ></TD ><TD WIDTH="10%" ALIGN="right" VALIGN="top" ><A HREF="app-pg-dumpall.html" >Fast Forward</A ></TD ><TD WIDTH="10%" ALIGN="right" VALIGN="top" ><A HREF="app-pg-dumpall.html" ACCESSKEY="N" >Next</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><H1 ><A NAME="APP-PGDUMP" ></A >pg_dump</H1 ><DIV CLASS="REFNAMEDIV" ><A NAME="AEN62924" ></A ><H2 >Name</H2 >pg_dump -- extract a <SPAN CLASS="PRODUCTNAME" >PostgreSQL</SPAN > database into a script file or other archive file </DIV ><A NAME="AEN62928" ></A ><DIV CLASS="REFSYNOPSISDIV" ><A NAME="AEN62930" ></A ><H2 >Synopsis</H2 ><P ><TT CLASS="COMMAND" >pg_dump</TT > [<TT CLASS="REPLACEABLE" ><I >option</I ></TT >...] [<TT CLASS="REPLACEABLE" ><I >dbname</I ></TT >]</P ></DIV ><DIV CLASS="REFSECT1" ><A NAME="PG-DUMP-DESCRIPTION" ></A ><H2 > Description </H2 ><P > <SPAN CLASS="APPLICATION" >pg_dump</SPAN > is a utility for backing up a <SPAN CLASS="PRODUCTNAME" >PostgreSQL</SPAN > database. It makes consistent backups even if the database is being used concurrently. <SPAN CLASS="APPLICATION" >pg_dump</SPAN > does not block other users accessing the database (readers or writers). </P ><P > 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 <A HREF="app-psql.html" ><SPAN CLASS="APPLICATION" >psql</SPAN ></A >. 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. </P ><P > The alternative archive file formats must be used with <A HREF="app-pgrestore.html" >pg_restore</A > to rebuild the database. They allow <SPAN CLASS="APPLICATION" >pg_restore</SPAN > 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. </P ><P > When used with one of the archive file formats and combined with <SPAN CLASS="APPLICATION" >pg_restore</SPAN >, <SPAN CLASS="APPLICATION" >pg_dump</SPAN > provides a flexible archival and transfer mechanism. <SPAN CLASS="APPLICATION" >pg_dump</SPAN > can be used to backup an entire database, then <SPAN CLASS="APPLICATION" >pg_restore</SPAN > can be used to examine the archive and/or select which parts of the database are to be restored. The most flexible output file format is the <SPAN CLASS="QUOTE" >"custom"</SPAN > format (<TT CLASS="OPTION" >-Fc</TT >). It allows for selection and reordering of all archived items, and is compressed by default. The <SPAN CLASS="APPLICATION" >tar</SPAN > format (<TT CLASS="OPTION" >-Ft</TT >) is not compressed and it is not possible to reorder data when loading, but it is otherwise quite flexible; moreover, it can be manipulated with standard Unix tools such as <TT CLASS="COMMAND" >tar</TT >. </P ><P > While running <SPAN CLASS="APPLICATION" >pg_dump</SPAN >, one should examine the output for any warnings (printed on standard error), especially in light of the limitations listed below. </P ></DIV ><DIV CLASS="REFSECT1" ><A NAME="PG-DUMP-OPTIONS" ></A ><H2 >Options</H2 ><P > The following command-line options control the content and format of the output. <P ></P ></P><DIV CLASS="VARIABLELIST" ><DL ><DT ><TT CLASS="REPLACEABLE" ><I >dbname</I ></TT ></DT ><DD ><P > Specifies the name of the database to be dumped. If this is not specified, the environment variable <TT CLASS="ENVAR" >PGDATABASE</TT > is used. If that is not set, the user name specified for the connection is used. </P ></DD ><DT ><TT CLASS="OPTION" >-a</TT ><BR><TT CLASS="OPTION" >--data-only</TT ></DT ><DD ><P > Dump only the data, not the schema (data definitions). </P ><P > This option is only meaningful for the plain-text format. For the archive formats, you can specify the option when you call <TT CLASS="COMMAND" >pg_restore</TT >. </P ></DD ><DT ><TT CLASS="OPTION" >-b</TT ><BR><TT CLASS="OPTION" >--blobs</TT ></DT ><DD ><P > Include large objects in the dump. This is the default behavior except when <TT CLASS="OPTION" >--schema</TT >, <TT CLASS="OPTION" >--table</TT >, or <TT CLASS="OPTION" >--schema-only</TT > is specified, so the <TT CLASS="OPTION" >-b</TT > switch is only useful to add large objects to selective dumps. </P ></DD ><DT ><TT CLASS="OPTION" >-c</TT ><BR><TT CLASS="OPTION" >--clean</TT ></DT ><DD ><P > Output commands to clean (drop) database objects prior to (the commands for) creating them. </P ><P > This option is only meaningful for the plain-text format. For the archive formats, you can specify the option when you call <TT CLASS="COMMAND" >pg_restore</TT >. </P ></DD ><DT ><TT CLASS="OPTION" >-C</TT ><BR><TT CLASS="OPTION" >--create</TT ></DT ><DD ><P > 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't matter which database you connect to before running the script.) </P ><P > This option is only meaningful for the plain-text format. For the archive formats, you can specify the option when you call <TT CLASS="COMMAND" >pg_restore</TT >. </P ></DD ><DT ><TT CLASS="OPTION" >-d</TT ><BR><TT CLASS="OPTION" >--inserts</TT ></DT ><DD ><P > Dump data as <TT CLASS="COMMAND" >INSERT</TT > commands (rather than <TT CLASS="COMMAND" >COPY</TT >). This will make restoration very slow; it is mainly useful for making dumps that can be loaded into non-<SPAN CLASS="PRODUCTNAME" >PostgreSQL</SPAN > databases. Also, since this option generates a separate command for each row, an error in reloading a row causes only that row to be lost rather than the entire table contents. Note that the restore might fail altogether if you have rearranged column order. The <TT CLASS="OPTION" >-D</TT > option is safe against column order changes, though even slower. </P ></DD ><DT ><TT CLASS="OPTION" >-D</TT ><BR><TT CLASS="OPTION" >--column-inserts</TT ><BR><TT CLASS="OPTION" >--attribute-inserts</TT ></DT ><DD ><P > Dump data as <TT CLASS="COMMAND" >INSERT</TT > commands with explicit column names (<TT CLASS="LITERAL" >INSERT INTO <TT CLASS="REPLACEABLE" ><I >table</I ></TT > (<TT CLASS="REPLACEABLE" ><I >column</I ></TT >, ...) VALUES ...</TT >). This will make restoration very slow; it is mainly useful for making dumps that can be loaded into non-<SPAN CLASS="PRODUCTNAME" >PostgreSQL</SPAN > databases. Also, since this option generates a separate command for each row, an error in reloading a row causes only that row to be lost rather than the entire table contents. </P ></DD ><DT ><TT CLASS="OPTION" >-E <TT CLASS="REPLACEABLE" ><I >encoding</I ></TT ></TT ><BR><TT CLASS="OPTION" >--encoding=<TT CLASS="REPLACEABLE" ><I >encoding</I ></TT ></TT ></DT ><DD ><P > 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 <TT CLASS="ENVAR" >PGCLIENTENCODING</TT > environment variable to the desired dump encoding.) </P ></DD ><DT ><TT CLASS="OPTION" >-f <TT CLASS="REPLACEABLE" ><I >file</I ></TT ></TT ><BR><TT CLASS="OPTION" >--file=<TT CLASS="REPLACEABLE" ><I >file</I ></TT ></TT ></DT ><DD ><P > Send output to the specified file. If this is omitted, the standard output is used. </P ></DD ><DT ><TT CLASS="OPTION" >-F <TT CLASS="REPLACEABLE" ><I >format</I ></TT ></TT ><BR><TT CLASS="OPTION" >--format=<TT CLASS="REPLACEABLE" ><I >format</I ></TT ></TT ></DT ><DD ><P > Selects the format of the output. <TT CLASS="REPLACEABLE" ><I >format</I ></TT > can be one of the following: <P ></P ></P><DIV CLASS="VARIABLELIST" ><DL ><DT ><TT CLASS="LITERAL" >p</TT ><BR><TT CLASS="LITERAL" >plain</TT ></DT ><DD ><P > Output a plain-text <ACRONYM CLASS="ACRONYM" >SQL</ACRONYM > script file (the default). </P ></DD ><DT ><TT CLASS="LITERAL" >c</TT ><BR><TT CLASS="LITERAL" >custom</TT ></DT ><DD ><P > Output a custom archive suitable for input into <SPAN CLASS="APPLICATION" >pg_restore</SPAN >. This is the most flexible format in that it allows reordering of loading data as well as object definitions. This format is also compressed by default. </P ></DD ><DT ><TT CLASS="LITERAL" >t</TT ><BR><TT CLASS="LITERAL" >tar</TT ></DT ><DD ><P > Output a <TT CLASS="COMMAND" >tar</TT > archive suitable for input into <SPAN CLASS="APPLICATION" >pg_restore</SPAN >. Using this archive format allows reordering and/or exclusion of database objects at the time the database is restored. It is also possible to limit which data is reloaded at restore time. </P ></DD ></DL ></DIV ><P> </P ></DD ><DT ><TT CLASS="OPTION" >-i</TT ><BR><TT CLASS="OPTION" >--ignore-version</TT ></DT ><DD ><P > Ignore version mismatch between <SPAN CLASS="APPLICATION" >pg_dump</SPAN > and the database server. </P ><P > <SPAN CLASS="APPLICATION" >pg_dump</SPAN > can dump from servers running previous releases of <SPAN CLASS="PRODUCTNAME" >PostgreSQL</SPAN >, but very old versions are not supported anymore (currently, those prior to 7.0). Dumping from a server newer than <SPAN CLASS="APPLICATION" >pg_dump</SPAN > is likely not to work at all. Use this option if you need to override the version check (and if <SPAN CLASS="APPLICATION" >pg_dump</SPAN > then fails, don't say you weren't warned). </P ></DD ><DT ><TT CLASS="OPTION" >-n <TT CLASS="REPLACEABLE" ><I >schema</I ></TT ></TT ><BR><TT CLASS="OPTION" >--schema=<TT CLASS="REPLACEABLE" ><I >schema</I ></TT ></TT ></DT ><DD ><P > Dump only schemas matching <TT CLASS="REPLACEABLE" ><I >schema</I ></TT >; 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 <TT CLASS="OPTION" >-n</TT > switches. Also, the <TT CLASS="REPLACEABLE" ><I >schema</I ></TT > parameter is interpreted as a pattern according to the same rules used by <SPAN CLASS="APPLICATION" >psql</SPAN >'s <TT CLASS="LITERAL" >\d</TT > commands (see <A HREF="app-psql.html#APP-PSQL-PATTERNS" ><I >Patterns</I ></A >), 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. </P ><DIV CLASS="NOTE" ><BLOCKQUOTE CLASS="NOTE" ><P ><B >Note: </B > When <TT CLASS="OPTION" >-n</TT > is specified, <SPAN CLASS="APPLICATION" >pg_dump</SPAN > 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. </P ></BLOCKQUOTE ></DIV ><DIV CLASS="NOTE" ><BLOCKQUOTE CLASS="NOTE" ><P ><B >Note: </B > Non-schema objects such as blobs are not dumped when <TT CLASS="OPTION" >-n</TT > is specified. You can add blobs back to the dump with the <TT CLASS="OPTION" >--blobs</TT > switch. </P ></BLOCKQUOTE ></DIV ></DD ><DT ><TT CLASS="OPTION" >-N <TT CLASS="REPLACEABLE" ><I >schema</I ></TT ></TT ><BR><TT CLASS="OPTION" >--exclude-schema=<TT CLASS="REPLACEABLE" ><I >schema</I ></TT ></TT ></DT ><DD ><P > Do not dump any schemas matching the <TT CLASS="REPLACEABLE" ><I >schema</I ></TT > pattern. The pattern is interpreted according to the same rules as for <TT CLASS="OPTION" >-n</TT >. <TT CLASS="OPTION" >-N</TT > can be given more than once to exclude schemas matching any of several patterns. </P ><P > When both <TT CLASS="OPTION" >-n</TT > and <TT CLASS="OPTION" >-N</TT > are given, the behavior is to dump just the schemas that match at least one <TT CLASS="OPTION" >-n</TT > switch but no <TT CLASS="OPTION" >-N</TT > switches. If <TT CLASS="OPTION" >-N</TT > appears without <TT CLASS="OPTION" >-n</TT >, then schemas matching <TT CLASS="OPTION" >-N</TT > are excluded from what is otherwise a normal dump. </P ></DD ><DT ><TT CLASS="OPTION" >-o</TT ><BR><TT CLASS="OPTION" >--oids</TT ></DT ><DD ><P > Dump object identifiers (<ACRONYM CLASS="ACRONYM" >OID</ACRONYM >s) as part of the data for every table. Use this option if your application references the <ACRONYM CLASS="ACRONYM" >OID</ACRONYM > columns in some way (e.g., in a foreign key constraint). Otherwise, this option should not be used. </P ></DD ><DT ><TT CLASS="OPTION" >-O</TT ><BR><TT CLASS="OPTION" >--no-owner</TT ></DT ><DD ><P > Do not output commands to set ownership of objects to match the original database. By default, <SPAN CLASS="APPLICATION" >pg_dump</SPAN > issues <TT CLASS="COMMAND" >ALTER OWNER</TT > or <TT CLASS="COMMAND" >SET SESSION AUTHORIZATION</TT > 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 <TT CLASS="OPTION" >-O</TT >. </P ><P > This option is only meaningful for the plain-text format. For the archive formats, you can specify the option when you call <TT CLASS="COMMAND" >pg_restore</TT >. </P ></DD ><DT ><TT CLASS="OPTION" >-R</TT ><BR><TT CLASS="OPTION" >--no-reconnect</TT ></DT ><DD ><P > This option is obsolete but still accepted for backwards compatibility. </P ></DD ><DT ><TT CLASS="OPTION" >-s</TT ><BR><TT CLASS="OPTION" >--schema-only</TT ></DT ><DD ><P > Dump only the object definitions (schema), not data. </P ></DD ><DT ><TT CLASS="OPTION" >-S <TT CLASS="REPLACEABLE" ><I >username</I ></TT ></TT ><BR><TT CLASS="OPTION" >--superuser=<TT CLASS="REPLACEABLE" ><I >username</I ></TT ></TT ></DT ><DD ><P > Specify the superuser user name to use when disabling triggers. This is only relevant if <TT CLASS="OPTION" >--disable-triggers</TT > is used. (Usually, it's better to leave this out, and instead start the resulting script as superuser.) </P ></DD ><DT ><TT CLASS="OPTION" >-t <TT CLASS="REPLACEABLE" ><I >table</I ></TT ></TT ><BR><TT CLASS="OPTION" >--table=<TT CLASS="REPLACEABLE" ><I >table</I ></TT ></TT ></DT ><DD ><P > Dump only tables (or views or sequences) matching <TT CLASS="REPLACEABLE" ><I >table</I ></TT >. Multiple tables can be selected by writing multiple <TT CLASS="OPTION" >-t</TT > switches. Also, the <TT CLASS="REPLACEABLE" ><I >table</I ></TT > parameter is interpreted as a pattern according to the same rules used by <SPAN CLASS="APPLICATION" >psql</SPAN >'s <TT CLASS="LITERAL" >\d</TT > commands (see <A HREF="app-psql.html#APP-PSQL-PATTERNS" ><I >Patterns</I ></A >), 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. </P ><P > The <TT CLASS="OPTION" >-n</TT > and <TT CLASS="OPTION" >-N</TT > switches have no effect when <TT CLASS="OPTION" >-t</TT > is used, because tables selected by <TT CLASS="OPTION" >-t</TT > will be dumped regardless of those switches, and non-table objects will not be dumped. </P ><DIV CLASS="NOTE" ><BLOCKQUOTE CLASS="NOTE" ><P ><B >Note: </B > When <TT CLASS="OPTION" >-t</TT > is specified, <SPAN CLASS="APPLICATION" >pg_dump</SPAN > 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. </P ></BLOCKQUOTE ></DIV ><DIV CLASS="NOTE" ><BLOCKQUOTE CLASS="NOTE" ><P ><B >Note: </B > The behavior of the <TT CLASS="OPTION" >-t</TT > switch is not entirely upward compatible with pre-8.2 <SPAN CLASS="PRODUCTNAME" >PostgreSQL</SPAN > versions. Formerly, writing <TT CLASS="LITERAL" >-t tab</TT > would dump all tables named <TT CLASS="LITERAL" >tab</TT >, but now it just dumps whichever one is visible in your default search path. To get the old behavior you can write <TT CLASS="LITERAL" >-t '*.tab'</TT >. Also, you must write something like <TT CLASS="LITERAL" >-t sch.tab</TT > to select a table in a particular schema, rather than the old locution of <TT CLASS="LITERAL" >-n sch -t tab</TT >. </P ></BLOCKQUOTE ></DIV ></DD ><DT ><TT CLASS="OPTION" >-T <TT CLASS="REPLACEABLE" ><I >table</I ></TT ></TT ><BR><TT CLASS="OPTION" >--exclude-table=<TT CLASS="REPLACEABLE" ><I >table</I ></TT ></TT ></DT ><DD ><P > Do not dump any tables matching the <TT CLASS="REPLACEABLE" ><I >table</I ></TT > pattern. The pattern is interpreted according to the same rules as for <TT CLASS="OPTION" >-t</TT >. <TT CLASS="OPTION" >-T</TT > can be given more than once to exclude tables matching any of several patterns. </P ><P > When both <TT CLASS="OPTION" >-t</TT > and <TT CLASS="OPTION" >-T</TT > are given, the behavior is to dump just the tables that match at least one <TT CLASS="OPTION" >-t</TT > switch but no <TT CLASS="OPTION" >-T</TT > switches. If <TT CLASS="OPTION" >-T</TT > appears without <TT CLASS="OPTION" >-t</TT >, then tables matching <TT CLASS="OPTION" >-T</TT > are excluded from what is otherwise a normal dump. </P ></DD ><DT ><TT CLASS="OPTION" >-v</TT ><BR><TT CLASS="OPTION" >--verbose</TT ></DT ><DD ><P > Specifies verbose mode. This will cause <SPAN CLASS="APPLICATION" >pg_dump</SPAN > to output detailed object comments and start/stop times to the dump file, and progress messages to standard error. </P ></DD ><DT ><TT CLASS="OPTION" >-x</TT ><BR><TT CLASS="OPTION" >--no-privileges</TT ><BR><TT CLASS="OPTION" >--no-acl</TT ></DT ><DD ><P > Prevent dumping of access privileges (grant/revoke commands). </P ></DD ><DT ><TT CLASS="OPTION" >--disable-dollar-quoting</TT ></DT ><DD ><P > This option disables the use of dollar quoting for function bodies, and forces them to be quoted using SQL standard string syntax. </P ></DD ><DT ><TT CLASS="OPTION" >--disable-triggers</TT ></DT ><DD ><P > This option is only relevant when creating a data-only dump. It instructs <SPAN CLASS="APPLICATION" >pg_dump</SPAN > to include commands to temporarily disable triggers on the target tables while the data is reloaded. Use this if you have referential integrity checks or other triggers on the tables that you do not want to invoke during data reload. </P ><P > Presently, the commands emitted for <TT CLASS="OPTION" >--disable-triggers</TT > must be done as superuser. So, you should also specify a superuser name with <TT CLASS="OPTION" >-S</TT >, or preferably be careful to start the resulting script as a superuser. </P ><P > This option is only meaningful for the plain-text format. For the archive formats, you can specify the option when you call <TT CLASS="COMMAND" >pg_restore</TT >. </P ></DD ><DT ><TT CLASS="OPTION" >--use-set-session-authorization</TT ></DT ><DD ><P > Output SQL-standard <TT CLASS="COMMAND" >SET SESSION AUTHORIZATION</TT > commands instead of <TT CLASS="COMMAND" >ALTER OWNER</TT > 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 <TT CLASS="COMMAND" >SET SESSION AUTHORIZATION</TT > will certainly require superuser privileges to restore correctly, whereas <TT CLASS="COMMAND" >ALTER OWNER</TT > requires lesser privileges. </P ></DD ><DT ><TT CLASS="OPTION" >-Z <TT CLASS="REPLACEABLE" ><I >0..9</I ></TT ></TT ><BR><TT CLASS="OPTION" >--compress=<TT CLASS="REPLACEABLE" ><I >0..9</I ></TT ></TT ></DT ><DD ><P > Specify the compression level to use. Zero means no compression. For the custom archive format, this specifies compression of individual table-data segments, and the default is to compress 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 <SPAN CLASS="APPLICATION" >gzip</SPAN >; but the default is not to compress. The tar archive format currently does not support compression at all. </P ></DD ></DL ></DIV ><P> </P ><P > The following command-line options control the database connection parameters. <P ></P ></P><DIV CLASS="VARIABLELIST" ><DL ><DT ><TT CLASS="OPTION" >-h <TT CLASS="REPLACEABLE" ><I >host</I ></TT ></TT ><BR><TT CLASS="OPTION" >--host=<TT CLASS="REPLACEABLE" ><I >host</I ></TT ></TT ></DT ><DD ><P > 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 <TT CLASS="ENVAR" >PGHOST</TT > environment variable, if set, else a Unix domain socket connection is attempted. </P ></DD ><DT ><TT CLASS="OPTION" >-p <TT CLASS="REPLACEABLE" ><I >port</I ></TT ></TT ><BR><TT CLASS="OPTION" >--port=<TT CLASS="REPLACEABLE" ><I >port</I ></TT ></TT ></DT ><DD ><P > Specifies the TCP port or local Unix domain socket file extension on which the server is listening for connections. Defaults to the <TT CLASS="ENVAR" >PGPORT</TT > environment variable, if set, or a compiled-in default. </P ></DD ><DT ><TT CLASS="OPTION" >-U <TT CLASS="REPLACEABLE" ><I >username</I ></TT ></TT ><BR><TT CLASS="OPTION" >--username=<TT CLASS="REPLACEABLE" ><I >username</I ></TT ></TT ></DT ><DD ><P > User name to connect as. </P ></DD ><DT ><TT CLASS="OPTION" >-W</TT ><BR><TT CLASS="OPTION" >--password</TT ></DT ><DD ><P > Force <SPAN CLASS="APPLICATION" >pg_dump</SPAN > to prompt for a password before connecting to a database. </P ><P > This option is never essential, since <SPAN CLASS="APPLICATION" >pg_dump</SPAN > will automatically prompt for a password if the server demands password authentication. However, <SPAN CLASS="APPLICATION" >pg_dump</SPAN > will waste a connection attempt finding out that the server wants a password. In some cases it is worth typing <TT CLASS="OPTION" >-W</TT > to avoid the extra connection attempt. </P ></DD ></DL ></DIV ><P> </P ></DIV ><DIV CLASS="REFSECT1" ><A NAME="AEN63338" ></A ><H2 >Environment</H2 ><P ></P ><DIV CLASS="VARIABLELIST" ><DL ><DT ><TT CLASS="ENVAR" >PGDATABASE</TT ><BR><TT CLASS="ENVAR" >PGHOST</TT ><BR><TT CLASS="ENVAR" >PGPORT</TT ><BR><TT CLASS="ENVAR" >PGUSER</TT ></DT ><DD ><P > Default connection parameters. </P ></DD ></DL ></DIV ><P > This utility, like most other <SPAN CLASS="PRODUCTNAME" >PostgreSQL</SPAN > utilities, also uses the environment variables supported by <SPAN CLASS="APPLICATION" >libpq</SPAN > (see <A HREF="libpq-envars.html" >Section 30.12</A >). </P ></DIV ><DIV CLASS="REFSECT1" ><A NAME="APP-PGDUMP-DIAGNOSTICS" ></A ><H2 >Diagnostics</H2 ><P > <SPAN CLASS="APPLICATION" >pg_dump</SPAN > internally executes <TT CLASS="COMMAND" >SELECT</TT > statements. If you have problems running <SPAN CLASS="APPLICATION" >pg_dump</SPAN >, make sure you are able to select information from the database using, for example, <A HREF="app-psql.html" ><SPAN CLASS="APPLICATION" >psql</SPAN ></A >. Also, any default connection settings and environment variables used by the <SPAN CLASS="APPLICATION" >libpq</SPAN > front-end library will apply. </P ></DIV ><DIV CLASS="REFSECT1" ><A NAME="PG-DUMP-NOTES" ></A ><H2 >Notes</H2 ><P > If your database cluster has any local additions to the <TT CLASS="LITERAL" >template1</TT > database, be careful to restore the output of <SPAN CLASS="APPLICATION" >pg_dump</SPAN > 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 <TT CLASS="LITERAL" >template0</TT > not <TT CLASS="LITERAL" >template1</TT >, for example: </P><PRE CLASS="PROGRAMLISTING" >CREATE DATABASE foo WITH TEMPLATE template0;</PRE ><P> </P ><P > <SPAN CLASS="APPLICATION" >pg_dump</SPAN > has a limitation; when a data-only dump is chosen and the option <TT CLASS="OPTION" >--disable-triggers</TT > is used, <SPAN CLASS="APPLICATION" >pg_dump</SPAN > emits commands to disable triggers on user tables before inserting the data and 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. </P ><P > Members of tar archives are limited to a size less than 8 GB. (This is an inherent limitation of the tar file format.) Therefore this format cannot be used if the textual representation of any one table exceeds that size. The total size of a tar archive and any of the other output formats is not limited, except possibly by the operating system. </P ><P > The dump file produced by <SPAN CLASS="APPLICATION" >pg_dump</SPAN > does not contain the statistics used by the optimizer to make query planning decisions. Therefore, it is wise to run <TT CLASS="COMMAND" >ANALYZE</TT > after restoring from a dump file to ensure good performance. The dump file also does not contain any <TT CLASS="COMMAND" >ALTER DATABASE ... SET</TT > commands; these settings are dumped by <A HREF="app-pg-dumpall.html" ><SPAN CLASS="APPLICATION" >pg_dumpall</SPAN ></A >, along with database users and other installation-wide settings. </P ><P > Because <SPAN CLASS="APPLICATION" >pg_dump</SPAN > is used to transfer data to newer versions of <SPAN CLASS="PRODUCTNAME" >PostgreSQL</SPAN >, the output of <SPAN CLASS="APPLICATION" >pg_dump</SPAN > can be loaded into newer <SPAN CLASS="PRODUCTNAME" >PostgreSQL</SPAN > databases. It also can read older <SPAN CLASS="PRODUCTNAME" >PostgreSQL</SPAN > databases. However, it usually cannot read newer <SPAN CLASS="PRODUCTNAME" >PostgreSQL</SPAN > databases or produce dump output that can be loaded into older database versions. To do this, manual editing of the dump file might be required. </P ></DIV ><DIV CLASS="REFSECT1" ><A NAME="PG-DUMP-EXAMPLES" ></A ><H2 >Examples</H2 ><P > To dump a database called <TT CLASS="LITERAL" >mydb</TT > into a SQL-script file: </P><PRE CLASS="SCREEN" ><SAMP CLASS="PROMPT" >$</SAMP > <KBD CLASS="USERINPUT" >pg_dump mydb > db.sql</KBD ></PRE ><P> </P ><P > To reload such a script into a (freshly created) database named <TT CLASS="LITERAL" >newdb</TT >: </P><PRE CLASS="SCREEN" ><SAMP CLASS="PROMPT" >$</SAMP > <KBD CLASS="USERINPUT" >psql -d newdb -f db.sql</KBD ></PRE ><P> </P ><P > To dump a database into a custom-format archive file: </P><PRE CLASS="SCREEN" ><SAMP CLASS="PROMPT" >$</SAMP > <KBD CLASS="USERINPUT" >pg_dump -Fc mydb > db.dump</KBD ></PRE ><P> </P ><P > To reload an archive file into a (freshly created) database named <TT CLASS="LITERAL" >newdb</TT >: </P><PRE CLASS="SCREEN" ><SAMP CLASS="PROMPT" >$</SAMP > <KBD CLASS="USERINPUT" >pg_restore -d newdb db.dump</KBD ></PRE ><P> </P ><P > To dump a single table named <TT CLASS="LITERAL" >mytab</TT >: </P><PRE CLASS="SCREEN" ><SAMP CLASS="PROMPT" >$</SAMP > <KBD CLASS="USERINPUT" >pg_dump -t mytab mydb > db.sql</KBD ></PRE ><P> </P ><P > To dump all tables whose names start with <TT CLASS="LITERAL" >emp</TT > in the <TT CLASS="LITERAL" >detroit</TT > schema, except for the table named <TT CLASS="LITERAL" >employee_log</TT >: </P><PRE CLASS="SCREEN" ><SAMP CLASS="PROMPT" >$</SAMP > <KBD CLASS="USERINPUT" >pg_dump -t 'detroit.emp*' -T detroit.employee_log mydb > db.sql</KBD ></PRE ><P> </P ><P > To dump all schemas whose names start with <TT CLASS="LITERAL" >east</TT > or <TT CLASS="LITERAL" >west</TT > and end in <TT CLASS="LITERAL" >gsm</TT >, excluding any schemas whose names contain the word <TT CLASS="LITERAL" >test</TT >: </P><PRE CLASS="SCREEN" ><SAMP CLASS="PROMPT" >$</SAMP > <KBD CLASS="USERINPUT" >pg_dump -n 'east*gsm' -n 'west*gsm' -N '*test*' mydb > db.sql</KBD ></PRE ><P> </P ><P > The same, using regular expression notation to consolidate the switches: </P><PRE CLASS="SCREEN" ><SAMP CLASS="PROMPT" >$</SAMP > <KBD CLASS="USERINPUT" >pg_dump -n '(east|west)*gsm' -N '*test*' mydb > db.sql</KBD ></PRE ><P> </P ><P > To dump all database objects except for tables whose names begin with <TT CLASS="LITERAL" >ts_</TT >: </P><PRE CLASS="SCREEN" ><SAMP CLASS="PROMPT" >$</SAMP > <KBD CLASS="USERINPUT" >pg_dump -T 'ts_*' mydb > db.sql</KBD ></PRE ><P> </P ><P > To specify an upper-case or mixed-case name in <TT CLASS="OPTION" >-t</TT > and related switches, you need to double-quote the name; else it will be folded to lower case (see <A HREF="app-psql.html#APP-PSQL-PATTERNS" ><I >Patterns</I ></A >). 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 </P><PRE CLASS="SCREEN" ><SAMP CLASS="PROMPT" >$</SAMP > <KBD CLASS="USERINPUT" >pg_dump -t '"MixedCaseName"' mydb > mytab.sql</KBD ></PRE ><P> </P ></DIV ><DIV CLASS="REFSECT1" ><A NAME="AEN63445" ></A ><H2 >See Also</H2 ><A HREF="app-pg-dumpall.html" ><SPAN CLASS="APPLICATION" >pg_dumpall</SPAN ></A >, <A HREF="app-pgrestore.html" >pg_restore</A >, <A HREF="app-psql.html" ><SPAN CLASS="APPLICATION" >psql</SPAN ></A ></DIV ><DIV CLASS="NAVFOOTER" ><HR ALIGN="LEFT" WIDTH="100%"><TABLE SUMMARY="Footer navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" ><A HREF="app-pgconfig.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="index.html" ACCESSKEY="H" >Home</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="app-pg-dumpall.html" ACCESSKEY="N" >Next</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >pg_config</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="reference-client.html" ACCESSKEY="U" >Up</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><SPAN CLASS="APPLICATION" >pg_dumpall</SPAN ></TD ></TR ></TABLE ></DIV ></BODY ></HTML >