1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-23 14:01:44 +03:00

Add --section option to pg_dump and pg_restore.

Valid values are --pre-data, data and post-data. The option can be
given more than once. --schema-only is equivalent to
--section=pre-data --section=post-data. --data-only is equivalent
to --section=data.

Andrew Dunstan, reviewed by Joachim Wieland and Josh Berkus.
This commit is contained in:
Andrew Dunstan
2011-12-16 19:09:38 -05:00
parent 4b43b48c9f
commit a4cd6abcc9
10 changed files with 184 additions and 6 deletions

View File

@ -665,6 +665,7 @@ NewRestoreOptions(void)
/* set any fields that shouldn't default to zeroes */
opts->format = archUnknown;
opts->promptPassword = TRI_DEFAULT;
opts->dumpSections = DUMP_UNSECTIONED;
return opts;
}
@ -2120,6 +2121,7 @@ ReadToc(ArchiveHandle *AH)
int depIdx;
int depSize;
TocEntry *te;
bool in_post_data = false;
AH->tocCount = ReadInt(AH);
AH->maxDumpId = 0;
@ -2185,6 +2187,12 @@ ReadToc(ArchiveHandle *AH)
te->section = SECTION_PRE_DATA;
}
/* will stay true even for SECTION_NONE items */
if (te->section == SECTION_POST_DATA)
in_post_data = true;
te->inPostData = in_post_data;
te->defn = ReadStr(AH);
te->dropStmt = ReadStr(AH);
@ -2334,6 +2342,17 @@ _tocEntryRequired(TocEntry *te, RestoreOptions *ropt, bool include_acls)
if (!ropt->createDB && strcmp(te->desc, "DATABASE") == 0)
return 0;
/* skip (all but) post data section as required */
/* table data is filtered if necessary lower down */
if (ropt->dumpSections != DUMP_UNSECTIONED)
{
if (!(ropt->dumpSections & DUMP_POST_DATA) && te->inPostData)
return 0;
if (!(ropt->dumpSections & DUMP_PRE_DATA) && ! te->inPostData && strcmp(te->desc, "TABLE DATA") != 0)
return 0;
}
/* Check options for selective dump/restore */
if (ropt->schemaNames)
{