On Fri, Aug 22, 2014 at 10:04:50PM -0400, Bruce Momjian wrote:
> On Fri, Aug 22, 2014 at 03:12:47PM -0400, Robert Haas wrote:
> > On Fri, Aug 22, 2014 at 2:33 PM, Bruce Momjian <br...@momjian.us> wrote:
> > >> Yes, you remember well.  I will have to find a different way for
> > >> pg_upgrade to call a no-op ALTER TABLE, which is fine.
> > >
> > > Looking at the ALTER TABLE options, I am going to put this check in a
> > > !IsBinaryUpgrade block so pg_upgrade can still use its trick.
> > 
> > -1, that's really ugly.
> > 
> > Maybe the right solution is to add a form of ALTER TABLE that is
> > specifically defined to do only this check.  This is an ongoing need,
> > so that might not be out of line.
> 
> Ah, seems ALTER TABLE ... DROP CONSTRAINT IF EXISTS also works --- I
> will use that.

OK, attached patch applied, with pg_upgrade adjustments.  I didn't
think the original regression tests for this were necessary.

-- 
  Bruce Momjian  <br...@momjian.us>        http://momjian.us
  EnterpriseDB                             http://enterprisedb.com

  + Everyone has their own god. +
diff --git a/contrib/pg_upgrade/dump.c b/contrib/pg_upgrade/dump.c
new file mode 100644
index e623a22..29a68c0
*** a/contrib/pg_upgrade/dump.c
--- b/contrib/pg_upgrade/dump.c
*************** optionally_create_toast_tables(void)
*** 115,120 ****
--- 115,124 ----
  								"c.relkind IN ('r', 'm') AND "
  								"c.reltoastrelid = 0");
  
+ 		/* Suppress NOTICE output from non-existant constraints */
+ 		PQclear(executeQueryOrDie(conn, "SET client_min_messages = warning;"));
+ 		PQclear(executeQueryOrDie(conn, "SET log_min_messages = warning;"));
+ 
  		ntups = PQntuples(res);
  		i_nspname = PQfnumber(res, "nspname");
  		i_relname = PQfnumber(res, "relname");
*************** optionally_create_toast_tables(void)
*** 125,137 ****
  					OPTIONALLY_CREATE_TOAST_OID));
  
  			/* dummy command that also triggers check for required TOAST table */
! 			PQclear(executeQueryOrDie(conn, "ALTER TABLE %s.%s RESET (binary_upgrade_dummy_option);",
  					quote_identifier(PQgetvalue(res, rowno, i_nspname)),
  					quote_identifier(PQgetvalue(res, rowno, i_relname))));
  		}
  
  		PQclear(res);
  
  		PQfinish(conn);
  	}
  
--- 129,144 ----
  					OPTIONALLY_CREATE_TOAST_OID));
  
  			/* dummy command that also triggers check for required TOAST table */
! 			PQclear(executeQueryOrDie(conn, "ALTER TABLE %s.%s DROP CONSTRAINT IF EXISTS binary_upgrade_dummy_constraint;",
  					quote_identifier(PQgetvalue(res, rowno, i_nspname)),
  					quote_identifier(PQgetvalue(res, rowno, i_relname))));
  		}
  
  		PQclear(res);
  
+ 		PQclear(executeQueryOrDie(conn, "RESET client_min_messages;"));
+ 		PQclear(executeQueryOrDie(conn, "RESET log_min_messages;"));
+ 
  		PQfinish(conn);
  	}
  
diff --git a/src/backend/access/common/reloptions.c b/src/backend/access/common/reloptions.c
new file mode 100644
index e0b81b9..97a4e22
*** a/src/backend/access/common/reloptions.c
--- b/src/backend/access/common/reloptions.c
*************** static void initialize_reloptions(void);
*** 307,312 ****
--- 307,314 ----
  static void parse_one_reloption(relopt_value *option, char *text_str,
  					int text_len, bool validate);
  
+ static bool is_valid_reloption(char *name);
+ 
  /*
   * initialize_reloptions
   *		initialization routine, must be called before parsing
*************** initialize_reloptions(void)
*** 382,387 ****
--- 384,408 ----
  }
  
  /*
+  * is_valid_reloption
+  *		check if a reloption exists
+  *
+  */
+ static bool
+ is_valid_reloption(char *name)
+ {
+ 	int i;
+ 
+ 	for (i = 0; relOpts[i]; i++)
+ 	{
+ 		if (pg_strcasecmp(relOpts[i]->name, name) == 0)
+ 			return true;
+ 	}
+ 
+ 	return false;
+ }
+ 
+ /*
   * add_reloption_kind
   *		Create a new relopt_kind value, to be used in custom reloptions by
   *		user-defined AMs.
*************** transformRelOptions(Datum oldOptions, Li
*** 672,677 ****
--- 693,703 ----
  
  		if (isReset)
  		{
+ 			if (!is_valid_reloption(def->defname))
+ 				ereport(ERROR,
+ 						(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
+ 						 errmsg("unrecognized parameter \"%s\"", def->defname)));
+ 
  			if (def->arg != NULL)
  				ereport(ERROR,
  						(errcode(ERRCODE_SYNTAX_ERROR),
-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Reply via email to