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

Commit7b070e8

Browse files
committed
Add --exclude-table-data option to pg_dump.
Andrew Dunstan, reviewed by Josh Berkus, Robert Haas and Peter Geoghegan.This allows dumping of a table definition but not its data, on a per table basis.Table name patterns are supported just as for --exclude-table.
1 parent4adead1 commit7b070e8

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,10 @@ PostgreSQL documentation
404404
<para>
405405
Dump only the object definitions (schema), not data.
406406
</para>
407+
<para>
408+
To exclude table data for only a subset of tables in the database,
409+
see <option>--exclude-table-data</>.
410+
</para>
407411
</listitem>
408412
</varlistentry>
409413

@@ -611,6 +615,24 @@ PostgreSQL documentation
611615
</listitem>
612616
</varlistentry>
613617

618+
<varlistentry>
619+
<term><option>--exclude-table-data=<replaceable class="parameter">table</replaceable></option></term>
620+
<listitem>
621+
<para>
622+
Do not dump data for any tables matching the <replaceable
623+
class="parameter">table</replaceable> pattern. The pattern is
624+
interpreted according to the same rules as for <option>-t</>.
625+
<option>--exclude-table-data</> can be given more than once to
626+
exclude tables matching any of several patterns. This option is
627+
useful when you need the definition of a particular table even
628+
though you do not need the data in it.
629+
</para>
630+
<para>
631+
To exclude data for all tables in the database, see <option>--schema-only</>.
632+
<para>
633+
</listitem>
634+
</varlistentry>
635+
614636
<varlistentry>
615637
<term><option>--inserts</option></term>
616638
<listitem>

‎src/bin/pg_dump/pg_dump.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ static SimpleStringList table_include_patterns = {NULL, NULL};
115115
staticSimpleOidListtable_include_oids= {NULL,NULL};
116116
staticSimpleStringListtable_exclude_patterns= {NULL,NULL};
117117
staticSimpleOidListtable_exclude_oids= {NULL,NULL};
118+
staticSimpleStringListtabledata_exclude_patterns= {NULL,NULL};
119+
staticSimpleOidListtabledata_exclude_oids= {NULL,NULL};
118120

119121
/* default, if no "inclusion" switches appear, is to dump everything */
120122
staticboolinclude_everything= true;
@@ -324,6 +326,7 @@ main(int argc, char **argv)
324326
{"column-inserts",no_argument,&column_inserts,1},
325327
{"disable-dollar-quoting",no_argument,&disable_dollar_quoting,1},
326328
{"disable-triggers",no_argument,&disable_triggers,1},
329+
{"exclude-table-data",required_argument,NULL,4},
327330
{"inserts",no_argument,&dump_inserts,1},
328331
{"lock-wait-timeout",required_argument,NULL,2},
329332
{"no-tablespaces",no_argument,&outputNoTablespaces,1},
@@ -487,6 +490,10 @@ main(int argc, char **argv)
487490
use_role=optarg;
488491
break;
489492

493+
case4:/* exclude table(s) data */
494+
simple_string_list_append(&tabledata_exclude_patterns,optarg);
495+
break;
496+
490497
default:
491498
fprintf(stderr,_("Try \"%s --help\" for more information.\n"),progname);
492499
exit(1);
@@ -715,6 +722,10 @@ main(int argc, char **argv)
715722
}
716723
expand_table_name_patterns(&table_exclude_patterns,
717724
&table_exclude_oids);
725+
726+
expand_table_name_patterns(&tabledata_exclude_patterns,
727+
&tabledata_exclude_oids);
728+
718729
/* non-matching exclusion patterns aren't an error */
719730

720731
/*
@@ -854,6 +865,7 @@ help(const char *progname)
854865
printf(_(" --column-inserts dump data as INSERT commands with column names\n"));
855866
printf(_(" --disable-dollar-quoting disable dollar quoting, use SQL standard quoting\n"));
856867
printf(_(" --disable-triggers disable triggers during data-only restore\n"));
868+
printf(_(" --exclude-table-data=TABLE do NOT dump data for the named table(s)\n"));
857869
printf(_(" --inserts dump data as INSERT commands, rather than COPY\n"));
858870
printf(_(" --no-security-labels do not dump security label assignments\n"));
859871
printf(_(" --no-tablespaces do not dump tablespace assignments\n"));
@@ -1087,6 +1099,15 @@ selectDumpableTable(TableInfo *tbinfo)
10871099
simple_oid_list_member(&table_exclude_oids,
10881100
tbinfo->dobj.catId.oid))
10891101
tbinfo->dobj.dump= false;
1102+
1103+
/* If table is to be dumped, check that the data is not excluded */
1104+
if (tbinfo->dobj.dump&& !
1105+
simple_oid_list_member(&tabledata_exclude_oids,
1106+
tbinfo->dobj.catId.oid))
1107+
tbinfo->dobj.dumpdata= true;
1108+
else
1109+
tbinfo->dobj.dumpdata= false;
1110+
10901111
}
10911112

10921113
/*
@@ -1518,6 +1539,10 @@ dumpTableData(Archive *fout, TableDataInfo *tdinfo)
15181539
DataDumperPtrdumpFn;
15191540
char*copyStmt;
15201541

1542+
/* don't do anything if the data isn't wanted */
1543+
if (!tbinfo->dobj.dumpdata)
1544+
return;
1545+
15211546
if (!dump_inserts)
15221547
{
15231548
/* Dump/restore using COPY */

‎src/bin/pg_dump/pg_dump.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ typedef struct _dumpableObject
129129
char*name;/* object name (should never be NULL) */
130130
struct_namespaceInfo*namespace;/* containing namespace, or NULL */
131131
booldump;/* true if we want to dump this object */
132+
booldumpdata;/* true if we want data for this object */
132133
boolext_member;/* true if object is member of extension */
133134
DumpId*dependencies;/* dumpIds of objects this one depends on */
134135
intnDeps;/* number of valid dependencies */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp