Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita578257

Browse files
committed
Accept a non-existent value in "ALTER USER/DATABASE SET ..." command.
When default_text_search_config, default_tablespace, or temp_tablespacessetting is set per-user or per-database, with an "ALTER USER/DATABASE SET..." statement, don't throw an error if the text search configuration ortablespace does not exist. In case of text search configuration, even ifit doesn't exist in the current database, it might exist in anotherdatabase, where the setting is intended to have its effect. This behavioris now the same as search_path's.Tablespaces are cluster-wide, so the same argument doesn't hold fortablespaces, but there's a problem with pg_dumpall: it dumps "ALTER USERSET ..." statements before the "CREATE TABLESPACE" statements. Arguablythat's pg_dumpall's fault - it should dump the statements in such an orderthat the tablespace is created first and then the "ALTER USER SETdefault_tablespace ..." statements after that - but it seems better to beconsistent with search_path and default_text_search_config anyway. Besides,you could still create a dump that throws an error, by creating thetablespace, running "ALTER USER SET default_tablespace", then dropping thetablespace and running pg_dumpall on that.Backpatch to all supported versions.
1 parentad10853 commita578257

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
@@ -1031,9 +1031,27 @@ check_default_tablespace(char **newval, void **extra, GucSource source)
10311031
if (**newval!='\0'&&
10321032
!OidIsValid(get_tablespace_oid(*newval, true)))
10331033
{
1034-
GUC_check_errdetail("Tablespace \"%s\" does not exist.",
1035-
*newval);
1036-
return false;
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+
if (source==PGC_S_TEST)
1043+
{
1044+
ereport(NOTICE,
1045+
(errcode(ERRCODE_UNDEFINED_OBJECT),
1046+
errmsg("tablespace \"%s\" does not exist",
1047+
*newval)));
1048+
}
1049+
else
1050+
{
1051+
GUC_check_errdetail("Tablespace \"%s\" does not exist.",
1052+
*newval);
1053+
return false;
1054+
}
10371055
}
10381056
}
10391057

@@ -1148,12 +1166,25 @@ check_temp_tablespaces(char **newval, void **extra, GucSource source)
11481166
}
11491167

11501168
/*
1151-
* In an interactive SET command, we ereport for bad info.
1152-
* Otherwise, silently ignore any bad list elements.
1169+
* In an interactive SET command, we ereport for bad info. When
1170+
* source == PGC_S_TEST, we are checking the argument of an ALTER
1171+
* DATABASE SET or ALTER USER SET command. pg_dumpall dumps all
1172+
* roles before tablespaces, so if we're restoring a pg_dumpall
1173+
* script the tablespace might not yet exist, but will be created
1174+
* later. Because of that, issue a NOTICE if source == PGC_S_TEST,
1175+
* but accept the value anyway. Otherwise, silently ignore any
1176+
* bad list elements.
11531177
*/
1154-
curoid=get_tablespace_oid(curname,source<PGC_S_INTERACTIVE);
1178+
curoid=get_tablespace_oid(curname,source <=PGC_S_TEST);
11551179
if (curoid==InvalidOid)
1180+
{
1181+
if (source==PGC_S_TEST)
1182+
ereport(NOTICE,
1183+
(errcode(ERRCODE_UNDEFINED_OBJECT),
1184+
errmsg("tablespace \"%s\" does not exist",
1185+
curname)));
11561186
continue;
1187+
}
11571188

11581189
/*
11591190
* 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
@@ -601,8 +601,25 @@ check_TSCurrentConfig(char **newval, void **extra, GucSource source)
601601

602602
cfgId=get_ts_config_oid(stringToQualifiedNameList(*newval), true);
603603

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

607624
/*
608625
* Modify the actually stored value to be fully qualified, to ensure

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp