Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8977b68

Browse files
committed
Allow multiple -n (schema) and -t (table) pg_dump options, and add -T
and -N options to exclude objects. Also support regular expressions foroption object names.Greg Sabino Mullane
1 parent9a4eaa9 commit8977b68

File tree

4 files changed

+341
-102
lines changed

4 files changed

+341
-102
lines changed

‎doc/src/sgml/ref/pg_dump.sgml

Lines changed: 90 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/ref/pg_dump.sgml,v 1.86 2006/05/13 17:10:35 momjian Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/ref/pg_dump.sgml,v 1.87 2006/08/01 18:05:04 momjian Exp $
33
PostgreSQL documentation
44
-->
55

@@ -398,24 +398,107 @@ PostgreSQL documentation
398398
<listitem>
399399
<para>
400400
Dump data for <replaceable class="parameter">table</replaceable>
401-
only. It is possible for there to be
402-
multiple tables with the same name in different schemas; if that
403-
is the case, all matching tables will be dumped. Specify both
404-
<option>--schema</> and <option>--table</> to select just one table.
401+
only. It is possible for there to be multiple tables with the same
402+
name in different schemas; if that is the case, all matching tables
403+
will be dumped. Also, if any POSIX regular expression character appears
404+
in the table name (<literal>([{\.?+</>, the string will be interpreted
405+
as a regular expression. Note that when in regular expression mode, the
406+
string will not be anchored to the start/end unless <literal>^</> and
407+
<literal>$</> are used at the beginning/end of the string.
405408
</para>
406409

410+
<para>
411+
The options <option>-t</>, <option>-T</>, <option>-n</>, and <option>-N</>
412+
can be used together to achieve a high degree of control over what is
413+
dumped. Multiple arguments can be used, and are parsed in the order
414+
given to build a list of valid tables and schemas. The schema options are
415+
parsed first to create a list of schemas to dump, and then the table options
416+
are parsed to only find tables in the matching schemas.
417+
</para>
418+
419+
<para>For example, to dump a single table named <literal>pg_class</>:
420+
421+
<screen>
422+
<prompt>$</prompt> <userinput>pg_dump -t pg_class mydb &gt; db.out</userinput>
423+
</screen>
424+
</para>
425+
426+
<para>To dump all tables starting with <literal>employee</> in the
427+
<literal>detroit</> schema, except for the table named <literal>employee_log</literal>:
428+
429+
<screen>
430+
<prompt>$</prompt> <userinput>pg_dump -n detroit -t ^employee -T employee_log mydb &gt; db.out</userinput>
431+
</screen>
432+
</para>
433+
434+
<para>To dump all schemas starting with <literal>east</> or <literal>west</> and ending in
435+
<literal>gsm</>, but not schemas that contain the letters <literal>test</>, except for
436+
one named <literal>east_alpha_test_five</>:
437+
438+
<screen>
439+
<prompt>$</prompt> <userinput>pg_dump -n "^(east|west).*gsm$" -N test -n east_alpha_test_five mydb &gt; db.out</userinput>
440+
</screen>
441+
</para>
442+
443+
444+
<para>To dump all tables except for those beginning with <literal>ts_</literal>:
445+
446+
<screen>
447+
<prompt>$</prompt> <userinput>pg_dump -T "^ts_" mydb &gt; db.out</userinput>
448+
</screen>
449+
</para>
450+
451+
407452
<note>
408453
<para>
409454
In this mode, <application>pg_dump</application> makes no
410-
attempt to dump any other database objects that the selectedtable
455+
attempt to dump any other database objects that the selectedtables
411456
may depend upon. Therefore, there is no guarantee
412-
that the results of asingle-table dump can be successfully
457+
that the results of aspecific-table dump can be successfully
413458
restored by themselves into a clean database.
414459
</para>
415460
</note>
416461
</listitem>
417462
</varlistentry>
418463

464+
<varlistentry>
465+
<term><option>-T <replaceable class="parameter">table</replaceable></option></term>
466+
<term><option>--exclude-table=<replaceable class="parameter">table</replaceable></option></term>
467+
<listitem>
468+
<para>
469+
Do not dump any matching <replaceable class="parameter">tables</replaceable>.
470+
More than one option can be used, and POSIX regular expressions are handled just
471+
like <literal>-t</>.
472+
</para>
473+
</listitem>
474+
</varlistentry>
475+
476+
<varlistentry>
477+
<term><option>-n <replaceable class="parameter">schema</replaceable></option></term>
478+
<term><option>--schema=<replaceable class="parameter">schema</replaceable></option></term>
479+
<listitem>
480+
<para>
481+
Dump only the matching <replaceable class="parameter">schemas</replaceable>.
482+
More than one option can be used, and POSIX regular expressions are handled just
483+
like <literal>-t</>.
484+
</para>
485+
486+
</listitem>
487+
</varlistentry>
488+
489+
<varlistentry>
490+
<term><option>-N <replaceable class="parameter">schema</replaceable></option></term>
491+
<term><option>--exclude-schema=<replaceable class="parameter">schema</replaceable></option></term>
492+
<listitem>
493+
<para>
494+
Do not dump the matching <replaceable class="parameter">schemas</replaceable>.
495+
More than one option can be used, and POSIX regular expressions are handled just
496+
like <literal>-t</>.
497+
</para>
498+
499+
</listitem>
500+
</varlistentry>
501+
419502
<varlistentry>
420503
<term><option>-v</></term>
421504
<term><option>--verbose</></term>

‎src/bin/pg_dump/common.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*
1212
*
1313
* IDENTIFICATION
14-
* $PostgreSQL: pgsql/src/bin/pg_dump/common.c,v 1.91 2006/07/14 14:52:26 momjian Exp $
14+
* $PostgreSQL: pgsql/src/bin/pg_dump/common.c,v 1.92 2006/08/01 18:05:04 momjian Exp $
1515
*
1616
*-------------------------------------------------------------------------
1717
*/
@@ -72,9 +72,7 @@ static intstrInArray(const char *pattern, char **arr, int arr_size);
7272
* Collect information about all potentially dumpable objects
7373
*/
7474
TableInfo*
75-
getSchemaData(int*numTablesPtr,
76-
constboolschemaOnly,
77-
constbooldataOnly)
75+
getSchemaData(int*numTablesPtr)
7876
{
7977
NamespaceInfo*nsinfo;
8078
AggInfo*agginfo;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp