On Mon, 2008-07-21 at 07:56 -0400, Stephen Frost wrote: > Simon, > > * Simon Riggs ([EMAIL PROTECTED]) wrote: > > > I hadn't realized that Simon was using "pre-schema" and "post-schema" > > > to name the first and third parts. I'd agree that this is confusing > > > nomenclature: it looks like it's trying to say that the data is the > > > schema, and the schema is not! How about "pre-data and "post-data"? > > > > OK by me. Any other takers? > > Having the command-line options be "--schema-pre-data" and > "--schema-post-data" is fine with me. Leaving them the way they are is > also fine by me. It's the documentation (back to pg_dump.sgml, > ~774/~797) that starts talking about Pre-Schema and Post-Schema.
OK, Mr.Reviewer, sir: * patch redone using --schema-before-data and --schema-after-data * docs rewritten using short clear descriptions using only the words "before" and "after", like in the option names * all variable names changed * retested So prefixes "pre" and "post" no longer appear anywhere. No latin derived phrases, just good ol' Anglo-Saxon words. -- Simon Riggs www.2ndQuadrant.com PostgreSQL Training, Services and Support
Index: doc/src/sgml/ref/pg_dump.sgml =================================================================== RCS file: /home/sriggs/pg/REPOSITORY/pgsql/doc/src/sgml/ref/pg_dump.sgml,v retrieving revision 1.103 diff -c -r1.103 pg_dump.sgml *** doc/src/sgml/ref/pg_dump.sgml 20 Jul 2008 18:43:30 -0000 1.103 --- doc/src/sgml/ref/pg_dump.sgml 23 Jul 2008 15:26:29 -0000 *************** *** 133,139 **** <para> Include large objects in the dump. This is the default behavior except when <option>--schema</>, <option>--table</>, or ! <option>--schema-only</> is specified, so the <option>-b</> switch is only useful to add large objects to selective dumps. </para> </listitem> --- 133,140 ---- <para> Include large objects in the dump. This is the default behavior except when <option>--schema</>, <option>--table</>, or ! <option>--schema-only</> or <option>--schema-before-data</> or ! <option>--schema-after-data</> is specified, so the <option>-b</> switch is only useful to add large objects to selective dumps. </para> </listitem> *************** *** 426,431 **** --- 427,452 ---- </varlistentry> <varlistentry> + <term><option>--schema-before-data</option></term> + <listitem> + <para> + Dump object definitions (schema) that occur before table data, + using the order produced by a full dump. + </para> + </listitem> + </varlistentry> + + <varlistentry> + <term><option>--schema-after-data</option></term> + <listitem> + <para> + Dump object definitions (schema) that occur after table data, + using the order produced by a full dump. + </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> *************** *** 790,795 **** --- 811,844 ---- </para> <para> + The output of <application>pg_dump</application> can be divided into three parts: + <itemizedlist> + <listitem> + <para> + Before Data - objects output before data, which includes + <command>CREATE TABLE</command> statements and others. + This part can be requested using <option>--schema-before-data</>. + </para> + </listitem> + <listitem> + <para> + Table Data - data can be requested using <option>--data-only</>. + </para> + </listitem> + <listitem> + <para> + After Data - objects output after data, which includes + <command>CREATE INDEX</command> statements and others. + This part can be requested using <option>--schema-after-data</>. + </para> + </listitem> + </itemizedlist> + This allows us to work more easily with large data dump files when + there is some need to edit commands or resequence their execution for + performance. + </para> + + <para> Because <application>pg_dump</application> is used to transfer data to newer versions of <productname>PostgreSQL</>, the output of <application>pg_dump</application> can be loaded into Index: doc/src/sgml/ref/pg_restore.sgml =================================================================== RCS file: /home/sriggs/pg/REPOSITORY/pgsql/doc/src/sgml/ref/pg_restore.sgml,v retrieving revision 1.75 diff -c -r1.75 pg_restore.sgml *** doc/src/sgml/ref/pg_restore.sgml 13 Apr 2008 03:49:21 -0000 1.75 --- doc/src/sgml/ref/pg_restore.sgml 23 Jul 2008 16:00:29 -0000 *************** *** 321,326 **** --- 321,346 ---- </varlistentry> <varlistentry> + <term><option>--schema-before-data</option></term> + <listitem> + <para> + Restore object definitions (schema) that occur before table data, + using the order produced by a full restore. + </para> + </listitem> + </varlistentry> + + <varlistentry> + <term><option>--schema-after-data</option></term> + <listitem> + <para> + Restore object definitions (schema) that occur after table data, + using the order produced by a full restore. + </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> *************** *** 572,577 **** --- 592,626 ---- </para> <para> + The actions of <application>pg_restore</application> can be + divided into three parts: + <itemizedlist> + <listitem> + <para> + Before Data - objects output before data, which includes + <command>CREATE TABLE</command> statements and others. + This part can be requested using <option>--schema-before-data</>. + </para> + </listitem> + <listitem> + <para> + Table Data - data can be requested using <option>--data-only</>. + </para> + </listitem> + <listitem> + <para> + After Data - objects output after data, which includes + <command>CREATE INDEX</command> statements and others. + This part can be requested using <option>--schema-after-data</>. + </para> + </listitem> + </itemizedlist> + This allows us to work more easily with large data dump files when + there is some need to edit commands or resequence their execution for + performance. + </para> + + <para> The limitations of <application>pg_restore</application> are detailed below. <itemizedlist> Index: src/bin/pg_dump/pg_backup.h =================================================================== RCS file: /home/sriggs/pg/REPOSITORY/pgsql/src/bin/pg_dump/pg_backup.h,v retrieving revision 1.47 diff -c -r1.47 pg_backup.h *** src/bin/pg_dump/pg_backup.h 13 Apr 2008 03:49:21 -0000 1.47 --- src/bin/pg_dump/pg_backup.h 23 Jul 2008 14:33:32 -0000 *************** *** 89,95 **** int use_setsessauth;/* Use SET SESSION AUTHORIZATION commands * instead of OWNER TO */ char *superuser; /* Username to use as superuser */ ! int dataOnly; int dropSchema; char *filename; int schemaOnly; --- 89,95 ---- int use_setsessauth;/* Use SET SESSION AUTHORIZATION commands * instead of OWNER TO */ char *superuser; /* Username to use as superuser */ ! int dumpObjFlags; /* which objects types to dump */ int dropSchema; char *filename; int schemaOnly; Index: src/bin/pg_dump/pg_backup_archiver.c =================================================================== RCS file: /home/sriggs/pg/REPOSITORY/pgsql/src/bin/pg_dump/pg_backup_archiver.c,v retrieving revision 1.157 diff -c -r1.157 pg_backup_archiver.c *** src/bin/pg_dump/pg_backup_archiver.c 4 May 2008 08:32:21 -0000 1.157 --- src/bin/pg_dump/pg_backup_archiver.c 23 Jul 2008 16:12:47 -0000 *************** *** 56,62 **** static void _selectTablespace(ArchiveHandle *AH, const char *tablespace); static void processEncodingEntry(ArchiveHandle *AH, TocEntry *te); static void processStdStringsEntry(ArchiveHandle *AH, TocEntry *te); ! static teReqs _tocEntryRequired(TocEntry *te, RestoreOptions *ropt, bool include_acls); static void _disableTriggersIfNecessary(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt); static void _enableTriggersIfNecessary(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt); static TocEntry *getTocEntryByDumpId(ArchiveHandle *AH, DumpId id); --- 56,62 ---- static void _selectTablespace(ArchiveHandle *AH, const char *tablespace); static void processEncodingEntry(ArchiveHandle *AH, TocEntry *te); static void processStdStringsEntry(ArchiveHandle *AH, TocEntry *te); ! static int _tocEntryRequired(TocEntry *te, RestoreOptions *ropt, bool include_acls); static void _disableTriggersIfNecessary(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt); static void _enableTriggersIfNecessary(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt); static TocEntry *getTocEntryByDumpId(ArchiveHandle *AH, DumpId id); *************** *** 129,135 **** { ArchiveHandle *AH = (ArchiveHandle *) AHX; TocEntry *te; ! teReqs reqs; OutputContext sav; bool defnDumped; --- 129,135 ---- { ArchiveHandle *AH = (ArchiveHandle *) AHX; TocEntry *te; ! int reqs; OutputContext sav; bool defnDumped; *************** *** 175,193 **** * Work out if we have an implied data-only restore. This can happen if * the dump was data only or if the user has used a toc list to exclude * all of the schema data. All we do is look for schema entries - if none ! * are found then we set the dataOnly flag. * ! * We could scan for wanted TABLE entries, but that is not the same as ! * dataOnly. At this stage, it seems unnecessary (6-Mar-2001). */ ! if (!ropt->dataOnly) { int impliedDataOnly = 1; for (te = AH->toc->next; te != AH->toc; te = te->next) { reqs = _tocEntryRequired(te, ropt, true); ! if ((reqs & REQ_SCHEMA) != 0) { /* It's schema, and it's wanted */ impliedDataOnly = 0; break; --- 175,193 ---- * Work out if we have an implied data-only restore. This can happen if * the dump was data only or if the user has used a toc list to exclude * all of the schema data. All we do is look for schema entries - if none ! * are found then say we only want DATA type objects. * ! * We could scan for wanted TABLE entries, but that is not the same. ! * At this stage, it seems unnecessary (6-Mar-2001). */ ! if (!WANT_DATA(ropt->dumpObjFlags)) { int impliedDataOnly = 1; for (te = AH->toc->next; te != AH->toc; te = te->next) { reqs = _tocEntryRequired(te, ropt, true); ! if (WANT_PRE_SCHEMA(reqs) || WANT_POST_SCHEMA(reqs)) { /* It's schema, and it's wanted */ impliedDataOnly = 0; break; *************** *** 195,201 **** } if (impliedDataOnly) { ! ropt->dataOnly = impliedDataOnly; ahlog(AH, 1, "implied data-only restore\n"); } } --- 195,201 ---- } if (impliedDataOnly) { ! ropt->dumpObjFlags = REQ_DATA; ahlog(AH, 1, "implied data-only restore\n"); } } *************** *** 236,242 **** AH->currentTE = te; reqs = _tocEntryRequired(te, ropt, false /* needn't drop ACLs */ ); ! if (((reqs & REQ_SCHEMA) != 0) && te->dropStmt) { /* We want the schema */ ahlog(AH, 1, "dropping %s %s\n", te->desc, te->tag); --- 236,242 ---- AH->currentTE = te; reqs = _tocEntryRequired(te, ropt, false /* needn't drop ACLs */ ); ! if (((reqs & REQ_SCHEMA_BEFORE_DATA) != 0) && te->dropStmt) { /* We want the schema */ ahlog(AH, 1, "dropping %s %s\n", te->desc, te->tag); *************** *** 278,284 **** /* Dump any relevant dump warnings to stderr */ if (!ropt->suppressDumpWarnings && strcmp(te->desc, "WARNING") == 0) { ! if (!ropt->dataOnly && te->defn != NULL && strlen(te->defn) != 0) write_msg(modulename, "warning from original dump file: %s\n", te->defn); else if (te->copyStmt != NULL && strlen(te->copyStmt) != 0) write_msg(modulename, "warning from original dump file: %s\n", te->copyStmt); --- 278,284 ---- /* Dump any relevant dump warnings to stderr */ if (!ropt->suppressDumpWarnings && strcmp(te->desc, "WARNING") == 0) { ! if (!WANT_DATA(ropt->dumpObjFlags) && te->defn != NULL && strlen(te->defn) != 0) write_msg(modulename, "warning from original dump file: %s\n", te->defn); else if (te->copyStmt != NULL && strlen(te->copyStmt) != 0) write_msg(modulename, "warning from original dump file: %s\n", te->copyStmt); *************** *** 286,292 **** defnDumped = false; ! if ((reqs & REQ_SCHEMA) != 0) /* We want the schema */ { ahlog(AH, 1, "creating %s %s\n", te->desc, te->tag); --- 286,293 ---- defnDumped = false; ! if ((WANT_PRE_SCHEMA(reqs) && WANT_PRE_SCHEMA(ropt->dumpObjFlags)) || ! (WANT_POST_SCHEMA(reqs) && WANT_POST_SCHEMA(ropt->dumpObjFlags))) /* We want the schema */ { ahlog(AH, 1, "creating %s %s\n", te->desc, te->tag); *************** *** 331,337 **** /* * If we have a data component, then process it */ ! if ((reqs & REQ_DATA) != 0) { /* * hadDumper will be set if there is genuine data component for --- 332,338 ---- /* * If we have a data component, then process it */ ! if (WANT_DATA(reqs)) { /* * hadDumper will be set if there is genuine data component for *************** *** 343,349 **** /* * If we can output the data, then restore it. */ ! if (AH->PrintTocDataPtr !=NULL && (reqs & REQ_DATA) != 0) { #ifndef HAVE_LIBZ if (AH->compression != 0) --- 344,350 ---- /* * If we can output the data, then restore it. */ ! if (AH->PrintTocDataPtr !=NULL && WANT_DATA(reqs)) { #ifndef HAVE_LIBZ if (AH->compression != 0) *************** *** 415,421 **** /* Work out what, if anything, we want from this entry */ reqs = _tocEntryRequired(te, ropt, true); ! if ((reqs & REQ_SCHEMA) != 0) /* We want the schema */ { ahlog(AH, 1, "setting owner and privileges for %s %s\n", te->desc, te->tag); --- 416,422 ---- /* Work out what, if anything, we want from this entry */ reqs = _tocEntryRequired(te, ropt, true); ! if (WANT_PRE_SCHEMA(reqs)) /* We want the schema */ { ahlog(AH, 1, "setting owner and privileges for %s %s\n", te->desc, te->tag); *************** *** 473,479 **** _disableTriggersIfNecessary(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt) { /* This hack is only needed in a data-only restore */ ! if (!ropt->dataOnly || !ropt->disable_triggers) return; ahlog(AH, 1, "disabling triggers for %s\n", te->tag); --- 474,480 ---- _disableTriggersIfNecessary(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt) { /* This hack is only needed in a data-only restore */ ! if (!WANT_DATA(ropt->dumpObjFlags) || !ropt->disable_triggers) return; ahlog(AH, 1, "disabling triggers for %s\n", te->tag); *************** *** 499,505 **** _enableTriggersIfNecessary(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt) { /* This hack is only needed in a data-only restore */ ! if (!ropt->dataOnly || !ropt->disable_triggers) return; ahlog(AH, 1, "enabling triggers for %s\n", te->tag); --- 500,506 ---- _enableTriggersIfNecessary(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt) { /* This hack is only needed in a data-only restore */ ! if (!WANT_DATA(ropt->dumpObjFlags) || !ropt->disable_triggers) return; ahlog(AH, 1, "enabling triggers for %s\n", te->tag); *************** *** 1321,1327 **** return NULL; } ! teReqs TocIDRequired(ArchiveHandle *AH, DumpId id, RestoreOptions *ropt) { TocEntry *te = getTocEntryByDumpId(AH, id); --- 1322,1328 ---- return NULL; } ! int TocIDRequired(ArchiveHandle *AH, DumpId id, RestoreOptions *ropt) { TocEntry *te = getTocEntryByDumpId(AH, id); *************** *** 2026,2035 **** te->defn); } ! static teReqs _tocEntryRequired(TocEntry *te, RestoreOptions *ropt, bool include_acls) { ! teReqs res = REQ_ALL; /* ENCODING and STDSTRINGS items are dumped specially, so always reject */ if (strcmp(te->desc, "ENCODING") == 0 || --- 2027,2036 ---- te->defn); } ! static int _tocEntryRequired(TocEntry *te, RestoreOptions *ropt, bool include_acls) { ! int res = ropt->dumpObjFlags; /* ENCODING and STDSTRINGS items are dumped specially, so always reject */ if (strcmp(te->desc, "ENCODING") == 0 || *************** *** 2109,2125 **** if ((strcmp(te->desc, "<Init>") == 0) && (strcmp(te->tag, "Max OID") == 0)) return 0; - /* Mask it if we only want schema */ - if (ropt->schemaOnly) - res = res & REQ_SCHEMA; - - /* Mask it we only want data */ - if (ropt->dataOnly) - res = res & REQ_DATA; - /* Mask it if we don't have a schema contribution */ if (!te->defn || strlen(te->defn) == 0) ! res = res & ~REQ_SCHEMA; /* Finally, if there's a per-ID filter, limit based on that as well */ if (ropt->idWanted && !ropt->idWanted[te->dumpId - 1]) --- 2110,2118 ---- if ((strcmp(te->desc, "<Init>") == 0) && (strcmp(te->tag, "Max OID") == 0)) return 0; /* Mask it if we don't have a schema contribution */ if (!te->defn || strlen(te->defn) == 0) ! res = res & ~(REQ_SCHEMA_BEFORE_DATA | REQ_SCHEMA_AFTER_DATA); /* Finally, if there's a per-ID filter, limit based on that as well */ if (ropt->idWanted && !ropt->idWanted[te->dumpId - 1]) Index: src/bin/pg_dump/pg_backup_archiver.h =================================================================== RCS file: /home/sriggs/pg/REPOSITORY/pgsql/src/bin/pg_dump/pg_backup_archiver.h,v retrieving revision 1.76 diff -c -r1.76 pg_backup_archiver.h *** src/bin/pg_dump/pg_backup_archiver.h 7 Nov 2007 12:24:24 -0000 1.76 --- src/bin/pg_dump/pg_backup_archiver.h 23 Jul 2008 16:13:23 -0000 *************** *** 158,169 **** STAGE_FINALIZING } ArchiverStage; ! typedef enum ! { ! REQ_SCHEMA = 1, ! REQ_DATA = 2, ! REQ_ALL = REQ_SCHEMA + REQ_DATA ! } teReqs; typedef struct _archiveHandle { --- 158,173 ---- STAGE_FINALIZING } ArchiverStage; ! #define REQ_SCHEMA_BEFORE_DATA (1 << 0) ! #define REQ_DATA (1 << 1) ! #define REQ_SCHEMA_AFTER_DATA (1 << 2) ! #define REQ_ALL (REQ_SCHEMA_BEFORE_DATA + REQ_DATA + REQ_SCHEMA_AFTER_DATA) ! ! #define WANT_PRE_SCHEMA(req) ((req & REQ_SCHEMA_BEFORE_DATA) == REQ_SCHEMA_BEFORE_DATA) ! #define WANT_DATA(req) ((req & REQ_DATA) == REQ_DATA) ! #define WANT_POST_SCHEMA(req) ((req & REQ_SCHEMA_AFTER_DATA) == REQ_SCHEMA_AFTER_DATA) ! #define WANT_ALL(req) ((req & REQ_ALL) == REQ_ALL) ! typedef struct _archiveHandle { *************** *** 317,323 **** extern void ReadToc(ArchiveHandle *AH); extern void WriteDataChunks(ArchiveHandle *AH); ! extern teReqs TocIDRequired(ArchiveHandle *AH, DumpId id, RestoreOptions *ropt); extern bool checkSeek(FILE *fp); #define appendStringLiteralAHX(buf,str,AH) \ --- 321,327 ---- extern void ReadToc(ArchiveHandle *AH); extern void WriteDataChunks(ArchiveHandle *AH); ! extern int TocIDRequired(ArchiveHandle *AH, DumpId id, RestoreOptions *ropt); extern bool checkSeek(FILE *fp); #define appendStringLiteralAHX(buf,str,AH) \ Index: src/bin/pg_dump/pg_dump.c =================================================================== RCS file: /home/sriggs/pg/REPOSITORY/pgsql/src/bin/pg_dump/pg_dump.c,v retrieving revision 1.497 diff -c -r1.497 pg_dump.c *** src/bin/pg_dump/pg_dump.c 20 Jul 2008 18:43:30 -0000 1.497 --- src/bin/pg_dump/pg_dump.c 23 Jul 2008 16:33:08 -0000 *************** *** 73,78 **** --- 73,82 ---- bool aclsSkip; const char *lockWaitTimeout; + /* groups of objects: default is we dump all groups */ + + int dumpObjFlags; + /* subquery used to convert user ID (eg, datdba) to user name */ static const char *username_subquery; *************** *** 225,232 **** RestoreOptions *ropt; static int disable_triggers = 0; ! static int outputNoTablespaces = 0; static int use_setsessauth = 0; static struct option long_options[] = { {"data-only", no_argument, NULL, 'a'}, --- 229,238 ---- RestoreOptions *ropt; static int disable_triggers = 0; ! static int outputNoTablespaces = 0; static int use_setsessauth = 0; + static int use_schemaBeforeData; + static int use_schemaAfterData; static struct option long_options[] = { {"data-only", no_argument, NULL, 'a'}, *************** *** 267,272 **** --- 273,280 ---- {"disable-triggers", no_argument, &disable_triggers, 1}, {"lock-wait-timeout", required_argument, NULL, 2}, {"no-tablespaces", no_argument, &outputNoTablespaces, 1}, + {"schema-before-data", no_argument, &use_schemaBeforeData, 1}, + {"schema-after-data", no_argument, &use_schemaAfterData, 1}, {"use-set-session-authorization", no_argument, &use_setsessauth, 1}, {NULL, 0, NULL, 0} *************** *** 464,474 **** if (optind < argc) dbname = argv[optind]; ! if (dataOnly && schemaOnly) { ! write_msg(NULL, "options -s/--schema-only and -a/--data-only cannot be used together\n"); exit(1); } if (dataOnly && outputClean) { --- 472,517 ---- if (optind < argc) dbname = argv[optind]; ! /* ! * Look for conflicting options relating to object groupings ! */ ! if (schemaOnly && dataOnly) ! { ! write_msg(NULL, "options %s and %s cannot be used together\n", ! "-s/--schema-only", "-a/--data-only"); ! exit(1); ! } ! else if ((schemaOnly || dataOnly) && ! (use_schemaBeforeData == 1 || use_schemaAfterData == 1)) { ! write_msg(NULL, "options %s and %s cannot be used together\n", ! schemaOnly ? "-s/--schema-only" : "-a/--data-only", ! use_schemaBeforeData == 1 ? "--schema-before-data" : "--schema-after-data"); exit(1); } + else if (use_schemaBeforeData == 1 && use_schemaAfterData == 1) + { + write_msg(NULL, "options %s and %s cannot be used together\n", + "--schema-before-data", "--schema-after-data"); + exit(1); + } + + /* + * Decide which of the object groups we will dump + */ + dumpObjFlags = REQ_ALL; + + if (dataOnly) + dumpObjFlags = REQ_DATA; + + if (use_schemaBeforeData == 1) + dumpObjFlags = REQ_SCHEMA_BEFORE_DATA; + + if (use_schemaAfterData == 1) + dumpObjFlags = REQ_SCHEMA_AFTER_DATA; + + if (schemaOnly) + dumpObjFlags = (REQ_SCHEMA_BEFORE_DATA | REQ_SCHEMA_AFTER_DATA); if (dataOnly && outputClean) { *************** *** 646,652 **** * Dumping blobs is now default unless we saw an inclusion switch or -s * ... but even if we did see one of these, -b turns it back on. */ ! if (include_everything && !schemaOnly) outputBlobs = true; /* --- 689,695 ---- * Dumping blobs is now default unless we saw an inclusion switch or -s * ... but even if we did see one of these, -b turns it back on. */ ! if (include_everything && WANT_PRE_SCHEMA(dumpObjFlags)) outputBlobs = true; /* *************** *** 658,664 **** if (g_fout->remoteVersion < 80400) guessConstraintInheritance(tblinfo, numTables); ! if (!schemaOnly) getTableData(tblinfo, numTables, oids); if (outputBlobs && hasBlobs(g_fout)) --- 701,707 ---- if (g_fout->remoteVersion < 80400) guessConstraintInheritance(tblinfo, numTables); ! if (WANT_DATA(dumpObjFlags)) getTableData(tblinfo, numTables, oids); if (outputBlobs && hasBlobs(g_fout)) *************** *** 712,718 **** dumpStdStrings(g_fout); /* The database item is always next, unless we don't want it at all */ ! if (include_everything && !dataOnly) dumpDatabase(g_fout); /* Now the rearrangeable objects. */ --- 755,761 ---- dumpStdStrings(g_fout); /* The database item is always next, unless we don't want it at all */ ! if (include_everything && WANT_DATA(dumpObjFlags)) dumpDatabase(g_fout); /* Now the rearrangeable objects. */ *************** *** 734,740 **** ropt->noTablespace = outputNoTablespaces; ropt->disable_triggers = disable_triggers; ropt->use_setsessauth = use_setsessauth; ! ropt->dataOnly = dataOnly; if (compressLevel == -1) ropt->compression = 0; --- 777,783 ---- ropt->noTablespace = outputNoTablespaces; ropt->disable_triggers = disable_triggers; ropt->use_setsessauth = use_setsessauth; ! ropt->dumpObjFlags = dumpObjFlags; if (compressLevel == -1) ropt->compression = 0; *************** *** 3414,3420 **** continue; /* Ignore indexes of tables not to be dumped */ ! if (!tbinfo->dobj.dump) continue; if (g_verbose) --- 3457,3463 ---- continue; /* Ignore indexes of tables not to be dumped */ ! if (!tbinfo->dobj.dump || !WANT_POST_SCHEMA(dumpObjFlags)) continue; if (g_verbose) *************** *** 5165,5171 **** int ncomments; /* Comments are SCHEMA not data */ ! if (dataOnly) return; /* Search for comments associated with catalogId, using table */ --- 5208,5214 ---- int ncomments; /* Comments are SCHEMA not data */ ! if (!WANT_PRE_SCHEMA(dumpObjFlags)) return; /* Search for comments associated with catalogId, using table */ *************** *** 5216,5222 **** PQExpBuffer target; /* Comments are SCHEMA not data */ ! if (dataOnly) return; /* Search for comments associated with relation, using table */ --- 5259,5265 ---- PQExpBuffer target; /* Comments are SCHEMA not data */ ! if (!WANT_PRE_SCHEMA(dumpObjFlags)) return; /* Search for comments associated with relation, using table */ *************** *** 5568,5574 **** char *qnspname; /* Skip if not to be dumped */ ! if (!nspinfo->dobj.dump || dataOnly) return; /* don't dump dummy namespace from pre-7.3 source */ --- 5611,5617 ---- char *qnspname; /* Skip if not to be dumped */ ! if (!nspinfo->dobj.dump || !WANT_PRE_SCHEMA(dumpObjFlags)) return; /* don't dump dummy namespace from pre-7.3 source */ *************** *** 5617,5623 **** dumpType(Archive *fout, TypeInfo *tinfo) { /* Skip if not to be dumped */ ! if (!tinfo->dobj.dump || dataOnly) return; /* Dump out in proper style */ --- 5660,5666 ---- dumpType(Archive *fout, TypeInfo *tinfo) { /* Skip if not to be dumped */ ! if (!tinfo->dobj.dump || !WANT_PRE_SCHEMA(dumpObjFlags)) return; /* Dump out in proper style */ *************** *** 6262,6268 **** PQExpBuffer q; /* Skip if not to be dumped */ ! if (!stinfo->dobj.dump || dataOnly) return; q = createPQExpBuffer(); --- 6305,6311 ---- PQExpBuffer q; /* Skip if not to be dumped */ ! if (!stinfo->dobj.dump || !WANT_PRE_SCHEMA(dumpObjFlags)) return; q = createPQExpBuffer(); *************** *** 6309,6315 **** if (!include_everything) return false; /* And they're schema not data */ ! if (dataOnly) return false; return true; } --- 6352,6358 ---- if (!include_everything) return false; /* And they're schema not data */ ! if (!WANT_PRE_SCHEMA(dumpObjFlags)) return false; return true; } *************** *** 6330,6336 **** FuncInfo *funcInfo; FuncInfo *validatorInfo = NULL; ! if (dataOnly) return; /* --- 6373,6379 ---- FuncInfo *funcInfo; FuncInfo *validatorInfo = NULL; ! if (!WANT_PRE_SCHEMA(dumpObjFlags)) return; /* *************** *** 6590,6596 **** int i; /* Skip if not to be dumped */ ! if (!finfo->dobj.dump || dataOnly) return; query = createPQExpBuffer(); --- 6633,6639 ---- int i; /* Skip if not to be dumped */ ! if (!finfo->dobj.dump || !WANT_PRE_SCHEMA(dumpObjFlags)) return; query = createPQExpBuffer(); *************** *** 6985,6991 **** TypeInfo *sourceInfo; TypeInfo *targetInfo; ! if (dataOnly) return; if (OidIsValid(cast->castfunc)) --- 7028,7034 ---- TypeInfo *sourceInfo; TypeInfo *targetInfo; ! if (!WANT_PRE_SCHEMA(dumpObjFlags)) return; if (OidIsValid(cast->castfunc)) *************** *** 7135,7141 **** char *oprcanhash; /* Skip if not to be dumped */ ! if (!oprinfo->dobj.dump || dataOnly) return; /* --- 7178,7184 ---- char *oprcanhash; /* Skip if not to be dumped */ ! if (!oprinfo->dobj.dump || !WANT_PRE_SCHEMA(dumpObjFlags)) return; /* *************** *** 7519,7525 **** int i; /* Skip if not to be dumped */ ! if (!opcinfo->dobj.dump || dataOnly) return; /* --- 7562,7568 ---- int i; /* Skip if not to be dumped */ ! if (!opcinfo->dobj.dump || !WANT_PRE_SCHEMA(dumpObjFlags)) return; /* *************** *** 7827,7833 **** int i; /* Skip if not to be dumped */ ! if (!opfinfo->dobj.dump || dataOnly) return; /* --- 7870,7876 ---- int i; /* Skip if not to be dumped */ ! if (!opfinfo->dobj.dump || !WANT_PRE_SCHEMA(dumpObjFlags)) return; /* *************** *** 8096,8102 **** bool condefault; /* Skip if not to be dumped */ ! if (!convinfo->dobj.dump || dataOnly) return; query = createPQExpBuffer(); --- 8139,8145 ---- bool condefault; /* Skip if not to be dumped */ ! if (!convinfo->dobj.dump || !WANT_PRE_SCHEMA(dumpObjFlags)) return; query = createPQExpBuffer(); *************** *** 8250,8256 **** bool convertok; /* Skip if not to be dumped */ ! if (!agginfo->aggfn.dobj.dump || dataOnly) return; query = createPQExpBuffer(); --- 8293,8299 ---- bool convertok; /* Skip if not to be dumped */ ! if (!agginfo->aggfn.dobj.dump || !WANT_PRE_SCHEMA(dumpObjFlags)) return; query = createPQExpBuffer(); *************** *** 8453,8459 **** PQExpBuffer delq; /* Skip if not to be dumped */ ! if (!prsinfo->dobj.dump || dataOnly) return; q = createPQExpBuffer(); --- 8496,8502 ---- PQExpBuffer delq; /* Skip if not to be dumped */ ! if (!prsinfo->dobj.dump || !WANT_PRE_SCHEMA(dumpObjFlags)) return; q = createPQExpBuffer(); *************** *** 8522,8528 **** char *tmplname; /* Skip if not to be dumped */ ! if (!dictinfo->dobj.dump || dataOnly) return; q = createPQExpBuffer(); --- 8565,8571 ---- char *tmplname; /* Skip if not to be dumped */ ! if (!dictinfo->dobj.dump || !WANT_PRE_SCHEMA(dumpObjFlags)) return; q = createPQExpBuffer(); *************** *** 8607,8613 **** PQExpBuffer delq; /* Skip if not to be dumped */ ! if (!tmplinfo->dobj.dump || dataOnly) return; q = createPQExpBuffer(); --- 8650,8656 ---- PQExpBuffer delq; /* Skip if not to be dumped */ ! if (!tmplinfo->dobj.dump || !WANT_PRE_SCHEMA(dumpObjFlags)) return; q = createPQExpBuffer(); *************** *** 8673,8679 **** int i_dictname; /* Skip if not to be dumped */ ! if (!cfginfo->dobj.dump || dataOnly) return; q = createPQExpBuffer(); --- 8716,8722 ---- int i_dictname; /* Skip if not to be dumped */ ! if (!cfginfo->dobj.dump || !WANT_PRE_SCHEMA(dumpObjFlags)) return; q = createPQExpBuffer(); *************** *** 8809,8815 **** PQExpBuffer sql; /* Do nothing if ACL dump is not enabled */ ! if (dataOnly || aclsSkip) return; sql = createPQExpBuffer(); --- 8852,8858 ---- PQExpBuffer sql; /* Do nothing if ACL dump is not enabled */ ! if (!WANT_PRE_SCHEMA(dumpObjFlags) || aclsSkip) return; sql = createPQExpBuffer(); *************** *** 8846,8852 **** { if (tbinfo->relkind == RELKIND_SEQUENCE) dumpSequence(fout, tbinfo); ! else if (!dataOnly) dumpTableSchema(fout, tbinfo); /* Handle the ACL here */ --- 8889,8895 ---- { if (tbinfo->relkind == RELKIND_SEQUENCE) dumpSequence(fout, tbinfo); ! else if (WANT_PRE_SCHEMA(dumpObjFlags)) dumpTableSchema(fout, tbinfo); /* Handle the ACL here */ *************** *** 9153,9159 **** PQExpBuffer delq; /* Only print it if "separate" mode is selected */ ! if (!tbinfo->dobj.dump || !adinfo->separate || dataOnly) return; /* Don't print inherited defaults, either */ --- 9196,9202 ---- PQExpBuffer delq; /* Only print it if "separate" mode is selected */ ! if (!tbinfo->dobj.dump || !adinfo->separate || !WANT_PRE_SCHEMA(dumpObjFlags)) return; /* Don't print inherited defaults, either */ *************** *** 9238,9244 **** PQExpBuffer q; PQExpBuffer delq; ! if (dataOnly) return; q = createPQExpBuffer(); --- 9281,9287 ---- PQExpBuffer q; PQExpBuffer delq; ! if (!WANT_POST_SCHEMA(dumpObjFlags)) return; q = createPQExpBuffer(); *************** *** 9307,9313 **** PQExpBuffer delq; /* Skip if not to be dumped */ ! if (!coninfo->dobj.dump || dataOnly) return; q = createPQExpBuffer(); --- 9350,9356 ---- PQExpBuffer delq; /* Skip if not to be dumped */ ! if (!coninfo->dobj.dump || !WANT_POST_SCHEMA(dumpObjFlags)) return; q = createPQExpBuffer(); *************** *** 9700,9706 **** * * Add a 'SETVAL(seq, last_val, iscalled)' as part of a "data" dump. */ ! if (!dataOnly) { resetPQExpBuffer(delqry); --- 9743,9749 ---- * * Add a 'SETVAL(seq, last_val, iscalled)' as part of a "data" dump. */ ! if (WANT_PRE_SCHEMA(dumpObjFlags)) { resetPQExpBuffer(delqry); *************** *** 9803,9809 **** tbinfo->dobj.catId, 0, tbinfo->dobj.dumpId); } ! if (!schemaOnly) { resetPQExpBuffer(query); appendPQExpBuffer(query, "SELECT pg_catalog.setval("); --- 9846,9852 ---- tbinfo->dobj.catId, 0, tbinfo->dobj.dumpId); } ! if (WANT_PRE_SCHEMA(dumpObjFlags)) { resetPQExpBuffer(query); appendPQExpBuffer(query, "SELECT pg_catalog.setval("); *************** *** 9836,9842 **** const char *p; int findx; ! if (dataOnly) return; query = createPQExpBuffer(); --- 9879,9885 ---- const char *p; int findx; ! if (!WANT_POST_SCHEMA(dumpObjFlags)) return; query = createPQExpBuffer(); *************** *** 10044,10050 **** PGresult *res; /* Skip if not to be dumped */ ! if (!rinfo->dobj.dump || dataOnly) return; /* --- 10087,10093 ---- PGresult *res; /* Skip if not to be dumped */ ! if (!rinfo->dobj.dump || !WANT_POST_SCHEMA(dumpObjFlags)) return; /* Index: src/bin/pg_dump/pg_restore.c =================================================================== RCS file: /home/sriggs/pg/REPOSITORY/pgsql/src/bin/pg_dump/pg_restore.c,v retrieving revision 1.88 diff -c -r1.88 pg_restore.c *** src/bin/pg_dump/pg_restore.c 13 Apr 2008 03:49:22 -0000 1.88 --- src/bin/pg_dump/pg_restore.c 23 Jul 2008 16:24:48 -0000 *************** *** 78,83 **** --- 78,90 ---- static int no_data_for_failed_tables = 0; static int outputNoTablespaces = 0; static int use_setsessauth = 0; + bool dataOnly = false; + bool schemaOnly = false; + + static int use_schemaBeforeData; + static int use_schemaAfterData; + + int dumpObjFlags; struct option cmdopts[] = { {"clean", 0, NULL, 'c'}, *************** *** 114,119 **** --- 121,128 ---- {"disable-triggers", no_argument, &disable_triggers, 1}, {"no-data-for-failed-tables", no_argument, &no_data_for_failed_tables, 1}, {"no-tablespaces", no_argument, &outputNoTablespaces, 1}, + {"schema-before-data", no_argument, &use_schemaBeforeData, 1}, + {"schema-after-data", no_argument, &use_schemaAfterData, 1}, {"use-set-session-authorization", no_argument, &use_setsessauth, 1}, {NULL, 0, NULL, 0} *************** *** 145,151 **** switch (c) { case 'a': /* Dump data only */ ! opts->dataOnly = 1; break; case 'c': /* clean (i.e., drop) schema prior to create */ opts->dropSchema = 1; --- 154,160 ---- switch (c) { case 'a': /* Dump data only */ ! dataOnly = true; break; case 'c': /* clean (i.e., drop) schema prior to create */ opts->dropSchema = 1; *************** *** 213,219 **** opts->triggerNames = strdup(optarg); break; case 's': /* dump schema only */ ! opts->schemaOnly = 1; break; case 'S': /* Superuser username */ if (strlen(optarg) != 0) --- 222,228 ---- opts->triggerNames = strdup(optarg); break; case 's': /* dump schema only */ ! schemaOnly = true; break; case 'S': /* Superuser username */ if (strlen(optarg) != 0) *************** *** 295,300 **** --- 304,350 ---- opts->useDB = 1; } + /* + * Look for conflicting options relating to object groupings + */ + if (schemaOnly && dataOnly) + { + write_msg(NULL, "options %s and %s cannot be used together\n", + "-s/--schema-only", "-a/--data-only"); + exit(1); + } + else if ((schemaOnly || dataOnly) && + (use_schemaBeforeData == 1 || use_schemaAfterData == 1)) + { + write_msg(NULL, "options %s and %s cannot be used together\n", + schemaOnly ? "-s/--schema-only" : "-a/--data-only", + use_schemaBeforeData == 1 ? "--schema-before-data" : "--schema-after-data"); + exit(1); + } + else if (use_schemaBeforeData == 1 && use_schemaAfterData == 1) + { + write_msg(NULL, "options %s and %s cannot be used together\n", + "--schema-before-data", "--schema-after-data"); + exit(1); + } + + /* + * Decide which of the object groups we will dump + */ + dumpObjFlags = REQ_ALL; + + if (dataOnly) + dumpObjFlags = REQ_DATA; + + if (use_schemaBeforeData == 1) + dumpObjFlags = REQ_SCHEMA_BEFORE_DATA; + + if (use_schemaAfterData == 1) + dumpObjFlags = REQ_SCHEMA_AFTER_DATA; + + if (schemaOnly) + dumpObjFlags = (REQ_SCHEMA_BEFORE_DATA | REQ_SCHEMA_AFTER_DATA); + opts->disable_triggers = disable_triggers; opts->noDataForFailedTables = no_data_for_failed_tables; opts->noTablespace = outputNoTablespaces;
-- Sent via pgsql-patches mailing list (pgsql-patches@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-patches