Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
...
head fork: adunstan/postgresql-dev
Checking mergeability… Don't worry, you can still create the pull request.
  • 3 commits
  • 5 files changed
  • 0 commit comments
  • 1 contributor
View
1  src/bin/pg_dump/pg_backup.h
@@ -119,6 +119,7 @@ typedef struct _restoreOptions
int dropSchema;
char *filename;
int schemaOnly;
+ int dumpSections;
int verbose;
int aclsSkip;
int tocSummary;
View
19 src/bin/pg_dump/pg_backup_archiver.c
@@ -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;
}
@@ -2163,6 +2164,7 @@ ReadToc(ArchiveHandle *AH)
int depIdx;
int depSize;
TocEntry *te;
+ bool in_post_data = false;
AH->tocCount = ReadInt(AH);
AH->maxDumpId = 0;
@@ -2228,6 +2230,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);
@@ -2377,6 +2385,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)
{
View
3  src/bin/pg_dump/pg_backup_archiver.h
@@ -287,6 +287,9 @@ typedef struct _tocEntry
void *dataDumperArg; /* Arg for above routine */
void *formatData; /* TOC Entry data specific to file format */
+ /* in post data? not quite the same as section, might be SECTION_NONE */
+ bool inPostData;
+
/* working state (needed only for parallel restore) */
struct _tocEntry *par_prev; /* list links for pending/ready items; */
struct _tocEntry *par_next; /* these are NULL if not in either list */
View
3  src/bin/pg_dump/pg_dump.c
@@ -14449,7 +14449,8 @@ check_sql_result(PGresult *res, PGconn *conn, const char *query,
exit_nicely();
}
-static void set_section (const char *arg)
+static void
+set_section (const char *arg)
{
/* if this is the first, clear all the bits */
if (dumpSections == DUMP_UNSECTIONED)
View
57 src/bin/pg_dump/pg_restore.c
@@ -61,6 +61,7 @@ extern int optind;
static void usage(const char *progname);
+static void set_section (int *dumpSections, const char *arg);
typedef struct option optType;
@@ -116,6 +117,7 @@ main(int argc, char **argv)
{"no-data-for-failed-tables", no_argument, &no_data_for_failed_tables, 1},
{"no-tablespaces", no_argument, &outputNoTablespaces, 1},
{"role", required_argument, NULL, 2},
+ {"section", required_argument, NULL, 3},
{"use-set-session-authorization", no_argument, &use_setsessauth, 1},
{"no-security-labels", no_argument, &no_security_labels, 1},
@@ -270,6 +272,10 @@ main(int argc, char **argv)
opts->use_role = optarg;
break;
+ case 3: /* section */
+ set_section(&(opts->dumpSections), optarg);
+ break;
+
default:
fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
exit(1);
@@ -292,6 +298,33 @@ main(int argc, char **argv)
exit(1);
}
+ if (opts->dataOnly && opts->schemaOnly)
+ {
+ fprintf(stderr, _("%s: options -s/--schema-only and -a/--data-only cannot be used together\n"),
+ progname);
+ exit(1);
+ }
+
+ if ((opts->dataOnly || opts->schemaOnly) && (opts->dumpSections != DUMP_UNSECTIONED))
+ {
+ fprintf(stderr, _("%s: options -s/--schema-only and -a/--data-only cannot be used with --section\n"),
+ progname);
+ exit(1);
+ }
+
+ if (opts->dataOnly)
+ opts->dumpSections = DUMP_DATA;
+ else if (opts->schemaOnly)
+ opts->dumpSections = DUMP_PRE_DATA | DUMP_POST_DATA;
+ else if ( opts->dumpSections != DUMP_UNSECTIONED)
+ {
+ opts->dataOnly = opts->dumpSections == DUMP_DATA;
+ opts->schemaOnly = !(opts->dumpSections & DUMP_DATA);
+ }
+
+
+ fprintf(stderr,"dumpsection: %d, dataOnly: %d, schemaOnly: %d\n", opts->dumpSections, opts->dataOnly, opts->schemaOnly);
+
/* Should get at most one of -d and -f, else user is confused */
if (opts->dbname)
{
@@ -432,6 +465,7 @@ usage(const char *progname)
" created\n"));
printf(_(" --no-security-labels do not restore security labels\n"));
printf(_(" --no-tablespaces do not restore tablespace assignments\n"));
+ printf(_(" --section=SECTION restore named section (pre-data, data or post-data)\n"));
printf(_(" --use-set-session-authorization\n"
" use SET SESSION AUTHORIZATION commands instead of\n"
" ALTER OWNER commands to set ownership\n"));
@@ -447,3 +481,26 @@ usage(const char *progname)
printf(_("\nIf no input file name is supplied, then standard input is used.\n\n"));
printf(_("Report bugs to <pgsql-bugs@postgresql.org>.\n"));
}
+
+static void
+set_section (int *dumpSections, const char *arg)
+{
+ /* if this is the first, clear all the bits */
+ if (*dumpSections == DUMP_UNSECTIONED)
+ *dumpSections = 0;
+
+ if (strcmp(arg,"pre-data") == 0)
+ *dumpSections |= DUMP_PRE_DATA;
+ else if (strcmp(arg,"data") == 0)
+ *dumpSections |= DUMP_DATA;
+ else if (strcmp(arg,"post-data") == 0)
+ *dumpSections |= DUMP_POST_DATA;
+ else
+ {
+ fprintf(stderr, _("%s: unknown section name \"%s\")\n"),
+ progname, arg);
+ fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
+ progname);
+ exit(1);
+ }
+}

No commit comments for this range

Something went wrong with that request. Please try again.