Skip to content

Commit 73d78e1

Browse files
committed
Throw error for ALTER TABLE RESET of an invalid option
Also adjust pg_upgrade to not use this method for optional TOAST table creation. Patch by Fabrízio de Royes Mello
1 parent ebe30ad commit 73d78e1

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

contrib/pg_upgrade/dump.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,10 @@ optionally_create_toast_tables(void)
115115
"c.relkind IN ('r', 'm') AND "
116116
"c.reltoastrelid = 0");
117117

118+
/* Suppress NOTICE output from non-existant constraints */
119+
PQclear(executeQueryOrDie(conn, "SET client_min_messages = warning;"));
120+
PQclear(executeQueryOrDie(conn, "SET log_min_messages = warning;"));
121+
118122
ntups = PQntuples(res);
119123
i_nspname = PQfnumber(res, "nspname");
120124
i_relname = PQfnumber(res, "relname");
@@ -125,13 +129,16 @@ optionally_create_toast_tables(void)
125129
OPTIONALLY_CREATE_TOAST_OID));
126130

127131
/* dummy command that also triggers check for required TOAST table */
128-
PQclear(executeQueryOrDie(conn, "ALTER TABLE %s.%s RESET (binary_upgrade_dummy_option);",
132+
PQclear(executeQueryOrDie(conn, "ALTER TABLE %s.%s DROP CONSTRAINT IF EXISTS binary_upgrade_dummy_constraint;",
129133
quote_identifier(PQgetvalue(res, rowno, i_nspname)),
130134
quote_identifier(PQgetvalue(res, rowno, i_relname))));
131135
}
132136

133137
PQclear(res);
134138

139+
PQclear(executeQueryOrDie(conn, "RESET client_min_messages;"));
140+
PQclear(executeQueryOrDie(conn, "RESET log_min_messages;"));
141+
135142
PQfinish(conn);
136143
}
137144

src/backend/access/common/reloptions.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,8 @@ static void initialize_reloptions(void);
307307
static void parse_one_reloption(relopt_value *option, char *text_str,
308308
int text_len, bool validate);
309309

310+
static bool is_valid_reloption(char *name);
311+
310312
/*
311313
* initialize_reloptions
312314
* initialization routine, must be called before parsing
@@ -381,6 +383,25 @@ initialize_reloptions(void)
381383
need_initialization = false;
382384
}
383385

386+
/*
387+
* is_valid_reloption
388+
* check if a reloption exists
389+
*
390+
*/
391+
static bool
392+
is_valid_reloption(char *name)
393+
{
394+
int i;
395+
396+
for (i = 0; relOpts[i]; i++)
397+
{
398+
if (pg_strcasecmp(relOpts[i]->name, name) == 0)
399+
return true;
400+
}
401+
402+
return false;
403+
}
404+
384405
/*
385406
* add_reloption_kind
386407
* Create a new relopt_kind value, to be used in custom reloptions by
@@ -672,6 +693,11 @@ transformRelOptions(Datum oldOptions, List *defList, char *namspace,
672693

673694
if (isReset)
674695
{
696+
if (!is_valid_reloption(def->defname))
697+
ereport(ERROR,
698+
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
699+
errmsg("unrecognized parameter \"%s\"", def->defname)));
700+
675701
if (def->arg != NULL)
676702
ereport(ERROR,
677703
(errcode(ERRCODE_SYNTAX_ERROR),

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy