⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 readme

📁 PostgreSQL 8.1.4的源码 适用于Linux下的开源数据库系统
💻
字号:
$PostgreSQL: pgsql/src/backend/utils/misc/README,v 1.5 2004/07/01 00:51:24 tgl Exp $GUC IMPLEMENTATION NOTESThe GUC (Grand Unified Configuration) module implements configurationvariables of multiple types (currently boolean, int, float, and string).Variable settings can come from various places, with a priority orderingdetermining which setting is used.PER-VARIABLE HOOKSEach variable known to GUC can optionally have an assign_hook and/ora show_hook to provide customized behavior.  Assign hooks are used toperform validity checking on variable values (above and beyond whatGUC can do).  They are also used to update any derived state that needsto change when a GUC variable is set.  Show hooks are used to modifythe default SHOW display for a variable.If an assign_hook is provided, it points to a function of the signature	bool assign_hook(newvalue, bool doit, GucSource source)where the type of "newvalue" matches the kind of variable.  This functionis called immediately before actually setting the variable's value (so itcan look at the actual variable to determine the old value).  If thefunction returns "true" then the assignment is completed; if it returns"false" then newvalue is considered invalid and the assignment is notperformed.  If "doit" is false then the function should simply checkvalidity of newvalue and not change any derived state.  The "source" parameterindicates where the new value came from.  If it is >= PGC_S_INTERACTIVE,then we are performing an interactive assignment (e.g., a SET command).In such cases it is okay for the assign_hook to raise an error via ereport().If the function returns false for an interactive assignment then guc.c willreport a generic "invalid value" error message.  (An internal ereport() inan assign_hook is only needed if you want to generate a specialized errormessage.)  But when source < PGC_S_INTERACTIVE, we are reading anon-interactive option source, such as postgresql.conf.  In this case theassign_hook should *not* ereport but should just return false if it doesn'tlike the newvalue.  (An ereport(LOG) call would be acceptable if you feel aneed for a custom complaint in this situation.)For string variables, the signature for assign hooks is a bit different:	const char *assign_hook(const char *newvalue,				bool doit,				GucSource source)The meanings of the parameters are the same as for the other types of GUCvariables, but the return value is handled differently:	NULL --- assignment fails (like returning false for other datatypes)	newvalue --- assignment succeeds, assign the newvalue as-is	malloc'd (not palloc'd!!!) string --- assign that value insteadThe third choice is allowed in case the assign_hook wants to return a"canonical" version of the new value.  For example, the assign_hook fordatestyle always returns a string that includes both output and inputdatestyle options, although the input might have specified only one.If a show_hook is provided, it points to a function of the signature	const char *show_hook(void)This hook allows variable-specific computation of the value displayedby SHOW.SAVING/RESTORING GUC VARIABLE VALUESPrior values of configuration variables must be remembered in order todeal with three special cases: RESET (a/k/a SET TO DEFAULT), rollback ofSET on transaction abort, and rollback of SET LOCAL at transaction end(either commit or abort).  RESET is defined as selecting the value thatwould be effective had there never been any SET commands in the currentsession.To handle these cases we must keep track of many distinct values for eachvariable.  The primary values are:* actual variable contents	always the current effective value* reset_value			the value to use for RESET* tentative_value		the uncommitted result of SETThe reason we need a tentative_value separate from the actual value isthat when a transaction does SET followed by SET LOCAL, the actual valuewill now be the LOCAL value, but we want to remember the prior SET so thatthat value is restored at transaction commit.In addition, for each level of transaction (possibly nested) we have toremember the transaction-entry-time actual and tentative values, in casewe need to restore them at transaction end.  (The RESET value is essentiallynon-transactional, so it doesn't have to be stacked.)  For efficiency thesestack entries are not constructed until/unless the variable is actually SETwithin a particular transaction.During initialization we set the actual value and reset_value based onwhichever non-interactive source has the highest priority.  They willhave the same value.  The tentative_value is not meaningful at this point.A SET command starts by stacking the existing actual and tentative valuesif this hasn't already been done within the current transaction.  Then:A SET LOCAL command sets the actual variable (and nothing else).  Attransaction end, the stacked values are used to restore the GUC entryto its pre-transaction state.A SET (or SET SESSION) command sets the actual variable, and if no error,then sets the tentative_value.  If the transaction commits, thetentative_value is assigned again to the actual variable (which could bynow be different, if the SET was followed by SET LOCAL).  If thetransaction aborts, the stacked values are used to restore the GUC entryto its pre-transaction state.In the case of SET within nested subtransactions, at each commit thetentative_value propagates out to the next transaction level.  It willbe thrown away at abort of any level, or after exiting the top transaction.RESET is executed like a SET, but using the reset_value as the desired newvalue.  (We do not provide a RESET LOCAL command, but SET LOCAL TO DEFAULThas the same behavior that RESET LOCAL would.)  The source associated withthe reset_value also becomes associated with the actual and tentative values.If SIGHUP is received, the GUC code rereads the postgresql.confconfiguration file (this does not happen in the signal handler, but atnext return to main loop; note that it can be executed while within atransaction).  New values from postgresql.conf are assigned to actualvariable, reset_value, and stacked actual values, but only if each ofthese has a current source priority <= PGC_S_FILE.  (It is thus possiblefor reset_value to track the config-file setting even if there iscurrently a different interactive value of the actual variable.)Note that tentative_value is unused and undefined except between a SETcommand and the end of the transaction.  Also notice that we must trackthe source associated with each one of the values.The assign_hook and show_hook routines work only with the actual variable,and are not directly aware of the additional values maintained by GUC.This is not a problem for normal usage, since we can assign first to theactual variable and then (if that succeeds) to the additional values asneeded.  However, for SIGHUP rereads we may not want to assign to theactual variable.  Our procedure in that case is to call the assign_hookwith doit = false so that the value is validated, but no derived state ischanged.STRING MEMORY HANDLINGString option values are allocated with strdup, not with thepstrdup/palloc mechanisms.  We would need to keep them in a permanentcontext anyway, and strdup gives us more control over handlingout-of-memory failures.We allow a string variable's actual value, reset_val, tentative_val, andstacked copies of same to point at the same storage.  This makes itslightly harder to free space (must test whether a value to be freed isn'tequal to any of the other pointers in the GUC entry or associated stackitems).  The main advantage is that we never need to strdup duringtransaction commit/abort, so cannot cause an out-of-memory failure there.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -