Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit b896e1e

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 106123f commit b896e1e

File tree

2 files changed

+55
-7
lines changed

2 files changed

+55
-7
lines changed

src/backend/commands/tablespace.c

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,9 +1036,27 @@ check_default_tablespace(char **newval, void **extra, GucSource source)
10361036
if (**newval != '\0' &&
10371037
!OidIsValid(get_tablespace_oid(*newval, true)))
10381038
{
1039-
GUC_check_errdetail("Tablespace \"%s\" does not exist.",
1040-
*newval);
1041-
return false;
1039+
/*
1040+
* When source == PGC_S_TEST, we are checking the argument of an
1041+
* ALTER DATABASE SET or ALTER USER SET command. pg_dumpall dumps
1042+
* all roles before tablespaces, so if we're restoring a
1043+
* pg_dumpall script the tablespace might not yet exist, but will
1044+
* be created later. Because of that, issue a NOTICE if source ==
1045+
* PGC_S_TEST, but accept the value anyway.
1046+
*/
1047+
if (source == PGC_S_TEST)
1048+
{
1049+
ereport(NOTICE,
1050+
(errcode(ERRCODE_UNDEFINED_OBJECT),
1051+
errmsg("tablespace \"%s\" does not exist",
1052+
*newval)));
1053+
}
1054+
else
1055+
{
1056+
GUC_check_errdetail("Tablespace \"%s\" does not exist.",
1057+
*newval);
1058+
return false;
1059+
}
10421060
}
10431061
}
10441062

@@ -1153,12 +1171,25 @@ check_temp_tablespaces(char **newval, void **extra, GucSource source)
11531171
}
11541172

11551173
/*
1156-
* In an interactive SET command, we ereport for bad info.
1157-
* Otherwise, silently ignore any bad list elements.
1174+
* In an interactive SET command, we ereport for bad info. When
1175+
* source == PGC_S_TEST, we are checking the argument of an ALTER
1176+
* DATABASE SET or ALTER USER SET command. pg_dumpall dumps all
1177+
* roles before tablespaces, so if we're restoring a pg_dumpall
1178+
* script the tablespace might not yet exist, but will be created
1179+
* later. Because of that, issue a NOTICE if source == PGC_S_TEST,
1180+
* but accept the value anyway. Otherwise, silently ignore any
1181+
* bad list elements.
11581182
*/
1159-
curoid = get_tablespace_oid(curname, source < PGC_S_INTERACTIVE);
1183+
curoid = get_tablespace_oid(curname, source <= PGC_S_TEST);
11601184
if (curoid == InvalidOid)
1185+
{
1186+
if (source == PGC_S_TEST)
1187+
ereport(NOTICE,
1188+
(errcode(ERRCODE_UNDEFINED_OBJECT),
1189+
errmsg("tablespace \"%s\" does not exist",
1190+
curname)));
11611191
continue;
1192+
}
11621193

11631194
/*
11641195
* Allow explicit specification of database's default tablespace

src/backend/utils/cache/ts_cache.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -604,8 +604,25 @@ check_TSCurrentConfig(char **newval, void **extra, GucSource source)
604604

605605
cfgId = get_ts_config_oid(stringToQualifiedNameList(*newval), true);
606606

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

610627
/*
611628
* Modify the actually stored value to be fully qualified, to ensure

0 commit comments

Comments
 (0)