Hi all,

with this patch, you can now restore default value with SIGHUP when commenting 
an variable in postgresql.conf

Emmanuel BERTHOULE


Index: src/backend/utils/misc/guc-file.l
===================================================================
RCS file: /projects/cvsroot/pgsql/src/backend/utils/misc/guc-file.l,v
retrieving revision 1.37
diff -c -r1.37 guc-file.l
*** src/backend/utils/misc/guc-file.l	7 Mar 2006 01:03:12 -0000	1.37
--- src/backend/utils/misc/guc-file.l	27 Mar 2006 20:30:55 -0000
***************
*** 18,23 ****
--- 18,24 ----
  #include "storage/fd.h"
  #include "utils/guc.h"
  
+ extern void ResetOptionsSIGHUP(void);
  
  /* Avoid exit() on fatal scanner errors (a bit ugly -- see yy_fatal_error) */
  #undef fprintf
***************
*** 124,129 ****
--- 125,132 ----
  		 * about problems with the config file.
  		 */
  		elevel = IsUnderPostmaster ? DEBUG2 : LOG;
+ 		/* SIGHUP initialize default value at first */ 
+ 		ResetOptionsSIGHUP();
  	}
  	else
  		elevel = ERROR;
***************
*** 154,160 ****
  	free_name_value_list(head);
  }
  
! 
  /*
   * Read and parse a single configuration file.  This function recurses
   * to handle "include" directives.
--- 157,163 ----
  	free_name_value_list(head);
  }
  
!  
  /*
   * Read and parse a single configuration file.  This function recurses
   * to handle "include" directives.
Index: src/backend/utils/misc/guc.c
===================================================================
RCS file: /projects/cvsroot/pgsql/src/backend/utils/misc/guc.c,v
retrieving revision 1.314
diff -c -r1.314 guc.c
*** src/backend/utils/misc/guc.c	7 Mar 2006 02:54:23 -0000	1.314
--- src/backend/utils/misc/guc.c	27 Mar 2006 20:30:56 -0000
***************
*** 3021,3026 ****
--- 3021,3127 ----
  
  
  /*
+  * Reset all options ( with context = SIGHUP ) to their saved default values
+  */
+ void
+ ResetOptionsSIGHUP(void)
+ {
+ 	int			i;
+ 	bool retour;
+ 	
+ 	for (i = 0; i < num_guc_variables; i++)
+ 	{
+ 		struct config_generic *gconf = guc_variables[i];
+ 
+ 		if ( gconf->context == PGC_SIGHUP  )
+ 		{
+ 			elog(LOG,"option = %s",gconf->name);
+ 			switch (gconf->vartype)
+ 			{
+ 				case PGC_BOOL:
+ 					{
+ 						struct config_bool *conf = (struct config_bool *) gconf;
+ 						
+ 						
+ 						if (conf->assign_hook)
+ 							if (!(*conf->assign_hook) (conf->reset_val, true,
+ 												   PGC_S_SESSION))
+ 								elog(ERROR, "failed to reset %s", conf->gen.name);
+ 						if ( !strcmp(GetConfigOptionResetString((const char*)conf->gen.name),"on") ) *conf->variable=true;
+ 							else *conf->variable=false;
+ 						conf->gen.reset_source=PGC_S_SIGHUP;
+ 						break;
+ 					}
+ 				case PGC_INT:
+ 					{
+ 						struct config_int *conf = (struct config_int *) gconf;
+ 	
+ 						if (conf->assign_hook)
+ 							if (!(*conf->assign_hook) (conf->reset_val, true,
+ 													PGC_S_SESSION))
+ 								elog(ERROR, "failed to reset %s", conf->gen.name);
+ 						*conf->variable = atoi(GetConfigOptionResetString(conf->gen.name));
+ 						conf->gen.reset_source=PGC_S_SIGHUP;
+ 						break;
+ 					}
+ 				case PGC_REAL:
+ 				{
+ 					struct config_real *conf = (struct config_real *) gconf;
+ 
+ 					if (conf->assign_hook)
+ 						if (!(*conf->assign_hook) (conf->reset_val, true,
+ 												   PGC_S_SESSION))
+ 							elog(ERROR, "failed to reset %s", conf->gen.name);
+ 					*conf->variable = atol(GetConfigOptionResetString(conf->gen.name));
+ 					conf->gen.reset_source=PGC_S_SIGHUP;
+ 					break;
+ 				}
+ 				case PGC_STRING:
+ 				{
+ 					struct config_string *conf = (struct config_string *) gconf;
+ 					char	   *str;
+ 
+ 					if (conf->reset_val == NULL)
+ 					{
+ 						/* Nothing to reset to, as yet; so do nothing */
+ 						break;
+ 					}
+ 
+ 					/* We need not strdup here */
+ 					str = guc_strdup(LOG, conf->reset_val);
+ 
+ 					if (conf->assign_hook)
+ 					{
+ 						const char *newstr;
+ 
+ 						newstr = (*conf->assign_hook) (str, true,
+ 													   PGC_S_SESSION);
+ 						if (newstr == NULL)
+ 							elog(ERROR, "failed to reset %s", conf->gen.name);
+ 						else if (newstr != str)
+ 						{
+ 							/*
+ 							 * See notes in set_config_option about casting
+ 							 */
+ 							str = (char *) newstr;
+ 						}
+ 					}
+ 
+ 					set_string_field(conf, conf->variable, str);
+ 					conf->gen.reset_source=PGC_S_SIGHUP;
+ 					break;
+ 				}
+ 					
+ 			}
+ 		}
+ 	}
+ }
+ 
+ 
+ 
+ 
+ 		
+ /*
   * push_old_value
   *		Push previous state during first assignment to a GUC variable
   *		within a particular transaction.
***************
*** 3124,3130 ****
  		GucStack   *stack = gconf->stack;
  		bool		useTentative;
  		bool		changed;
! 
  		/*
  		 * Skip if nothing's happened to this var in this transaction
  		 */
--- 3225,3231 ----
  		GucStack   *stack = gconf->stack;
  		bool		useTentative;
  		bool		changed;
! 		
  		/*
  		 * Skip if nothing's happened to this var in this transaction
  		 */
***************
*** 3711,3717 ****
  	 * transactional.)
  	 */
  	makeDefault = changeVal && (source <= PGC_S_OVERRIDE) && (value != NULL);
! 
  	/*
  	 * Ignore attempted set if overridden by previously processed setting.
  	 * However, if changeVal is false then plow ahead anyway since we are
--- 3812,3818 ----
  	 * transactional.)
  	 */
  	makeDefault = changeVal && (source <= PGC_S_OVERRIDE) && (value != NULL);
! 	
  	/*
  	 * Ignore attempted set if overridden by previously processed setting.
  	 * However, if changeVal is false then plow ahead anyway since we are
***************
*** 4049,4055 ****
  						newval = (char *) hookresult;
  					}
  				}
! 
  				if (changeVal || makeDefault)
  				{
  					/* Save old value to support transaction abort */
--- 4150,4156 ----
  						newval = (char *) hookresult;
  					}
  				}
! 				
  				if (changeVal || makeDefault)
  				{
  					/* Save old value to support transaction abort */
***************
*** 4077,4082 ****
--- 4178,4184 ----
  												 newval);
  								stack->source = source;
  							}
+ 							
  						}
  						/* Perhaps we didn't install newval anywhere */
  						if (!string_field_used(conf, newval))
***************
*** 4097,4102 ****
--- 4199,4206 ----
  				}
  				else
  					free(newval);
+ 					
+ 				
  				break;
  			}
  	}
Index: src/include/utils/guc.h
===================================================================
RCS file: /projects/cvsroot/pgsql/src/include/utils/guc.h,v
retrieving revision 1.67
diff -c -r1.67 guc.h
*** src/include/utils/guc.h	7 Mar 2006 03:01:22 -0000	1.67
--- src/include/utils/guc.h	27 Mar 2006 20:30:56 -0000
***************
*** 88,93 ****
--- 88,94 ----
  	PGC_S_USER,					/* per-user setting */
  	PGC_S_CLIENT,				/* from client connection request */
  	PGC_S_OVERRIDE,				/* special case to forcibly set default */
+ 	PGC_S_SIGHUP,				/* Default value from SIGHUP signal */	
  	PGC_S_INTERACTIVE,			/* dividing line for error reporting */
  	PGC_S_TEST,					/* test per-database or per-user setting */
  	PGC_S_SESSION				/* SET command */
---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings

Reply via email to