Skip to content

Latest commit

 

History

History
109 lines (79 loc) · 4.35 KB

20231026_01.md

File metadata and controls

109 lines (79 loc) · 4.35 KB

PostgreSQL 17 preview - Allow ALTER SYSTEM to set unrecognized custom GUCs.

作者

digoal

日期

2023-10-26

标签

PostgreSQL , PolarDB , GUC , alter system set , unrecognized custom guc


背景

https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=2d870b4aeff174ea3b8a0837bc2065c820fb43e2

Allow ALTER SYSTEM to set unrecognized custom GUCs.  
  
author	Tom Lane <tgl@sss.pgh.pa.us>	  
Sat, 21 Oct 2023 17:35:19 +0000 (13:35 -0400)  
committer	Tom Lane <tgl@sss.pgh.pa.us>	  
Sat, 21 Oct 2023 17:35:19 +0000 (13:35 -0400)  
commit	2d870b4aeff174ea3b8a0837bc2065c820fb43e2  
tree	e1b9019542be5d4a9fd69e21ed1158ae80c3604d	tree  
parent	36a14afc076024ba48c399f2af2d4cd1b2c39348	commit | diff  
Allow ALTER SYSTEM to set unrecognized custom GUCs.  
  
Previously, ALTER SYSTEM failed if the target GUC wasn't present in  
the session's GUC hashtable.  That is a reasonable behavior for core  
(single-part) GUC names, and for custom GUCs for which we have loaded  
an extension that's reserved the prefix.  But it's unnecessarily  
restrictive otherwise, and it also causes inconsistent behavior:  
you can "ALTER SYSTEM SET foo.bar" only if you did "SET foo.bar"  
earlier in the session.  That's fairly silly.  
  
Hence, refactor things so that we can execute ALTER SYSTEM even  
if the variable doesn't have a GUC hashtable entry, as long as the  
name meets the custom-variable naming requirements and does not  
have a reserved prefix.  (It's safe to do this even if the  
variable belongs to an extension we currently don't have loaded.  
A bad value will at worst cause a WARNING when the extension  
does get loaded.)  
  
Also, adjust GRANT ON PARAMETER to have the same opinions about  
whether to allow an unrecognized GUC name, and to throw the  
same errors if not (it previously used a one-size-fits-all  
message for several distinguishable conditions).  By default,  
only a superuser will be allowed to do ALTER SYSTEM SET on an  
unrecognized name, but it's possible to GRANT the ability to  
do it.  
  
Patch by me, pursuant to a documentation complaint from  
Gavin Panella.  Arguably this is a bug fix, but given the  
lack of other complaints I'll refrain from back-patching.  
  
Discussion: https://postgr.es/m/2617358.1697501956@sss.pgh.pa.us  
Discussion: https://postgr.es/m/169746329791.169914.16613647309012285391@wrigleys.postgresql.org  
+-- Superuser should be able to ALTER SYSTEM SET a non-existent custom GUC.  
+ALTER SYSTEM SET none.such = 'whiz bang';  
+-- None of the above should have created a placeholder GUC for none.such.  
+SHOW none.such;  -- error  
+ERROR:  unrecognized configuration parameter "none.such"  
+-- However, if we reload ...  
+SELECT pg_reload_conf();  
+ pg_reload_conf   
+----------------  
+ t  
+(1 row)  
+  
+-- and start a new session to avoid race condition ...  
+\c -  
+SET SESSION AUTHORIZATION regress_admin;  
+-- then it should be there.  
+SHOW none.such;  
+ none.such   
+-----------  
+ whiz bang  
+(1 row)  
+  

digoal's wechat