Skip to content

Commit 8bff640

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 a752952 commit 8bff640

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
@@ -1031,11 +1031,22 @@ assign_default_tablespace(const char *newval, bool doit, GucSource source)
10311031
if (newval[0] != '\0' &&
10321032
!OidIsValid(get_tablespace_oid(newval)))
10331033
{
1034-
ereport(GUC_complaint_elevel(source),
1034+
/*
1035+
* When source == PGC_S_TEST, we are checking the argument of an
1036+
* ALTER DATABASE SET or ALTER USER SET command. pg_dumpall dumps
1037+
* all roles before tablespaces, so if we're restoring a
1038+
* pg_dumpall script the tablespace might not yet exist, but will
1039+
* be created later. Because of that, issue a NOTICE if source ==
1040+
* PGC_S_TEST, but accept the value anyway.
1041+
*/
1042+
ereport((source == PGC_S_TEST) ? NOTICE : GUC_complaint_elevel(source),
10351043
(errcode(ERRCODE_UNDEFINED_OBJECT),
10361044
errmsg("tablespace \"%s\" does not exist",
10371045
newval)));
1038-
return NULL;
1046+
if (source == PGC_S_TEST)
1047+
return newval;
1048+
else
1049+
return NULL;
10391050
}
10401051
}
10411052

@@ -1152,10 +1163,16 @@ assign_temp_tablespaces(const char *newval, bool doit, GucSource source)
11521163
{
11531164
/*
11541165
* In an interactive SET command, we ereport for bad info.
1166+
* When source == PGC_S_TEST, we are checking the argument of
1167+
* an ALTER DATABASE SET or ALTER USER SET command. pg_dumpall
1168+
* dumps all roles before tablespaces, so if we're restoring a
1169+
* pg_dumpall script the tablespace might not yet exist, but
1170+
* will be created later. Because of that, issue a NOTICE if
1171+
* source == PGC_S_TEST, but accept the value anyway.
11551172
* Otherwise, silently ignore any bad list elements.
11561173
*/
11571174
if (source >= PGC_S_INTERACTIVE)
1158-
ereport(ERROR,
1175+
ereport((source == PGC_S_TEST) ? NOTICE : ERROR,
11591176
(errcode(ERRCODE_UNDEFINED_OBJECT),
11601177
errmsg("tablespace \"%s\" does not exist",
11611178
curname)));

src/backend/utils/cache/ts_cache.c

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

604604
cfgId = TSConfigGetCfgid(stringToQualifiedNameList(newval), true);
605605

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

609627
/*
610628
* Modify the actually stored value to be fully qualified, to ensure

0 commit comments

Comments
 (0)