8000 Accept a non-existent value in "ALTER USER/DATABASE SET ..." command. · jcsston/postgres@45bcc71 · GitHub
[go: up one dir, main page]

Skip to content

Commit 45bcc71

Browse files
committed
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.
1 parent b4e9fd4 commit 45bcc71

File tree

2 files changed

+39
-4
lines changed

2 files changed

+39
-4
lines changed

src/backend/commands/tablespace.c

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -926,11 +926,22 @@ assign_default_tablespace(const char *newval, bool doit, GucSource source)
926926
if (newval[0] != '\0' &&
927927
!OidIsValid(get_tablespace_oid(newval)))
928928
{
929-
ereport(GUC_complaint_elevel(source),
929+
/*
930+
* When source == PGC_S_TEST, we are checking the argument of an
931+
* ALTER DATABASE SET or ALTER USER SET command. pg_dumpall dumps
932+
* all roles before tablespaces, so if we're restoring a
933+
* pg_dumpall script the tablespace might not yet exist, but will
934+
* be created later. Because of that, issue a NOTICE if source ==
935+
* PGC_S_TEST, but accept the value anyway.
936+
*/
937+
ereport((source == PGC_S_TEST) ? NOTICE : GUC_complaint_elevel(source),
930938
(errcode(ERRCODE_UNDEFINED_OBJECT),
931939
errmsg("tablespace \"%s\" does not exist",
932940
newval)));
933-
return NULL;
941+
if (source == PGC_S_TEST)
942+
return newval;
943+
else
944+
return NULL;
934945
}
935946
}
936947

@@ -1047,10 +1058,16 @@ assign_temp_tablespaces(const char *newval, bool doit, GucSource source)
10471058
{
10481059
/*
10491060
* In an interactive SET command, we ereport for bad info.
1061+
* When source == PGC_S_TEST, we are checking the argument of
1062+
* an ALTER DATABASE SET or ALTER USER SET command. pg_dumpall
1063+
* dumps all roles before tablespaces, so if we're restoring a
1064+
* pg_dumpall script the tablespace might not yet exist, but
1065 10000 +
* will be created later. Because of that, issue a NOTICE if
1066+
* source == PGC_S_TEST, but accept the value anyway.
10501067
* Otherwise, silently ignore any bad list elements.
10511068
*/
10521069
if (source >= PGC_S_INTERACTIVE)
1053-
ereport(ERROR,
1070+
ereport((source == PGC_S_TEST) ? NOTICE : ERROR,
10541071
(errcode(ERRCODE_UNDEFINED_OBJECT),
10551072
errmsg("tablespace \"%s\" does not exist",
10561073
curname)));

src/backend/utils/cache/ts_cache.c

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -608,8 +608,26 @@ assignTSCurrentConfig(const char *newval, bool doit, GucSource source)
608608

609609
cfgId = TSConfigGetCfgid(stringToQualifiedNameList(newval), true);
610610

611+
/*
612+
* When source == PGC_S_TEST, we are checking the argument of an
613+
* ALTER DATABASE SET or ALTER USER SET command. It could be that
614+
* the intended use of the setting is for some other database, so
615+
* we should not error out if the text search configuration is not
616+
* present in the current database. We issue a NOTICE instead.
617+
*/
611618
if (!OidIsValid(cfgId))
612-
return NULL;
619+
{
620+
if (source == PGC_S_TEST && !doit)
621+
{
622+
ereport(NOTICE,
623+
(errcode(ERRCODE_UNDEFINED_OBJECT),
624+
errmsg("text search configuration \"%s\" does not exist",
625+
newval)));
626+
return newval;
627+
}
628+
else
629+
return NULL;
630+
}
613631

614632
/*
615633
* Modify the actually stored value to be fully qualified, to ensure

0 commit comments

Comments
 (0)
0