暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

PostgreSQL 14 preview - 自定义GUC参数规范化

digoal 2021-01-04
564

作者

digoal

日期

2021-04-08

标签

PostgreSQL , 自定义参数 , GUC


背景

PostgreSQL 14 自定义参数规范化, 必须由字母数字_和美元符号组成. 开头只能是字母

https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=3db826bd55cd1df0dd8c3d811f8e5b936d7ba1e4

```
Tighten up allowed names for custom GUC parameters.
author Tom Lane tgl@sss.pgh.pa.us
Wed, 7 Apr 2021 15:22:22 +0000 (11:22 -0400)
committer Tom Lane tgl@sss.pgh.pa.us
Wed, 7 Apr 2021 15:22:22 +0000 (11:22 -0400)
commit 3db826bd55cd1df0dd8c3d811f8e5b936d7ba1e4
tree 58aa2d1b51b3ce1e8990ab2b516f7a8be68287f4 tree
parent 23607a8156d595522c232ff3933d77041d3adaa1 commit | diff
Tighten up allowed names for custom GUC parameters.

Formerly we were pretty lax about what a custom GUC's name could
be; so long as it had at least one dot in it, we'd take it.
However, corner cases such as dashes or equal signs in the name
would cause various bits of functionality to misbehave. Rather
than trying to make the world perfectly safe for that, let's
just require that custom names look like "identifier.identifier",
where "identifier" means something that scan.l would accept
without double quotes.

Along the way, this patch refactors things slightly in guc.c
so that find_option() is responsible for reporting GUC-not-found
cases, allowing removal of duplicative code from its callers.

Per report from Hubert Depesz Lubaczewski. No back-patch,
since the consequences of the problem don't seem to warrant
changing behavior in stable branches.

Discussion: https://postgr.es/m/951335.1612910077@sss.pgh.pa.us
```

+SET no_such_variable TO 42; +ERROR: unrecognized configuration parameter "no_such_variable" +-- Test "custom" GUCs created on the fly (which aren't really an +-- intended feature, but many people use them). +SET custom.my_guc = 42; +SHOW custom.my_guc; + custom.my_guc +--------------- + 42 +(1 row) + +SET custom."bad-guc" = 42; -- disallowed because -c cannot set this name +ERROR: invalid configuration parameter name "custom.bad-guc" +DETAIL: Custom parameter names must be of the form "identifier.identifier". +SHOW custom."bad-guc"; +ERROR: unrecognized configuration parameter "custom.bad-guc" +SET special."weird name" = 'foo'; -- could be allowed, but we choose not to +ERROR: invalid configuration parameter name "special.weird name" +DETAIL: Custom parameter names must be of the form "identifier.identifier". +SHOW special."weird name"; +ERROR: unrecognized configuration parameter "special.weird name"

+/* + * Decide whether a proposed custom variable name is allowed. + * + * It must be "identifier.identifier", where the rules for what is an + * identifier agree with scan.l. + */ +static bool +valid_custom_variable_name(const char *name) +{ + int num_sep = 0; + bool name_start = true; + + for (const char *p = name; *p; p++) + { + if (*p == GUC_QUALIFIER_SEPARATOR) + { + if (name_start) + return false; /* empty name component */ + num_sep++; + name_start = true; + } + else if (strchr("ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "abcdefghijklmnopqrstuvwxyz", *p) != NULL || + IS_HIGHBIT_SET(*p)) + { + /* okay as first or non-first character */ + name_start = false; + } + else if (!name_start && strchr("0123456789_$", *p) != NULL) + /* okay as non-first character */ ; + else + return false; + } + if (name_start) + return false; /* empty name component */ + /* OK if we had exactly one separator */ + return (num_sep == 1); +}

PostgreSQL 许愿链接

您的愿望将传达给PG kernel hacker、数据库厂商等, 帮助提高数据库产品质量和功能, 说不定下一个PG版本就有您提出的功能点. 针对非常好的提议,奖励限量版PG文化衫、纪念品、贴纸、PG热门书籍等,奖品丰富,快来许愿。开不开森.

9.9元购买3个月阿里云RDS PostgreSQL实例

PostgreSQL 解决方案集合

德哥 / digoal's github - 公益是一辈子的事.

digoal's wechat

文章转载自digoal,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论