Accept a non-existent value in "ALTER USER/DATABASE SET ..." command.
When default_text_search_config, default_tablespace, or temp_tablespaces setting is set per-user or per-database, with an "ALTER USER/DATABASE SET ..." statement, don't throw an error if the text search configuration or tablespace does not exist. In case of text search configuration, even if it doesn't exist in the current database, it might exist in another database, where the setting is intended to have its effect. This behavior is now the same as search_path's. Tablespaces are cluster-wide, so the same argument doesn't hold for tablespaces, but there's a problem with pg_dumpall: it dumps "ALTER USER SET ..." statements before the "CREATE TABLESPACE" statements. Arguably that's pg_dumpall's fault - it should dump the statements in such an order that the tablespace is created first and then the "ALTER USER SET default_tablespace ..." statements after that - but it seems better to be consistent with search_path and default_text_search_config anyway. Besides, you could still create a dump that throws an error, by creating the tablespace, running "ALTER USER SET default_tablespace", then dropping the tablespace and running pg_dumpall on that. Backpatch to all supported versions.
This commit is contained in:
parent
b4e9fd4df3
commit
45bcc71980
@ -926,11 +926,22 @@ assign_default_tablespace(const char *newval, bool doit, GucSource source)
|
||||
if (newval[0] != '\0' &&
|
||||
!OidIsValid(get_tablespace_oid(newval)))
|
||||
{
|
||||
ereport(GUC_complaint_elevel(source),
|
||||
/*
|
||||
* When source == PGC_S_TEST, we are checking the argument of an
|
||||
* ALTER DATABASE SET or ALTER USER SET command. pg_dumpall dumps
|
||||
* all roles before tablespaces, so if we're restoring a
|
||||
* pg_dumpall script the tablespace might not yet exist, but will
|
||||
* be created later. Because of that, issue a NOTICE if source ==
|
||||
* PGC_S_TEST, but accept the value anyway.
|
||||
*/
|
||||
ereport((source == PGC_S_TEST) ? NOTICE : GUC_complaint_elevel(source),
|
||||
(errcode(ERRCODE_UNDEFINED_OBJECT),
|
||||
errmsg("tablespace \"%s\" does not exist",
|
||||
newval)));
|
||||
return NULL;
|
||||
if (source == PGC_S_TEST)
|
||||
return newval;
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1047,10 +1058,16 @@ assign_temp_tablespaces(const char *newval, bool doit, GucSource source)
|
||||
{
|
||||
/*
|
||||
* In an interactive SET command, we ereport for bad info.
|
||||
* When source == PGC_S_TEST, we are checking the argument of
|
||||
* an ALTER DATABASE SET or ALTER USER SET command. pg_dumpall
|
||||
* dumps all roles before tablespaces, so if we're restoring a
|
||||
* pg_dumpall script the tablespace might not yet exist, but
|
||||
* will be created later. Because of that, issue a NOTICE if
|
||||
* source == PGC_S_TEST, but accept the value anyway.
|
||||
* Otherwise, silently ignore any bad list elements.
|
||||
*/
|
||||
if (source >= PGC_S_INTERACTIVE)
|
||||
ereport(ERROR,
|
||||
ereport((source == PGC_S_TEST) ? NOTICE : ERROR,
|
||||
(errcode(ERRCODE_UNDEFINED_OBJECT),
|
||||
errmsg("tablespace \"%s\" does not exist",
|
||||
curname)));
|
||||
|
20
src/backend/utils/cache/ts_cache.c
vendored
20
src/backend/utils/cache/ts_cache.c
vendored
@ -608,8 +608,26 @@ assignTSCurrentConfig(const char *newval, bool doit, GucSource source)
|
||||
|
||||
cfgId = TSConfigGetCfgid(stringToQualifiedNameList(newval), true);
|
||||
|
||||
/*
|
||||
* When source == PGC_S_TEST, we are checking the argument of an
|
||||
* ALTER DATABASE SET or ALTER USER SET command. It could be that
|
||||
* the intended use of the setting is for some other database, so
|
||||
* we should not error out if the text search configuration is not
|
||||
* present in the current database. We issue a NOTICE instead.
|
||||
*/
|
||||
if (!OidIsValid(cfgId))
|
||||
return NULL;
|
||||
{
|
||||
if (source == PGC_S_TEST && !doit)
|
||||
{
|
||||
ereport(NOTICE,
|
||||
(errcode(ERRCODE_UNDEFINED_OBJECT),
|
||||
errmsg("text search configuration \"%s\" does not exist",
|
||||
newval)));
|
||||
return newval;
|
||||
}
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* Modify the actually stored value to be fully qualified, to ensure
|
||||
|
Loading…
x
Reference in New Issue
Block a user