📄 pg_dump.sgml
字号:
</para> </listitem> </varlistentry> <varlistentry> <term><option>-s</option></term> <term><option>--schema-only</option></term> <listitem> <para> Dump only the schema (data definitions), no data. </para> </listitem> </varlistentry> <varlistentry> <term><option>-S <replaceable class="parameter">username</replaceable></option></term> <term><option>--superuser=<replaceable class="parameter">username</replaceable></option></term> <listitem> <para> Specify the superuser user name to use when disabling triggers. This is only relevant if <option>--disable-triggers</> is used. (Usually, it's better to leave this out, and instead start the resulting script as superuser.) </para> </listitem> </varlistentry> <varlistentry> <term><option>-t <replaceable class="parameter">table</replaceable></option></term> <term><option>--table=<replaceable class="parameter">table</replaceable></option></term> <listitem> <para> Dump data for <replaceable class="parameter">table</replaceable> only. It is possible for there to be multiple tables with the same name in different schemas; if that is the case, all matching tables will be dumped. Specify both <option>--schema</> and <option>--table</> to select just one table. </para> <note> <para> In this mode, <application>pg_dump</application> makes no attempt to dump any other database objects that the selected table may depend upon. Therefore, there is no guarantee that the results of a single-table dump can be successfully restored by themselves into a clean database. </para> </note> </listitem> </varlistentry> <varlistentry> <term><option>-v</></term> <term><option>--verbose</></term> <listitem> <para> Specifies verbose mode. This will cause <application>pg_dump</application> to print progress messages to standard error. </para> </listitem> </varlistentry> <varlistentry> <term><option>-x</></term> <term><option>--no-privileges</></term> <term><option>--no-acl</></term> <listitem> <para> Prevent dumping of access privileges (grant/revoke commands). </para> </listitem> </varlistentry> <varlistentry> <term><option>-X use-set-session-authorization</></term> <term><option>--use-set-session-authorization</></term> <listitem> <para> This option is obsolete but still accepted for backwards compatibility. <application>pg_dump</application> now always behaves in the way formerly selected by this option. </para> </listitem> </varlistentry> <varlistentry> <term><option>-X disable-triggers</></term> <term><option>--disable-triggers</></term> <listitem> <para> This option is only relevant when creating a data-only dump. It instructs <application>pg_dump</application> 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. </para> <para> Presently, the commands emitted for <option>--disable-triggers</> must be done as superuser. So, you should also specify a superuser name with <option>-S</>, or preferably be careful to start the resulting script as a superuser. </para> <para> This option is only meaningful for the plain-text format. For the other formats, you may specify the option when you call <command>pg_restore</command>. </para> </listitem> </varlistentry> <varlistentry> <term><option>-Z <replaceable class="parameter">0..9</replaceable></option></term> <term><option>--compress=<replaceable class="parameter">0..9</replaceable></option></term> <listitem> <para> Specify the compression level to use in archive formats that support compression. (Currently only the custom archive format supports compression.) </para> </listitem> </varlistentry> </variablelist> </para> <para> The following command-line options control the database connection parameters. <variablelist> <varlistentry> <term><option>-h <replaceable class="parameter">host</replaceable></option></term> <term><option>--host=<replaceable class="parameter">host</replaceable></option></term> <listitem> <para> 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 <envar>PGHOST</envar> environment variable, if set, else a Unix domain socket connection is attempted. </para> </listitem> </varlistentry> <varlistentry> <term><option>-p <replaceable class="parameter">port</replaceable></option></term> <term><option>--port=<replaceable class="parameter">port</replaceable></option></term> <listitem> <para> Specifies the TCP port or local Unix domain socket file extension on which the server is listening for connections. Defaults to the <envar>PGPORT</envar> environment variable, if set, or a compiled-in default. </para> </listitem> </varlistentry> <varlistentry> <term><option>-U <replaceable>username</replaceable></option></term> <listitem> <para> Connect as the given user </para> </listitem> </varlistentry> <varlistentry> <term><option>-W</option></term> <listitem> <para> Force a password prompt. This should happen automatically if the server requires password authentication. </para> </listitem> </varlistentry> </variablelist> </para> </refsect1> <refsect1> <title>Environment</title> <variablelist> <varlistentry> <term><envar>PGDATABASE</envar></term> <term><envar>PGHOST</envar></term> <term><envar>PGPORT</envar></term> <term><envar>PGUSER</envar></term> <listitem> <para> Default connection parameters. </para> </listitem> </varlistentry> </variablelist> </refsect1> <refsect1 id="app-pgdump-diagnostics"> <title>Diagnostics</title> <para> <application>pg_dump</application> internally executes <command>SELECT</command> statements. If you have problems running <application>pg_dump</application>, make sure you are able to select information from the database using, for example, <xref linkend="app-psql">. </para> </refsect1> <refsect1 id="pg-dump-notes"> <title>Notes</title> <para> If your database cluster has any local additions to the <literal>template1</> database, be careful to restore the output of <application>pg_dump</application> 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 <literal>template0</> not <literal>template1</>, for example:<programlisting>CREATE DATABASE foo WITH TEMPLATE template0;</programlisting> </para> <para> <application>pg_dump</application> has a few limitations: <itemizedlist> <listitem> <para> When dumping a single table or as plain text, <application>pg_dump</application> does not handle large objects. Large objects must be dumped with the entire database using one of the non-text archive formats. </para> </listitem> <listitem> <para> When a data-only dump is chosen and the option <option>--disable-triggers</> is used, <application>pg_dump</application> 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 may be left in the wrong state. </para> </listitem> </itemizedlist> </para> <para> 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 a 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. </para> <para> Once restored, it is wise to run <command>ANALYZE</> on each restored table so the optimizer has useful statistics. </para> </refsect1> <refsect1 id="pg-dump-examples"> <title>Examples</title> <para> To dump a database:<screen><prompt>$</prompt> <userinput>pg_dump mydb > db.out</userinput></screen> </para> <para> To reload this database:<screen><prompt>$</prompt> <userinput>psql -d database -f db.out</userinput></screen> </para> <para> To dump a database called <literal>mydb</> that contains large objects to a <filename>tar</filename> file:<screen><prompt>$</prompt> <userinput>pg_dump -Ft -b mydb > db.tar</userinput></screen> </para> <para> To reload this database (with large objects) to an existing database called <literal>newdb</>:<screen><prompt>$</prompt> <userinput>pg_restore -d newdb db.tar</userinput></screen> </para> </refsect1> <refsect1> <title>History</title> <para> The <application>pg_dump</application> utility first appeared in <application>Postgres95</application> release 0.02. The non-plain-text output formats were introduced in <productname>PostgreSQL</productname> release 7.1. </para> </refsect1> <refsect1> <title>See Also</title> <simplelist type="inline"> <member><xref linkend="app-pg-dumpall"></member> <member><xref linkend="app-pgrestore"></member> <member><xref linkend="app-psql"></member> </simplelist> </refsect1></refentry><!-- Keep this comment at the end of the fileLocal variables:mode: sgmlsgml-omittag:nilsgml-shorttag:tsgml-minimize-attributes:nilsgml-always-quote-attributes:tsgml-indent-step:1sgml-indent-data:tsgml-parent-document:nilsgml-default-dtd-file:"../reference.ced"sgml-exposed-tags:nilsgml-local-catalogs:"/usr/lib/sgml/catalog"sgml-local-ecat-files:nilEnd:-->
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -