On Thu, 2008-07-24 at 03:54 -0400, Tom Lane wrote:
> Simon Riggs <[EMAIL PROTECTED]> writes:
> > [80k patch]
> 
> Surely there is a whole lot of unintended noise in this patch?
> I certainly don't believe that you meant to change keywords.c
> for instance.

Removed, thanks.

Unrelated to this patch, it seems I have some issues with my repository,
judging by this and another unrelated issue reported by Martin Zaun.

-- 
 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	24 Jul 2008 07:30:19 -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	24 Jul 2008 07:30:19 -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	24 Jul 2008 07:30:19 -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	24 Jul 2008 07:30:19 -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_SCHEMA_BEFORE_DATA(reqs) || WANT_SCHEMA_AFTER_DATA(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_SCHEMA_BEFORE_DATA(reqs) && WANT_SCHEMA_BEFORE_DATA(ropt->dumpObjFlags)) ||
! 			(WANT_SCHEMA_AFTER_DATA(reqs) && WANT_SCHEMA_AFTER_DATA(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_SCHEMA_BEFORE_DATA(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	24 Jul 2008 07:30:19 -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_SCHEMA_BEFORE_DATA(req)	((req & REQ_SCHEMA_BEFORE_DATA) == REQ_SCHEMA_BEFORE_DATA)
! #define WANT_DATA(req)					((req & REQ_DATA) == REQ_DATA)
! #define WANT_SCHEMA_AFTER_DATA(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	24 Jul 2008 07:35:28 -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;
  
***************
*** 227,232 ****
--- 231,238 ----
  	static int	disable_triggers = 0;
  	static int  outputNoTablespaces = 0;
  	static int	use_setsessauth = 0;
+ 	static int	schemaBeforeData;
+ 	static int	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, &schemaBeforeData, 1},
+  		{"schema-after-data", no_argument, &schemaAfterData, 1},
  		{"use-set-session-authorization", no_argument, &use_setsessauth, 1},
  
  		{NULL, 0, NULL, 0}
***************
*** 420,425 ****
--- 428,437 ----
  					disable_triggers = 1;
  				else if (strcmp(optarg, "no-tablespaces") == 0)
  					outputNoTablespaces = 1;
+ 				else if (strcmp(optarg, "schema-before-data") == 0)
+ 					schemaBeforeData = 1;
+ 				else if (strcmp(optarg, "schema-after-data") == 0)
+ 					schemaAfterData = 1;
  				else if (strcmp(optarg, "use-set-session-authorization") == 0)
  					use_setsessauth = 1;
  				else
***************
*** 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)
  	{
--- 476,521 ----
  	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) && 
! 				(schemaBeforeData || schemaAfterData))
  	{
! 		write_msg(NULL, "options %s and %s cannot be used together\n",
! 				schemaOnly ? "-s/--schema-only" : "-a/--data-only",
! 				schemaBeforeData ? "--schema-before-data" : "--schema-after-data");
  		exit(1);
  	}
+ 	else if (schemaBeforeData && schemaAfterData)
+ 	{
+ 		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 (schemaBeforeData)
+ 		dumpObjFlags = REQ_SCHEMA_BEFORE_DATA;
+ 
+ 	if (schemaAfterData)
+ 		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;
  
  	/*
--- 693,699 ----
  	 * 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_DATA(dumpObjFlags))
  		outputBlobs = true;
  
  	/*
***************
*** 658,664 ****
  	if (g_fout->remoteVersion < 80400)
  		guessConstraintInheritance(tblinfo, numTables);
  
! 	if (!schemaOnly)
  		getTableData(tblinfo, numTables, oids);
  
  	if (outputBlobs && hasBlobs(g_fout))
--- 705,711 ----
  	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. */
--- 759,765 ----
  	dumpStdStrings(g_fout);
  
  	/* The database item is always next, unless we don't want it at all */
! 	if (include_everything && WANT_SCHEMA_BEFORE_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;
--- 781,787 ----
  		ropt->noTablespace = outputNoTablespaces;
  		ropt->disable_triggers = disable_triggers;
  		ropt->use_setsessauth = use_setsessauth;
! 		ropt->dumpObjFlags = dumpObjFlags;
  
  		if (compressLevel == -1)
  			ropt->compression = 0;
***************
*** 792,797 ****
--- 839,846 ----
  	printf(_("  --disable-dollar-quoting    disable dollar quoting, use SQL standard quoting\n"));
  	printf(_("  --disable-triggers          disable triggers during data-only restore\n"));
  	printf(_("  --no-tablespaces            do not dump tablespace assignments\n"));
+ 	printf(_("  --schema-before-data        dump only the part of schema before table data\n"));
+ 	printf(_("  --schema-after-data         dump only the part of schema after table data\n"));
  	printf(_("  --use-set-session-authorization\n"
  			 "                              use SESSION AUTHORIZATION commands instead of\n"
  	"                              ALTER OWNER commands to set ownership\n"));
***************
*** 5165,5171 ****
  	int			ncomments;
  
  	/* Comments are SCHEMA not data */
! 	if (dataOnly)
  		return;
  
  	/* Search for comments associated with catalogId, using table */
--- 5214,5220 ----
  	int			ncomments;
  
  	/* Comments are SCHEMA not data */
! 	if (!WANT_SCHEMA_BEFORE_DATA(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 */
--- 5265,5271 ----
  	PQExpBuffer target;
  
  	/* Comments are SCHEMA not data */
! 	if (!WANT_SCHEMA_BEFORE_DATA(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 */
--- 5617,5623 ----
  	char	   *qnspname;
  
  	/* Skip if not to be dumped */
! 	if (!nspinfo->dobj.dump || !WANT_SCHEMA_BEFORE_DATA(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 */
--- 5666,5672 ----
  dumpType(Archive *fout, TypeInfo *tinfo)
  {
  	/* Skip if not to be dumped */
! 	if (!tinfo->dobj.dump || !WANT_SCHEMA_BEFORE_DATA(dumpObjFlags))
  		return;
  
  	/* Dump out in proper style */
***************
*** 5646,5651 ****
--- 5695,5704 ----
  				i;
  	char	   *label;
  
+ 	/* Skip if not to be dumped */
+ 	if (!tinfo->dobj.dump || !WANT_SCHEMA_BEFORE_DATA(dumpObjFlags))
+ 		return;
+ 
  	/* Set proper schema search path so regproc references list correctly */
  	selectSourceSchema(tinfo->dobj.namespace->dobj.name);
  
***************
*** 6262,6268 ****
  	PQExpBuffer q;
  
  	/* Skip if not to be dumped */
! 	if (!stinfo->dobj.dump || dataOnly)
  		return;
  
  	q = createPQExpBuffer();
--- 6315,6321 ----
  	PQExpBuffer q;
  
  	/* Skip if not to be dumped */
! 	if (!stinfo->dobj.dump || !WANT_SCHEMA_BEFORE_DATA(dumpObjFlags))
  		return;
  
  	q = createPQExpBuffer();
***************
*** 6309,6315 ****
  	if (!include_everything)
  		return false;
  	/* And they're schema not data */
! 	if (dataOnly)
  		return false;
  	return true;
  }
--- 6362,6368 ----
  	if (!include_everything)
  		return false;
  	/* And they're schema not data */
! 	if (!WANT_SCHEMA_BEFORE_DATA(dumpObjFlags))
  		return false;
  	return true;
  }
***************
*** 6330,6336 ****
  	FuncInfo   *funcInfo;
  	FuncInfo   *validatorInfo = NULL;
  
! 	if (dataOnly)
  		return;
  
  	/*
--- 6383,6389 ----
  	FuncInfo   *funcInfo;
  	FuncInfo   *validatorInfo = NULL;
  
! 	if (!WANT_SCHEMA_BEFORE_DATA(dumpObjFlags))
  		return;
  
  	/*
***************
*** 6590,6596 ****
  	int			i;
  
  	/* Skip if not to be dumped */
! 	if (!finfo->dobj.dump || dataOnly)
  		return;
  
  	query = createPQExpBuffer();
--- 6643,6649 ----
  	int			i;
  
  	/* Skip if not to be dumped */
! 	if (!finfo->dobj.dump || !WANT_SCHEMA_BEFORE_DATA(dumpObjFlags))
  		return;
  
  	query = createPQExpBuffer();
***************
*** 6985,6991 ****
  	TypeInfo   *sourceInfo;
  	TypeInfo   *targetInfo;
  
! 	if (dataOnly)
  		return;
  
  	if (OidIsValid(cast->castfunc))
--- 7038,7044 ----
  	TypeInfo   *sourceInfo;
  	TypeInfo   *targetInfo;
  
! 	if (!WANT_SCHEMA_BEFORE_DATA(dumpObjFlags))
  		return;
  
  	if (OidIsValid(cast->castfunc))
***************
*** 7135,7141 ****
  	char	   *oprcanhash;
  
  	/* Skip if not to be dumped */
! 	if (!oprinfo->dobj.dump || dataOnly)
  		return;
  
  	/*
--- 7188,7194 ----
  	char	   *oprcanhash;
  
  	/* Skip if not to be dumped */
! 	if (!oprinfo->dobj.dump || !WANT_SCHEMA_BEFORE_DATA(dumpObjFlags))
  		return;
  
  	/*
***************
*** 7519,7525 ****
  	int			i;
  
  	/* Skip if not to be dumped */
! 	if (!opcinfo->dobj.dump || dataOnly)
  		return;
  
  	/*
--- 7572,7578 ----
  	int			i;
  
  	/* Skip if not to be dumped */
! 	if (!opcinfo->dobj.dump || !WANT_SCHEMA_BEFORE_DATA(dumpObjFlags))
  		return;
  
  	/*
***************
*** 7827,7833 ****
  	int			i;
  
  	/* Skip if not to be dumped */
! 	if (!opfinfo->dobj.dump || dataOnly)
  		return;
  
  	/*
--- 7880,7886 ----
  	int			i;
  
  	/* Skip if not to be dumped */
! 	if (!opfinfo->dobj.dump || !WANT_SCHEMA_BEFORE_DATA(dumpObjFlags))
  		return;
  
  	/*
***************
*** 8096,8102 ****
  	bool		condefault;
  
  	/* Skip if not to be dumped */
! 	if (!convinfo->dobj.dump || dataOnly)
  		return;
  
  	query = createPQExpBuffer();
--- 8149,8155 ----
  	bool		condefault;
  
  	/* Skip if not to be dumped */
! 	if (!convinfo->dobj.dump || !WANT_SCHEMA_BEFORE_DATA(dumpObjFlags))
  		return;
  
  	query = createPQExpBuffer();
***************
*** 8250,8256 ****
  	bool		convertok;
  
  	/* Skip if not to be dumped */
! 	if (!agginfo->aggfn.dobj.dump || dataOnly)
  		return;
  
  	query = createPQExpBuffer();
--- 8303,8309 ----
  	bool		convertok;
  
  	/* Skip if not to be dumped */
! 	if (!agginfo->aggfn.dobj.dump || !WANT_SCHEMA_BEFORE_DATA(dumpObjFlags))
  		return;
  
  	query = createPQExpBuffer();
***************
*** 8453,8459 ****
  	PQExpBuffer delq;
  
  	/* Skip if not to be dumped */
! 	if (!prsinfo->dobj.dump || dataOnly)
  		return;
  
  	q = createPQExpBuffer();
--- 8506,8512 ----
  	PQExpBuffer delq;
  
  	/* Skip if not to be dumped */
! 	if (!prsinfo->dobj.dump || !WANT_SCHEMA_BEFORE_DATA(dumpObjFlags))
  		return;
  
  	q = createPQExpBuffer();
***************
*** 8522,8528 ****
  	char	   *tmplname;
  
  	/* Skip if not to be dumped */
! 	if (!dictinfo->dobj.dump || dataOnly)
  		return;
  
  	q = createPQExpBuffer();
--- 8575,8581 ----
  	char	   *tmplname;
  
  	/* Skip if not to be dumped */
! 	if (!dictinfo->dobj.dump || !WANT_SCHEMA_BEFORE_DATA(dumpObjFlags))
  		return;
  
  	q = createPQExpBuffer();
***************
*** 8607,8613 ****
  	PQExpBuffer delq;
  
  	/* Skip if not to be dumped */
! 	if (!tmplinfo->dobj.dump || dataOnly)
  		return;
  
  	q = createPQExpBuffer();
--- 8660,8666 ----
  	PQExpBuffer delq;
  
  	/* Skip if not to be dumped */
! 	if (!tmplinfo->dobj.dump || !WANT_SCHEMA_BEFORE_DATA(dumpObjFlags))
  		return;
  
  	q = createPQExpBuffer();
***************
*** 8673,8679 ****
  	int			i_dictname;
  
  	/* Skip if not to be dumped */
! 	if (!cfginfo->dobj.dump || dataOnly)
  		return;
  
  	q = createPQExpBuffer();
--- 8726,8732 ----
  	int			i_dictname;
  
  	/* Skip if not to be dumped */
! 	if (!cfginfo->dobj.dump || !WANT_SCHEMA_BEFORE_DATA(dumpObjFlags))
  		return;
  
  	q = createPQExpBuffer();
***************
*** 8809,8815 ****
  	PQExpBuffer sql;
  
  	/* Do nothing if ACL dump is not enabled */
! 	if (dataOnly || aclsSkip)
  		return;
  
  	sql = createPQExpBuffer();
--- 8862,8868 ----
  	PQExpBuffer sql;
  
  	/* Do nothing if ACL dump is not enabled */
! 	if (!WANT_SCHEMA_BEFORE_DATA(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 */
--- 8899,8905 ----
  	{
  		if (tbinfo->relkind == RELKIND_SEQUENCE)
  			dumpSequence(fout, tbinfo);
! 		else if (WANT_SCHEMA_BEFORE_DATA(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 */
--- 9206,9212 ----
  	PQExpBuffer delq;
  
  	/* Only print it if "separate" mode is selected */
! 	if (!tbinfo->dobj.dump || !adinfo->separate || !WANT_SCHEMA_BEFORE_DATA(dumpObjFlags))
  		return;
  
  	/* Don't print inherited defaults, either */
***************
*** 9238,9244 ****
  	PQExpBuffer q;
  	PQExpBuffer delq;
  
! 	if (dataOnly)
  		return;
  
  	q = createPQExpBuffer();
--- 9291,9297 ----
  	PQExpBuffer q;
  	PQExpBuffer delq;
  
! 	if (!WANT_SCHEMA_AFTER_DATA(dumpObjFlags))
  		return;
  
  	q = createPQExpBuffer();
***************
*** 9307,9313 ****
  	PQExpBuffer delq;
  
  	/* Skip if not to be dumped */
! 	if (!coninfo->dobj.dump || dataOnly)
  		return;
  
  	q = createPQExpBuffer();
--- 9360,9366 ----
  	PQExpBuffer delq;
  
  	/* Skip if not to be dumped */
! 	if (!coninfo->dobj.dump || !WANT_SCHEMA_AFTER_DATA(dumpObjFlags))
  		return;
  
  	q = createPQExpBuffer();
***************
*** 9700,9706 ****
  	 *
  	 * Add a 'SETVAL(seq, last_val, iscalled)' as part of a "data" dump.
  	 */
! 	if (!dataOnly)
  	{
  		resetPQExpBuffer(delqry);
  
--- 9753,9759 ----
  	 *
  	 * Add a 'SETVAL(seq, last_val, iscalled)' as part of a "data" dump.
  	 */
! 	if (WANT_SCHEMA_BEFORE_DATA(dumpObjFlags))
  	{
  		resetPQExpBuffer(delqry);
  
***************
*** 9803,9809 ****
  					tbinfo->dobj.catId, 0, tbinfo->dobj.dumpId);
  	}
  
! 	if (!schemaOnly)
  	{
  		resetPQExpBuffer(query);
  		appendPQExpBuffer(query, "SELECT pg_catalog.setval(");
--- 9856,9862 ----
  					tbinfo->dobj.catId, 0, tbinfo->dobj.dumpId);
  	}
  
! 	if (WANT_DATA(dumpObjFlags))
  	{
  		resetPQExpBuffer(query);
  		appendPQExpBuffer(query, "SELECT pg_catalog.setval(");
***************
*** 9836,9842 ****
  	const char *p;
  	int			findx;
  
! 	if (dataOnly)
  		return;
  
  	query = createPQExpBuffer();
--- 9889,9895 ----
  	const char *p;
  	int			findx;
  
! 	if (!WANT_SCHEMA_AFTER_DATA(dumpObjFlags))
  		return;
  
  	query = createPQExpBuffer();
***************
*** 10044,10050 ****
  	PGresult   *res;
  
  	/* Skip if not to be dumped */
! 	if (!rinfo->dobj.dump || dataOnly)
  		return;
  
  	/*
--- 10097,10103 ----
  	PGresult   *res;
  
  	/* Skip if not to be dumped */
! 	if (!rinfo->dobj.dump || !WANT_SCHEMA_AFTER_DATA(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	24 Jul 2008 07:30:19 -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	schemaBeforeData;
+  	static int	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, &schemaBeforeData, 1},
+  		{"schema-after-data", no_argument, &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)
***************
*** 249,254 ****
--- 258,267 ----
  					no_data_for_failed_tables = 1;
  				else if (strcmp(optarg, "no-tablespaces") == 0)
  					outputNoTablespaces = 1;
+ 				else if (strcmp(optarg, "schema-before-data") == 0)
+ 					schemaBeforeData = 1;
+ 				else if (strcmp(optarg, "schema-after-data") == 0)
+ 					schemaAfterData = 1;
  				else if (strcmp(optarg, "use-set-session-authorization") == 0)
  					use_setsessauth = 1;
  				else
***************
*** 295,300 ****
--- 308,354 ----
  		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) && 
+ 				(schemaBeforeData || schemaAfterData))
+ 	{
+ 		write_msg(NULL, "options %s and %s cannot be used together\n",
+ 				schemaOnly ? "-s/--schema-only" : "-a/--data-only",
+ 				schemaBeforeData ? "--schema-before-data" : "--schema-after-data");
+ 		exit(1);
+ 	}
+ 	else if (schemaBeforeData && schemaAfterData)
+ 	{
+ 		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 (schemaBeforeData)
+ 		dumpObjFlags = REQ_SCHEMA_BEFORE_DATA;
+ 
+ 	if (schemaAfterData)
+ 		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;
***************
*** 405,410 ****
--- 459,466 ----
  			 "                           do not restore data of tables that could not be\n"
  			 "                           created\n"));
  	printf(_("  --no-tablespaces         do not dump tablespace assignments\n"));
+ 	printf(_("  --schema-before-data     dump only the part of schema before table data\n"));
+ 	printf(_("  --schema-after-data      dump only the part of schema after table data\n"));
  	printf(_("  --use-set-session-authorization\n"
  			 "                           use SESSION AUTHORIZATION commands instead of\n"
  			 "                           OWNER TO commands\n"));
-- 
Sent via pgsql-patches mailing list (pgsql-patches@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-patches

Reply via email to